mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-02 15:51:59 +00:00
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: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
23e0d9af76
commit
39c6cdb771
@ -705,10 +705,53 @@ out:
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
ret = tcsetattr(console->peer, TCSAFLUSH, console->tios);
|
||||
if (ret < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user