From: Christian Brauner Date: Thu, 9 Nov 2017 18:39:59 +0000 (+0100) Subject: commands: truncate console ringbuffer log file X-Git-Tag: lxc-3.0.0.beta1~182^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf685555b3817bfd0a69eefb7a08a3eec647bcc9;p=thirdparty%2Flxc.git commands: truncate console ringbuffer log file When a "clear" request is sent to the console ringbuffer we should truncate the console log file as well. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 759346b8b..133b6e6c1 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -23,6 +23,7 @@ #include "config.h" +#include #include #include #include @@ -1062,11 +1063,32 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req, } rsp.ret = 0; - - if (log->clear) + if (log->clear) { + /* clear the ringbuffer */ lxc_ringbuf_clear(buf); - else if (rsp.datalen > 0) + + /* truncate the ringbuffer log file */ + if (console->buffer_log_file) { + rsp.ret = -ENOENT; + if (!file_exists(console->buffer_log_file)) + goto out; + + /* be very certain things are kosher */ + rsp.ret = -EBADF; + if (console->buffer_log_file_fd < 0) + goto out; + + rsp.ret = lxc_unpriv(ftruncate(console->buffer_log_file_fd, 0)); + if (rsp.ret < 0) { + ERROR("%s - Failed to truncate console " + "ringbuffer log file \"%s\"", + strerror(errno), console->buffer_log_file); + goto out; + } + } + } else if (rsp.datalen > 0) { lxc_ringbuf_move_read_addr(buf, rsp.datalen); + } out: return lxc_cmd_rsp_send(fd, &rsp);