]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: add lxc.console.rotate
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 14 Nov 2017 23:35:02 +0000 (00:35 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 17 Nov 2017 23:20:52 +0000 (00:20 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
doc/lxc.container.conf.sgml.in
src/lxc/conf.h
src/lxc/confile.c

index 2e2879e719f3b472a87278e216f67ff8f9bfed4b..f00092aedd0f83eaf05e62fd055fba7469d9122c 100644 (file)
@@ -733,11 +733,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
           </term>
           <listitem>
             <para>
-              Specify a path to a file where the console output will
-              be written.
+              Specify a path to a file where the console output will be written.
+              Note that in contrast to the on-disk ringbuffer logfile this file
+              will keep growing potentially filling up the users disks if not
+              rotated and deleted. This problem can also be avoided by using the
+              in-memory ringbuffer options
+              <option>lxc.console.buffer.size</option> and
+              <option>lxc.console.buffer.logfile</option>.
             </para>
           </listitem>
         </varlistentry>
+
+        <varlistentry>
+          <term>
+            <option>lxc.console.rotate</option>
+          </term>
+          <listitem>
+            <para>
+              Whether to rotate the console logfile specified in
+              <option>lxc.console.logfile</option>. Users can send an API
+              request to rotate the logfile. Note that the old logfile will have
+              the same name as the original with the suffix ".1" appended.
+
+              Users wishing to prevent the console log file from filling the
+              disk should rotate the logfile and delete it if unneeded. This
+              problem can also be avoided by using the in-memory ringbuffer
+              options <option>lxc.console.buffer.size</option> and
+              <option>lxc.console.buffer.logfile</option>.
+            </para>
+          </listitem>
+        </varlistentry>
+
         <varlistentry>
           <term>
             <option>lxc.console.path</option>
index b07c92e74edad6176aa3e5fbfe1c505fc2449bbc..58302cf30c002bc9b1412a7b1d065b0c9c83a6de 100644 (file)
@@ -150,6 +150,7 @@ struct lxc_console {
        char *path;
        char *log_path;
        int log_fd;
+       unsigned int log_rotate;
        char name[MAXPATHLEN];
        struct termios *tios;
        struct lxc_tty_state *tty_state;
index 977bea2edb2cde09d2d4d4b22c463f54b7b43bfb..24e74adffd36d6ad3dd1d7121907e131d15c1e72 100644 (file)
@@ -83,6 +83,7 @@ lxc_config_define(cap_keep);
 lxc_config_define(cgroup_controller);
 lxc_config_define(cgroup_dir);
 lxc_config_define(console_logfile);
+lxc_config_define(console_rotate);
 lxc_config_define(console_buffer_logfile);
 lxc_config_define(console_buffer_size);
 lxc_config_define(console_path);
@@ -154,6 +155,7 @@ static struct lxc_config_t config[] = {
        { "lxc.console.buffer.size",       false,                  set_config_console_buffer_size,         get_config_console_buffer_size,         clr_config_console_buffer_size,       },
        { "lxc.console.logfile",           false,                  set_config_console_logfile,             get_config_console_logfile,             clr_config_console_logfile,           },
        { "lxc.console.path",              false,                  set_config_console_path,                get_config_console_path,                clr_config_console_path,              },
+       { "lxc.console.rotate",            false,                  set_config_console_rotate,              get_config_console_rotate,              clr_config_console_rotate,            },
        { "lxc.environment",               false,                  set_config_environment,                 get_config_environment,                 clr_config_environment,               },
        { "lxc.ephemeral",                 false,                  set_config_ephemeral,                   get_config_ephemeral,                   clr_config_ephemeral,                 },
        { "lxc.execute.cmd",               false,                  set_config_execute_cmd,                 get_config_execute_cmd,                 clr_config_execute_cmd,               },
@@ -1790,6 +1792,23 @@ static int set_config_console_path(const char *key, const char *value,
        return set_config_path_item(&lxc_conf->console.path, value);
 }
 
+static int set_config_console_rotate(const char *key, const char *value,
+                                    struct lxc_conf *lxc_conf, void *data)
+{
+       if (lxc_config_value_empty(value)) {
+               lxc_conf->console.log_rotate = 0;
+               return 0;
+       }
+
+       if (lxc_safe_uint(value, &lxc_conf->console.log_rotate) < 0)
+               return -1;
+
+       if (lxc_conf->console.log_rotate > 1)
+               return -1;
+
+       return 0;
+}
+
 static int set_config_console_logfile(const char *key, const char *value,
                                      struct lxc_conf *lxc_conf, void *data)
 {
@@ -3100,6 +3119,13 @@ static int get_config_console_logfile(const char *key, char *retv, int inlen,
        return lxc_get_conf_str(retv, inlen, c->console.log_path);
 }
 
+static int get_config_console_rotate(const char *key, char *retv, int inlen,
+                                    struct lxc_conf *c, void *data)
+{
+       return lxc_get_conf_int(c, retv, inlen, c->console.log_rotate);
+}
+
+
 static int get_config_console_buffer_size(const char *key, char *retv,
                                          int inlen, struct lxc_conf *c,
                                          void *data)
@@ -3518,6 +3544,13 @@ static inline int clr_config_console_logfile(const char *key,
        return 0;
 }
 
+static inline int clr_config_console_rotate(const char *key, struct lxc_conf *c,
+                                           void *data)
+{
+       c->console.log_rotate = 0;
+       return 0;
+}
+
 static inline int clr_config_console_buffer_size(const char *key,
                                                 struct lxc_conf *c, void *data)
 {