From: Christian Brauner Date: Tue, 14 Nov 2017 23:35:02 +0000 (+0100) Subject: confile: add lxc.console.rotate X-Git-Tag: lxc-3.0.0.beta1~182^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d91adfa6123ac2c884fac6dbe74c823cb4eafe5b;p=thirdparty%2Flxc.git confile: add lxc.console.rotate Signed-off-by: Christian Brauner --- diff --git a/doc/lxc.container.conf.sgml.in b/doc/lxc.container.conf.sgml.in index 2e2879e71..f00092aed 100644 --- a/doc/lxc.container.conf.sgml.in +++ b/doc/lxc.container.conf.sgml.in @@ -733,11 +733,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - 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 + and + . + + + + + + + + Whether to rotate the console logfile specified in + . 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 and + . + + + + diff --git a/src/lxc/conf.h b/src/lxc/conf.h index b07c92e74..58302cf30 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -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; diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 977bea2ed..24e74adff 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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) {