console: dump ringbuffer to disk on container exit

The console ringbuffer will be dumped to disk if the console log file is not rotated and it's size is not unlimited. In the former two cases we will have all data from the ringbuffer available anyway. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 23e0d9af
...@@ -705,10 +705,53 @@ out: ...@@ -705,10 +705,53 @@ out:
return ret; return ret;
} }
int lxc_console_write_ringbuffer(struct lxc_console *console)
{
char *r_addr;
ssize_t ret;
uint64_t used;
struct lxc_ringbuf *buf = &console->ringbuf;
/* There's not log file where we can dump the ringbuffer to. */
if (console->log_fd < 0)
return 0;
/* The log file is simply appended to. */
if (console->log_size == 0)
return 0;
/* The log file is rotated. */
if (console->log_rotate == 0)
return 0;
used = lxc_ringbuf_used(buf);
if (used == 0)
return 0;
ret = lxc_console_truncate_log_file(console);
if (ret < 0)
return ret;
/* Write as much as we can without exceeding the limit. */
if (console->log_size < used)
used = console->log_size;
r_addr = lxc_ringbuf_get_read_addr(buf);
ret = lxc_write_nointr(console->log_fd, r_addr, used);
if (ret < 0)
return -EIO;
return 0;
}
void lxc_console_delete(struct lxc_console *console) void lxc_console_delete(struct lxc_console *console)
{ {
int ret; int ret;
ret = lxc_console_write_ringbuffer(console);
if (ret < 0)
WARN("Failed to write console ringbuffer to console log file");
if (console->tios && console->peer >= 0) { if (console->tios && console->peer >= 0) {
ret = tcsetattr(console->peer, TCSAFLUSH, console->tios); ret = tcsetattr(console->peer, TCSAFLUSH, console->tios);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment