]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
logging: Add lxc_log_options_no_override function
authorStéphane Graber <stgraber@ubuntu.com>
Tue, 4 Feb 2014 18:03:05 +0000 (13:03 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 4 Feb 2014 23:01:59 +0000 (18:01 -0500)
In current LXC, loglevel and logfile are write-once functions.
That behaviour was appropriate when those two were first introduced
(pre-API) but with current API, one would expect to be able to
set_config_item those multiple times.

So instead, introduce lxc_log_options_no_override which when called
turns those two config keys read-only and have all existing binaries
which use log_init call that function once they're done setting the
value requested by the user.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
20 files changed:
src/lxc/confile.c
src/lxc/log.c
src/lxc/log.h
src/lxc/lxc_attach.c
src/lxc/lxc_cgroup.c
src/lxc/lxc_console.c
src/lxc/lxc_create.c
src/lxc/lxc_destroy.c
src/lxc/lxc_execute.c
src/lxc/lxc_freeze.c
src/lxc/lxc_info.c
src/lxc/lxc_init.c
src/lxc/lxc_monitor.c
src/lxc/lxc_monitord.c
src/lxc/lxc_snapshot.c
src/lxc/lxc_start.c
src/lxc/lxc_stop.c
src/lxc/lxc_unfreeze.c
src/lxc/lxc_wait.c
src/python-lxc/lxc/__init__.py

index ec8b07f3389619f6c8d823b54e239464df2cc1ea..546df53909a05cd2b37d15f819f731dcaa14a58f 100644 (file)
@@ -1106,10 +1106,6 @@ static int config_loglevel(const char *key, const char *value,
        if (!value || strlen(value) == 0)
                return 0;
 
-       if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET) {
-               DEBUG("Log level already set - ignoring new value");
-               return 0;
-       }
        if (value[0] >= '0' && value[0] <= '9')
                newlevel = atoi(value);
        else
index 4a2b7eb325ba8dd6cf43c50f24c478a56b6d1712..6706f907180559d2f2d86ad1843d46ecef2faafc 100644 (file)
@@ -247,6 +247,11 @@ static int __lxc_log_set_file(const char *fname, int create_dirs)
                free(log_fname);
        }
 
+       if (!fname || strlen(fname) == 0) {
+               log_fname = NULL;
+               return 0;
+       }
+
 #if USE_CONFIGPATH_LOGS
        // we don't build_dir for the default if the default is
        // i.e. /var/lib/lxc/$container/$container.log
@@ -299,7 +304,6 @@ extern int lxc_log_init(const char *name, const char *file,
                        return -1;
                }
 
-               lxc_loglevel_specified = 1;
                lxc_priority = lxc_log_priority_to_int(priority);
        }
 
@@ -315,7 +319,6 @@ extern int lxc_log_init(const char *name, const char *file,
        if (file) {
                if (strcmp(file, "none") == 0)
                        return 0;
-               lxc_logfile_specified = 1;
                ret = __lxc_log_set_file(file, 1);
        } else {
 
@@ -366,15 +369,12 @@ extern int lxc_log_set_level(int level)
                ERROR("invalid log priority %d", level);
                return -1;
        }
-       lxc_loglevel_specified = 1;
        lxc_log_category_lxc.priority = level;
        return 0;
 }
 
 extern int lxc_log_get_level(void)
 {
-       if (!lxc_loglevel_specified)
-               return LXC_LOG_PRIORITY_NOTSET;
        return lxc_log_category_lxc.priority;
 }
 
@@ -395,7 +395,6 @@ extern int lxc_log_set_file(const char *fname)
 {
        if (lxc_logfile_specified)
                return 0;
-       lxc_logfile_specified = 1;
        return __lxc_log_set_file(fname, 0);
 }
 
@@ -414,3 +413,12 @@ extern const char *lxc_log_get_prefix(void)
 {
        return log_prefix;
 }
+
+extern void lxc_log_options_no_override()
+{
+       if (lxc_log_get_file())
+               lxc_logfile_specified = 1;
+
+       if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET)
+               lxc_loglevel_specified = 1;
+}
index 4a9714ae9712fd963ccd5783912524623fe5d974..ff8e47da8fddf10222f87f40f2bcb958e46ad0c8 100644 (file)
@@ -298,4 +298,5 @@ extern const char *lxc_log_get_file(void);
 extern int lxc_log_get_level(void);
 extern bool lxc_log_has_valid_level(void);
 extern const char *lxc_log_get_prefix(void);
+extern void lxc_log_options_no_override();
 #endif
index 6744c058726feb52cdedbec38b0d2d74f263052b..e3e89c4ddb7d9184c1f511b6c6fdfc8f9b52cd77 100644 (file)
@@ -203,6 +203,7 @@ int main(int argc, char *argv[])
                           my_args.progname, my_args.quiet, my_args.lxcpath[0]);
        if (ret)
                return ret;
+       lxc_log_options_no_override();
 
        if (remount_sys_proc)
                attach_options.attach_flags |= LXC_ATTACH_REMOUNT_PROC_SYS;
index 7998f1cca0c9247b033d02ca767efd44bf038089..b7fc621e23103b647723ef99765954cab49359ba 100644 (file)
@@ -76,6 +76,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return -1;
+       lxc_log_options_no_override();
 
        state_object = my_args.argv[0];
 
