]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: lxc-wait: add default log priority & cleanups 2550/head
author2xsec <dh48.jeong@samsung.com>
Mon, 20 Aug 2018 01:43:22 +0000 (10:43 +0900)
committer2xsec <dh48.jeong@samsung.com>
Mon, 20 Aug 2018 01:43:22 +0000 (10:43 +0900)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/lxc/tools/lxc_wait.c

index deecc7734f67c45a60893f3aff1c17ce48e107f2..6c3c0708533add036f147730b9325ce73960cfff 100644 (file)
 
 lxc_log_define(lxc_wait, lxc);
 
-static int my_checker(const struct lxc_arguments *args)
-{
-       if (!args->states) {
-               ERROR("Missing state option to wait for");
-               return -1;
-       }
-
-       return 0;
-}
-
-static int my_parser(struct lxc_arguments *args, int c, char *arg)
-{
-       switch (c) {
-       case 's': args->states = optarg; break;
-       case 't': args->timeout = atol(optarg); break;
-       }
-
-       return 0;
-}
+static int my_parser(struct lxc_arguments *args, int c, char *arg);
+static int my_checker(const struct lxc_arguments *args);
 
 static const struct option my_longopts[] = {
        {"state", required_argument, 0, 's'},
@@ -64,8 +47,8 @@ static const struct option my_longopts[] = {
 };
 
 static struct lxc_arguments my_args = {
-       .progname = "lxc-wait",
-       .help     = "\
+       .progname     = "lxc-wait",
+       .help         = "\
 --name=NAME --state=STATE\n\
 \n\
 lxc-wait waits for NAME container state to reach STATE\n\
@@ -77,12 +60,38 @@ Options :\n\
                     ABORTING, FREEZING, FROZEN, THAWED\n\
   -t, --timeout=TMO Seconds to wait for state changes\n\
   --rcfile=FILE     Load configuration file FILE\n",
-       .options  = my_longopts,
-       .parser   = my_parser,
-       .checker  = my_checker,
-       .timeout = -1,
+       .options      = my_longopts,
+       .parser       = my_parser,
+       .checker      = my_checker,
+       .log_priority = "ERROR",
+       .log_file     = "none",
+       .timeout      = -1,
 };
 
+static int my_parser(struct lxc_arguments *args, int c, char *arg)
+{
+       switch (c) {
+       case 's':
+               args->states = optarg;
+               break;
+       case 't':
+               args->timeout = atol(optarg);
+               break;
+       }
+
+       return 0;
+}
+
+static int my_checker(const struct lxc_arguments *args)
+{
+       if (!args->states) {
+               ERROR("Missing state option to wait for");
+               return -1;
+       }
+
+       return 0;
+}
+
 int main(int argc, char *argv[])
 {
        struct lxc_container *c;
@@ -91,18 +100,15 @@ int main(int argc, char *argv[])
        if (lxc_arguments_parse(&my_args, argc, argv))
                exit(EXIT_FAILURE);
 
-       /* Only create log if explicitly instructed */
-       if (my_args.log_file || my_args.log_priority) {
-               log.name = my_args.name;
-               log.file = my_args.log_file;
-               log.level = my_args.log_priority;
-               log.prefix = my_args.progname;
-               log.quiet = my_args.quiet;
-               log.lxcpath = my_args.lxcpath[0];
+       log.name = my_args.name;
+       log.file = my_args.log_file;
+       log.level = my_args.log_priority;
+       log.prefix = my_args.progname;
+       log.quiet = my_args.quiet;
+       log.lxcpath = my_args.lxcpath[0];
 
-               if (lxc_log_init(&log))
-                       exit(EXIT_FAILURE);
-       }
+       if (lxc_log_init(&log))
+               exit(EXIT_FAILURE);
 
        c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
        if (!c)