]> git.proxmox.com Git - mirror_lxc.git/commitdiff
add quiet option
authorMichel Normand <normand@fr.ibm.com>
Mon, 18 May 2009 20:11:45 +0000 (22:11 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Mon, 18 May 2009 20:11:45 +0000 (22:11 +0200)
This added quiet option allow to disable
the reporting via stderr of the lxc error messages.

Note that the usage function is still printing in case of error,
but will be removed by later patches

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
16 files changed:
src/lxc/log.c
src/lxc/log.h
src/lxc/lxc_cgroup.c
src/lxc/lxc_checkpoint.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_monitor.c
src/lxc/lxc_restart.c
src/lxc/lxc_start.c
src/lxc/lxc_stop.c
src/lxc/lxc_unfreeze.c
src/lxc/lxc_wait.c

index fa6fe4a681cd06c2e647ea2b601265b8b1ae228e..596ed990092a26ab2910bbdec68e3c6f88d14d51 100644 (file)
@@ -97,7 +97,7 @@ static struct lxc_log_appender log_appender_stderr = {
 static struct lxc_log_appender log_appender_logfile = {
        .name           = "logfile",
        .append         = log_append_logfile,
-       .next           = &log_appender_stderr,
+       .next           = NULL,
 };
 
 static struct lxc_log_category log_root = {
@@ -147,7 +147,7 @@ static int log_open(const char *name)
 
 /*---------------------------------------------------------------------------*/
 extern int lxc_log_init(const char *file, const char *priority,
-                       const char *prefix)
+                       const char *prefix, int quiet)
 {
        int lxc_priority = LXC_LOG_PRIORITY_ERROR;
 
@@ -162,6 +162,9 @@ extern int lxc_log_init(const char *file, const char *priority,
 
        lxc_log_category_lxc.priority = lxc_priority;
 
+       if (!quiet)
+               lxc_log_category_lxc.appender->next = &log_appender_stderr;
+
        if (prefix)
                lxc_log_setprefix(prefix);
 
index 1443eb28616a2a444cdeb95bb97ded54601577ae..d9c1fb32f9f1148a1adf56e281c6bac74e831320 100644 (file)
@@ -286,5 +286,5 @@ extern struct lxc_log_category lxc_log_category_lxc;
 } while (0)
 
 extern int lxc_log_init(const char *file, const char *priority,
-                       const char *prefix);
+                       const char *prefix, int quiet);
 #endif
index 98dfe93cdb4e13c0d0cdcdc4a04cf91ceefd7505..a46b2f6cec1e051fbd0f4e497d923fcc121c55a3 100644 (file)
@@ -36,6 +36,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -45,6 +46,7 @@ int main(int argc, char *argv[])
        char *name = NULL, *subsystem = NULL, *value = NULL;
        const char *log_file = NULL, *log_priority = NULL;
        int nbargs = 0;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
                switch (opt) {
@@ -57,6 +59,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -65,7 +70,7 @@ int main(int argc, char *argv[])
        if (!name || (argc-optind) < 1)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        if ((argc -optind) >= 1)
index 687d7f5cb32760faed97581a33e7f639afc6fbc2..e8d7d606d8a34ee7f43cb1cc0e6663ca3a32cef0 100644 (file)
@@ -33,6 +33,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -44,6 +45,7 @@ int main(int argc, char *argv[])
        int stop = 0;
        int nbargs = 0;
        int ret = 1;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "sn:o:l:")) != -1) {
                switch (opt) {
@@ -59,6 +61,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -70,7 +75,7 @@ int main(int argc, char *argv[])
        if (!argv[1])
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return -1;
 
        if (lxc_freeze(name))
index dc6e8999ea03bf87567b31b958ba7541cf478dd2..8d2541b0256f0dde1906e880809b273cb094e69a 100644 (file)
@@ -50,6 +50,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t [-t <tty#>] : tty number\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -57,6 +58,7 @@ int main(int argc, char *argv[])
 {
        char *name = NULL;
        const char *log_file = NULL, *log_priority = NULL;
+       int quiet = 0;
        int opt;
        int nbargs = 0;
        int master = -1;
@@ -80,6 +82,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -88,7 +93,7 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        /* Get current termios */
index 42ac24d54deea768d67d0475e207372ff8ddd520..3be3424ccd1c1e68c82027cc2533b1d6a5c84ed1 100644 (file)
@@ -41,6 +41,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -f <confile> : path of the configuration file\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -50,8 +51,9 @@ int main(int argc, char *argv[])
        const char *log_file = NULL, *log_priority = NULL;
        struct lxc_conf lxc_conf;
        int err, opt;
+       int quiet = 0;
 
-       while ((opt = getopt(argc, argv, "f:n:o:l:")) != -1) {
+       while ((opt = getopt(argc, argv, "f:n:o:l:q")) != -1) {
                switch (opt) {
                case 'n':
                        name = optarg;
@@ -65,13 +67,16 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
        }
 
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        if (lxc_conf_init(&lxc_conf))
index 0383be1d62d3b4da8f9d178e3a6723ed3d47508a..2c93ce5f62db4d1fa687e922f2addbd8f54c291c 100644 (file)
@@ -33,6 +33,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -43,6 +44,7 @@ int main(int argc, char *argv[])
        int opt;
        int nbargs = 0;
        int err;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
                switch (opt) {
@@ -55,6 +57,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -63,7 +68,7 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        err = lxc_destroy(name);
index 0c0f3a9b2a675eac5020bb4ce8789c3b23cb3c9a..7ddc534dbc765c3b716603ea4605156556510186 100644 (file)
@@ -42,6 +42,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t [-f <confile>] : path of the configuration file\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -55,9 +56,10 @@ int main(int argc, char *argv[])
        int nbargs = 0;
        int autodestroy = 0;
        int ret = 1;
+       int quiet = 0;
        struct lxc_conf lxc_conf;
 
-       while ((opt = getopt(argc, argv, "f:n:o:l:")) != -1) {
+       while ((opt = getopt(argc, argv, "f:n:o:l:q")) != -1) {
                switch (opt) {
                case 'n':
                        name = optarg;
@@ -71,6 +73,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -81,7 +86,7 @@ int main(int argc, char *argv[])
 
        argc -= nbargs;
        
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                goto out;
 
        if (lxc_conf_init(&lxc_conf))
index bf6b5808434063f744b5ce03e549396da4108631..8190cba5ac70d67fe174fa08fc8ac33ebc0e7f08 100644 (file)
@@ -34,6 +34,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -43,6 +44,7 @@ int main(int argc, char *argv[])
        const char *log_file = NULL, *log_priority = NULL;
        int opt;
        int nbargs = 0;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
                switch (opt) {
@@ -55,6 +57,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -63,7 +68,7 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        if (lxc_freeze(name))
index a960985d4f731867a7724eabbd369abc7dc249f2..5cfb501ed7ab3347a82569fb45d8c0cfa014f980 100644 (file)
@@ -33,6 +33,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -41,6 +42,7 @@ int main(int argc, char *argv[])
        char *name = NULL;
        const char *log_file = NULL, *log_priority = NULL;
        int opt, state, nbargs = 0;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
                switch (opt) {
@@ -53,6 +55,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -61,7 +66,7 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        state = lxc_getstate(name);
index 472b3193081719eb9b37de26505f59f011eba501..937cf875d11621ca5696aad885e54e5850c252b3 100644 (file)
@@ -37,6 +37,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container or regular expression\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -48,8 +49,9 @@ int main(int argc, char *argv[])
        struct lxc_msg msg;
        regex_t preg;
        int fd, opt;
+       int quiet = 0;
 
-       while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
+       while ((opt = getopt(argc, argv, "n:o:l:q")) != -1) {
                switch (opt) {
                case 'n':
                        name = optarg;
@@ -60,13 +62,16 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
        }
 
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        regexp = malloc(strlen(name) + 3);
index 58bf40d78c2b36c56f03fe665d1d7c861c0cb9aa..0b7812c73f31fa6e65273ce2685cb616cedd5ee4 100644 (file)
@@ -35,6 +35,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -43,6 +44,7 @@ int main(int argc, char *argv[])
        char *name = NULL;
        const char *log_file = NULL, *log_priority = NULL;
        int opt, nbargs = 0;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
                switch (opt) {
@@ -55,6 +57,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -66,7 +71,7 @@ int main(int argc, char *argv[])
        if (!argv[optind])
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        if (lxc_restart(name, argv[1], 0)) {
index 809041e9270565ad567818ed5d295d55af7f0518..0faf446c749c818bf1567e9629eb6397e0fe02d0 100644 (file)
@@ -45,6 +45,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -54,6 +55,7 @@ int main(int argc, char *argv[])
        const char *log_file = NULL, *log_priority = NULL;
        char **args;
        int opt, err = LXC_ERROR_INTERNAL, nbargs = 0;
+       int quiet = 0;
        struct termios tios;
 
        char *default_args[] = {
@@ -72,6 +74,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -87,7 +92,7 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        if (tcgetattr(0, &tios)) {
index 9406d2ff7c9a39f39431927c207e1a7e4200cc38..7c3ae3b68796975447e1990a09328be802fccc82 100644 (file)
@@ -33,6 +33,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -41,8 +42,9 @@ int main(int argc, char *argv[])
        char *name = NULL;
        const char *log_file = NULL, *log_priority = NULL;
        int opt, err, nbargs = 0;
+       int quiet = 0;
 
-       while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
+       while ((opt = getopt(argc, argv, "n:o:l:q")) != -1) {
                switch (opt) {
                case 'n':
                        name = optarg;
@@ -53,6 +55,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -61,7 +66,7 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        err = lxc_stop(name);
index 562bd22ed4806d0954203b68178b59cdf2dc84b5..be8976552057a961f0bae2ae6bbbaef77401d9c4 100644 (file)
@@ -33,6 +33,7 @@ void usage(char *cmd)
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -41,6 +42,7 @@ int main(int argc, char *argv[])
        char *name = NULL;
        const char *log_file = NULL, *log_priority = NULL;
        int opt, nbargs = 0;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
                switch (opt) {
@@ -53,6 +55,9 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
 
                nbargs++;
@@ -61,7 +66,7 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return 1;
 
        if (lxc_unfreeze(name))
index 711b377388e9f4a23404de82cff69e5a4ac5db86..0b723e8854153e557e4f47194af03acc870cff7e 100644 (file)
@@ -38,6 +38,7 @@ void usage(char *cmd)
                "STARTING, RUNNING, STOPPING, ABORTING, FREEZING, FROZEN\n");
        fprintf(stderr, "\t[-o <logfile>]    : path of the log file\n");
        fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
+       fprintf(stderr, "\t[-q ]             : be quiet\n");
        _exit(1);
 }
 
@@ -66,6 +67,7 @@ int main(int argc, char *argv[])
        const char *log_file = NULL, *log_priority = NULL;
        struct lxc_msg msg;
        int s[MAX_STATE] = { }, fd, opt;
+       int quiet = 0;
 
        while ((opt = getopt(argc, argv, "s:n:o:l:")) != -1) {
                switch (opt) {
@@ -81,13 +83,16 @@ int main(int argc, char *argv[])
                case 'l':
                        log_priority = optarg;
                        break;
+               case 'q':
+                       quiet = 1;
+                       break;
                }
        }
 
        if (!name || !states)
                usage(argv[0]);
 
-       if (lxc_log_init(log_file, log_priority, basename(argv[0])))
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
                return -1;
 
        if (fillwaitedstates(states, s)) {