]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/generic-main.c
Log to stderr, allow --log=-
[petitboot] / ui / ncurses / generic-main.c
index 2d342c3ecbd74c2a93630dacfeff588a0fc6fef5..4d154eee067502cff1d93a4ee6ba44bc2cde31e1 100644 (file)
@@ -45,7 +45,8 @@ static void print_usage(void)
 {
        print_version();
        printf(
-"Usage: petitboot-nc [-h, --help] [-l, --log log-file] [-V, --version]\n");
+"Usage: petitboot-nc [-d, --start-daemon] [-h, --help] [-l, --log log-file]\n"
+"                    [-V, --version]\n");
 }
 
 /**
@@ -59,6 +60,7 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no};
  */
 
 struct opts {
+       enum opt_value start_daemon;
        enum opt_value show_help;
        const char *log_file;
        enum opt_value show_version;
@@ -71,12 +73,13 @@ struct opts {
 static int opts_parse(struct opts *opts, int argc, char *argv[])
 {
        static const struct option long_options[] = {
-               {"help",    no_argument,       NULL, 'h'},
-               {"log",     required_argument, NULL, 'l'},
-               {"version", no_argument,       NULL, 'V'},
-               { NULL,     0,                 NULL, 0},
+               {"start-daemon", no_argument,       NULL, 'd'},
+               {"help",         no_argument,       NULL, 'h'},
+               {"log",          required_argument, NULL, 'l'},
+               {"version",      no_argument,       NULL, 'V'},
+               { NULL,          0,                 NULL, 0},
        };
-       static const char short_options[] = "hl:V";
+       static const char short_options[] = "dhl:V";
        static const struct opts default_values = {
                .log_file = "/var/log/petitboot/petitboot-nc.log",
        };
@@ -91,6 +94,9 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
                        break;
 
                switch (c) {
+               case 'd':
+                       opts->start_daemon = opt_yes;
+                       break;
                case 'h':
                        opts->show_help = opt_yes;
                        break;
@@ -228,7 +234,6 @@ int main(int argc, char *argv[])
        static struct opts opts;
        int result;
        int cui_result;
-       FILE *log;
 
        result = opts_parse(&opts, argc, argv);
 
@@ -247,9 +252,13 @@ int main(int argc, char *argv[])
                return EXIT_SUCCESS;
        }
 
-       log = fopen(opts.log_file, "a");
-       assert(log);
-       pb_log_set_stream(log);
+       if (strcmp(opts.log_file, "-")) {
+               FILE *log = fopen(opts.log_file, "a");
+
+               assert(log);
+               pb_log_set_stream(log);
+       } else
+               pb_log_set_stream(stderr);
 
 #if defined(DEBUG)
        pb_log_always_flush(1);
@@ -269,7 +278,7 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
-       pb.cui = cui_init(&pb, pb_kexec_cb, NULL);
+       pb.cui = cui_init(&pb, pb_kexec_cb, NULL, opts.start_daemon);
 
        if (!pb.cui)
                return EXIT_FAILURE;