index 03aa15848552044881d835ce05547276dcaad9c9..c262ada919a7014e47b5f21f7743763d04706baa 100644 (file)
@@ -105,6 +105,7 @@ int main(int argc, char *argv[])
                           my_args.progname, my_args.quiet, my_args.lxcpath[0]);
        if (ret)
                return EXIT_FAILURE;
+       lxc_log_options_no_override();
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c) {
index 058dc43bdea80ca33669ec78d373d2f860f4c7d8..87845b4addbab7ea11ad1b842ff467b1abcb5889 100644 (file)
@@ -201,6 +201,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                exit(1);
+       lxc_log_options_no_override();
 
        memset(&spec, 0, sizeof(spec));
        if (!my_args.bdevtype)
index 729d35276cd5b517bb12fd96cc7c8fdee60dcc26..cd56f08249fc415303e062e87ba6e038003815f3 100644 (file)
@@ -72,6 +72,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                exit(1);
+       lxc_log_options_no_override();
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c) {
index 6a54bf63a7e01a7099217da3c0dcb458a26f116e..18baa064f1027395df5dc56260fec46487f92ebf 100644 (file)
@@ -103,6 +103,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return -1;
+       lxc_log_options_no_override();
 
        /* rcfile is specified in the cli option */
        if (my_args.rcfile)
index 086c81c3b8ff6e86141504becbbd07b2f3f28e85..bb01a3a16a38a4fd0f4e5a44467dbd7ade31133d 100644 (file)
@@ -66,6 +66,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                exit(1);
+       lxc_log_options_no_override();
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c) {
index 4243cf3ecfa37c99e5a31af94b0cf869ca55cd63..b556c2c01a475df9e90d18a7f6f2bd16f0e3cb01 100644 (file)
@@ -371,6 +371,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return ret;
+       lxc_log_options_no_override();
 
        if (print_info(my_args.name, my_args.lxcpath[0]) == 0)
                ret = EXIT_SUCCESS;
index 3e51c00e1dc5820ba9947f5c4e7f55b8afdacb44..91ed08df000810a42b6a498203166cb97f99e190 100644 (file)
@@ -111,6 +111,7 @@ int main(int argc, char *argv[])
                           basename(argv[0]), quiet, lxcpath);
        if (err < 0)
                exit(EXIT_FAILURE);
+       lxc_log_options_no_override();
 
        if (!argv[optind]) {
                ERROR("missing command to launch");
index 52f4c98c328958d892d06a1cac8c0dcc114f9fa4..fa954dcc5e0c917545322a44dbad4323cc18868d 100644 (file)
@@ -86,6 +86,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return -1;
+       lxc_log_options_no_override();
 
        if (quit_monitord) {
                int ret = EXIT_SUCCESS;
index 84e023990ea87382514a46f23249eb17b24af08e..f6d99d57e6bc4d0f7546af78821878c6be7e6a29 100644 (file)
@@ -355,6 +355,7 @@ int main(int argc, char *argv[])
        ret = lxc_log_init(NULL, logpath, "NOTICE", "lxc-monitord", 0, lxcpath);
        if (ret)
                INFO("Failed to open log file %s, log will be lost", lxcpath);
+       lxc_log_options_no_override();
 
        pipefd = atoi(argv[2]);
 
index a49e8d737d943e8022086aec93ce4fc864b1964d..a8d4e7fc184c7b77310e3a8ab3daa7082186396f 100644 (file)
@@ -187,6 +187,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                exit(1);
+       lxc_log_options_no_override();
 
        if (geteuid()) {
                if (access(my_args.lxcpath[0], O_RDWR) < 0) {
index 19ebea028339557b37a8eb48b9af13af8e3e0373..9517fe6f4c5746eb937aa4fecd4828592d6c2b91 100644 (file)
@@ -228,6 +228,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return err;
+       lxc_log_options_no_override();
 
        const char *lxcpath = my_args.lxcpath[0];
 
index 99621a23deae33b8c32d671672332e578528085a..fc9d70a84a19a98d2ed70a8c1caacea7ae464b73 100644 (file)
@@ -144,6 +144,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return 1;
+       lxc_log_options_no_override();
 
        /* Set default timeout */
        if (my_args.timeout == -2) {
index ccabada5565b6e3afd0dbadf2f47d8c4d59cdbf6..e66d165bb8f7e0f2611d451e24df944f3d84ef53 100644 (file)
@@ -64,6 +64,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                exit(1);
+       lxc_log_options_no_override();
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c) {
index 269acfdee3e294cfa2f064b49a1a0ed46d1d866e..d34c5e739fcd915f3250629e6aa528d9995334b7 100644 (file)
@@ -92,6 +92,7 @@ int main(int argc, char *argv[])
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
                         my_args.progname, my_args.quiet, my_args.lxcpath[0]))
                return -1;
+       lxc_log_options_no_override();
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c)
index 43fb07dbaf81347c7a03e94c2e7f04ee8a990f2b..4973dee8f5c3c2e07ed385e9c9934d5ef9d617e6 100644 (file)
@@ -362,6 +362,10 @@ class Container(_lxc.Container):
         set_key(key, value)
         new_value = self.get_config_item(key)
 
+        # loglevel is special and won't match the string we set
+        if key == "lxc.loglevel":
+            new_value = value
+
         if (isinstance(value, str) and isinstance(new_value, str) and
                 value == new_value):
             return True