From 441e49639508dce2a3fd94dabe5f40fead110ebf Mon Sep 17 00:00:00 2001 From: Michel Normand Date: Mon, 18 May 2009 22:11:45 +0200 Subject: [PATCH] add quiet option 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 Signed-off-by: Daniel Lezcano --- src/lxc/log.c | 7 +++++-- src/lxc/log.h | 2 +- src/lxc/lxc_cgroup.c | 7 ++++++- src/lxc/lxc_checkpoint.c | 7 ++++++- src/lxc/lxc_console.c | 7 ++++++- src/lxc/lxc_create.c | 9 +++++++-- src/lxc/lxc_destroy.c | 7 ++++++- src/lxc/lxc_execute.c | 9 +++++++-- src/lxc/lxc_freeze.c | 7 ++++++- src/lxc/lxc_info.c | 7 ++++++- src/lxc/lxc_monitor.c | 9 +++++++-- src/lxc/lxc_restart.c | 7 ++++++- src/lxc/lxc_start.c | 7 ++++++- src/lxc/lxc_stop.c | 9 +++++++-- src/lxc/lxc_unfreeze.c | 7 ++++++- src/lxc/lxc_wait.c | 7 ++++++- 16 files changed, 94 insertions(+), 21 deletions(-) diff --git a/src/lxc/log.c b/src/lxc/log.c index fa6fe4a68..596ed9900 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -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); diff --git a/src/lxc/log.h b/src/lxc/log.h index 1443eb286..d9c1fb32f 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -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 diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 98dfe93cd..a46b2f6ce 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -36,6 +36,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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) diff --git a/src/lxc/lxc_checkpoint.c b/src/lxc/lxc_checkpoint.c index 687d7f5cb..e8d7d606d 100644 --- a/src/lxc/lxc_checkpoint.c +++ b/src/lxc/lxc_checkpoint.c @@ -33,6 +33,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) diff --git a/src/lxc/lxc_console.c b/src/lxc/lxc_console.c index dc6e8999e..8d2541b02 100644 --- a/src/lxc/lxc_console.c +++ b/src/lxc/lxc_console.c @@ -50,6 +50,7 @@ void usage(char *cmd) fprintf(stderr, "\t [-t ] : tty number\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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 */ diff --git a/src/lxc/lxc_create.c b/src/lxc/lxc_create.c index 42ac24d54..3be3424cc 100644 --- a/src/lxc/lxc_create.c +++ b/src/lxc/lxc_create.c @@ -41,6 +41,7 @@ void usage(char *cmd) fprintf(stderr, "\t -f : path of the configuration file\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) diff --git a/src/lxc/lxc_destroy.c b/src/lxc/lxc_destroy.c index 0383be1d6..2c93ce5f6 100644 --- a/src/lxc/lxc_destroy.c +++ b/src/lxc/lxc_destroy.c @@ -33,6 +33,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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); diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c index 0c0f3a9b2..7ddc534db 100644 --- a/src/lxc/lxc_execute.c +++ b/src/lxc/lxc_execute.c @@ -42,6 +42,7 @@ void usage(char *cmd) fprintf(stderr, "\t [-f ] : path of the configuration file\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) diff --git a/src/lxc/lxc_freeze.c b/src/lxc/lxc_freeze.c index bf6b58084..8190cba5a 100644 --- a/src/lxc/lxc_freeze.c +++ b/src/lxc/lxc_freeze.c @@ -34,6 +34,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c index a960985d4..5cfb501ed 100644 --- a/src/lxc/lxc_info.c +++ b/src/lxc/lxc_info.c @@ -33,6 +33,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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); diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index 472b31930..937cf875d 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -37,6 +37,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container or regular expression\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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); diff --git a/src/lxc/lxc_restart.c b/src/lxc/lxc_restart.c index 58bf40d78..0b7812c73 100644 --- a/src/lxc/lxc_restart.c +++ b/src/lxc/lxc_restart.c @@ -35,6 +35,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) { diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c index 809041e92..0faf446c7 100644 --- a/src/lxc/lxc_start.c +++ b/src/lxc/lxc_start.c @@ -45,6 +45,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) { diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c index 9406d2ff7..7c3ae3b68 100644 --- a/src/lxc/lxc_stop.c +++ b/src/lxc/lxc_stop.c @@ -33,6 +33,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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); diff --git a/src/lxc/lxc_unfreeze.c b/src/lxc/lxc_unfreeze.c index 562bd22ed..be8976552 100644 --- a/src/lxc/lxc_unfreeze.c +++ b/src/lxc/lxc_unfreeze.c @@ -33,6 +33,7 @@ void usage(char *cmd) fprintf(stderr, "\t -n : name of the container\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) diff --git a/src/lxc/lxc_wait.c b/src/lxc/lxc_wait.c index 711b37738..0b723e885 100644 --- a/src/lxc/lxc_wait.c +++ b/src/lxc/lxc_wait.c @@ -38,6 +38,7 @@ void usage(char *cmd) "STARTING, RUNNING, STOPPING, ABORTING, FREEZING, FROZEN\n"); fprintf(stderr, "\t[-o ] : path of the log file\n"); fprintf(stderr, "\t[-l ]: 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)) { -- 2.47.2