[lxc-devel] [lxc/master] commands: clear console log file

brauner on Github lxc-bot at linuxcontainers.org
Thu Nov 9 18:43:11 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 474 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171109/9182b90a/attachment.bin>
-------------- next part --------------
From cbba38fd7501d97f113ee395ac4b481b7f980014 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 9 Nov 2017 19:39:59 +0100
Subject: [PATCH] commands: clear console 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 <christian.brauner at ubuntu.com>
---
 src/lxc/commands.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 880cb28c2..d95643d49 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -1060,11 +1060,21 @@ 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 on-disk log file */
+		if (!console->log_path)
+			goto out;
+
+		rsp.ret = truncate(console->log_path, 0);
+		if (rsp.ret < 0)
+			ERROR("%s - Failed to truncate console log file \"%s\"",
+			      console->log_path);
+	} else if (rsp.datalen > 0) {
 		lxc_ringbuf_move_read_addr(buf, rsp.datalen);
+	}
 
 out:
 	return lxc_cmd_rsp_send(fd, &rsp);


More information about the lxc-devel mailing list