X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fgeneric-main.c;h=9a22265811bd3c87cb49e4191a817160d24d2ff0;hp=972490acef49d2bb8e2ee0ecc4974cbbc3f52f15;hb=59e81c46a962da51e51474e9b36258ff0e04ae42;hpb=174887a55ad4e8cbacde32de207c3deef8711fab diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 972490a..9a22265 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -38,14 +38,15 @@ static void print_version(void) { - printf("pb-cui (" PACKAGE_NAME ") " PACKAGE_VERSION "\n"); + printf("petitboot-nc (" PACKAGE_NAME ") " PACKAGE_VERSION "\n"); } static void print_usage(void) { print_version(); printf( -"Usage: pb-cui [-h, --help] [-l, --log log-file] [-V, --version]\n"); +"Usage: petitboot-nc [-d, --dry-run] [-h, --help] [-l, --log log-file]\n" +" [-s, --start-daemon] [-V, --version]\n"); } /** @@ -59,8 +60,10 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no}; */ struct opts { + enum opt_value dry_run; enum opt_value show_help; const char *log_file; + enum opt_value start_daemon; enum opt_value show_version; }; @@ -71,14 +74,16 @@ 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}, + {"dry-run", no_argument, NULL, 'd'}, + {"help", no_argument, NULL, 'h'}, + {"log", required_argument, NULL, 'l'}, + {"start-daemon", no_argument, NULL, 's'}, + {"version", no_argument, NULL, 'V'}, + { NULL, 0, NULL, 0}, }; - static const char short_options[] = "hl:V"; + static const char short_options[] = "dhl:sV"; static const struct opts default_values = { - .log_file = "pb-cui.log", + .log_file = "/var/log/petitboot/petitboot-nc.log", }; *opts = default_values; @@ -91,12 +96,18 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) break; switch (c) { + case 'd': + opts->dry_run = opt_yes; + break; case 'h': opts->show_help = opt_yes; break; case 'l': opts->log_file = optarg; break; + case 's': + opts->start_daemon = opt_yes; + break; case 'V': opts->show_version = opt_yes; break; @@ -118,6 +129,7 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) struct pb_cui { struct pmenu *mm; struct cui *cui; + struct opts opts; }; static struct pb_cui *pb_from_cui(struct cui *cui) @@ -142,7 +154,7 @@ static int pb_kexec_cb(struct cui *cui, struct cui_opt_data *cod) assert(pb->cui->current == &pb->cui->main->scr); - return pb_run_kexec(cod->kd); + return pb_run_kexec(cod->kd, pb->opts.dry_run); } /** @@ -225,37 +237,39 @@ static void sig_handler(int signum) int main(int argc, char *argv[]) { static struct sigaction sa; - static struct opts opts; int result; int cui_result; - FILE *log; - result = opts_parse(&opts, argc, argv); + result = opts_parse(&pb.opts, argc, argv); if (result) { print_usage(); return EXIT_FAILURE; } - if (opts.show_help == opt_yes) { + if (pb.opts.show_help == opt_yes) { print_usage(); return EXIT_SUCCESS; } - if (opts.show_version == opt_yes) { + if (pb.opts.show_version == opt_yes) { print_version(); return EXIT_SUCCESS; } - log = fopen(opts.log_file, "a"); - assert(log); - pb_log_set_stream(log); + if (strcmp(pb.opts.log_file, "-")) { + FILE *log = fopen(pb.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); #endif - pb_log("--- pb-cui ---\n"); + pb_log("--- petitboot-nc ---\n"); sa.sa_handler = sig_handler; result = sigaction(SIGALRM, &sa, NULL); @@ -269,7 +283,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, pb.opts.start_daemon); if (!pb.cui) return EXIT_FAILURE;