]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands: truncate console ringbuffer log file
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Nov 2017 18:39:59 +0000 (19:39 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 17 Nov 2017 23:20:56 +0000 (00:20 +0100)
When a "clear" request is sent to the console ringbuffer we should truncate the
console log file as well.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c

index 759346b8b43e19afbf80873ec710caa4615e3c6c..133b6e6c1e1584ef89773a64da27d848ee58adc8 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "config.h"
 
+#include <caps.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <malloc.h>
@@ -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);