]> git.ozlabs.org Git - petitboot/commitdiff
Add UI option --dry-run
authorGeoff Levand <geoff@infradead.org>
Wed, 28 Mar 2012 02:59:09 +0000 (19:59 -0700)
committerGeoff Levand <geoff@infradead.org>
Wed, 28 Mar 2012 02:59:09 +0000 (19:59 -0700)
Signed-off-by: Geoff Levand <geoff@infradead.org>
ui/common/ui-system.c
ui/common/ui-system.h
ui/ncurses/generic-main.c
ui/twin/main-generic.c
ui/twin/pbt-client.c
ui/twin/pbt-client.h
ui/twin/pbt-main.c
ui/twin/pbt-main.h

index 8604848e4c5363c13686cae1897b5c10f02f6b6e..4b0f144e41eb2d64cce7812e421236e4cb761042 100644 (file)
@@ -64,7 +64,7 @@ int pb_start_daemon(void)
  */
 
 static int kexec_load(const char *l_image, const char *l_initrd,
  */
 
 static int kexec_load(const char *l_image, const char *l_initrd,
-       const char *args)
+       const char *args, int dry_run)
 {
        int result;
        const char *argv[6];
 {
        int result;
        const char *argv[6];
@@ -91,7 +91,7 @@ static int kexec_load(const char *l_image, const char *l_initrd,
        *p++ = l_image;                 /* 5 */
        *p++ = NULL;                    /* 6 */
 
        *p++ = l_image;                 /* 5 */
        *p++ = NULL;                    /* 6 */
 
-       result = pb_run_cmd(argv, 1);
+       result = dry_run ? 0 : pb_run_cmd(argv, 1);
 
        if (result)
                pb_log("%s: failed: (%d)\n", __func__, result);
 
        if (result)
                pb_log("%s: failed: (%d)\n", __func__, result);
@@ -108,9 +108,9 @@ static int kexec_load(const char *l_image, const char *l_initrd,
  * Must only be called after a successful call to kexec_load().
  */
 
  * Must only be called after a successful call to kexec_load().
  */
 
-static int kexec_reboot(void)
+static int kexec_reboot(int dry_run)
 {
 {
-       int result;
+       int result = 0;
        const char *argv[4];
        const char **p;
 
        const char *argv[4];
        const char **p;
 
@@ -122,7 +122,7 @@ static int kexec_reboot(void)
        *p++ =  "now";                  /* 3 */
        *p++ =  NULL;                   /* 4 */
 
        *p++ =  "now";                  /* 3 */
        *p++ =  NULL;                   /* 4 */
 
-       result = pb_run_cmd(argv, 1);
+       result = dry_run ? 0 : pb_run_cmd(argv, 1);
 
        /* On error, force a kexec with the -e option */
 
 
        /* On error, force a kexec with the -e option */
 
@@ -145,7 +145,7 @@ static int kexec_reboot(void)
  * pb_run_kexec - Run kexec with the supplied boot options.
  */
 
  * pb_run_kexec - Run kexec with the supplied boot options.
  */
 
-int pb_run_kexec(const struct pb_kexec_data *kd)
+int pb_run_kexec(const struct pb_kexec_data *kd, int dry_run)
 {
        int result;
        char *l_image = NULL;
 {
        int result;
        char *l_image = NULL;
@@ -153,9 +153,10 @@ int pb_run_kexec(const struct pb_kexec_data *kd)
        unsigned int clean_image = 0;
        unsigned int clean_initrd = 0;
 
        unsigned int clean_image = 0;
        unsigned int clean_initrd = 0;
 
-       pb_log("%s: image:  '%s'\n", __func__, kd->image);
-       pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
-       pb_log("%s: args:   '%s'\n", __func__, kd->args);
+       pb_log("%s: image:   '%s'\n", __func__, kd->image);
+       pb_log("%s: initrd:  '%s'\n", __func__, kd->initrd);
+       pb_log("%s: args:    '%s'\n", __func__, kd->args);
+       pb_log("%s: dry_run: '%d'\n", __func__, dry_run);
 
        result = -1;
 
 
        result = -1;
 
@@ -174,7 +175,7 @@ int pb_run_kexec(const struct pb_kexec_data *kd)
        if (!l_image && !l_initrd)
                goto no_load;
 
        if (!l_image && !l_initrd)
                goto no_load;
 
-       result = kexec_load(l_image, l_initrd, kd->args);
+       result = kexec_load(l_image, l_initrd, kd->args, dry_run);
 
 no_load:
        if (clean_image)
 
 no_load:
        if (clean_image)
@@ -186,7 +187,7 @@ no_load:
        talloc_free(l_initrd);
 
        if (!result)
        talloc_free(l_initrd);
 
        if (!result)
-               result = kexec_reboot();
+               result = kexec_reboot(dry_run);
 
        return result;
 }
 
        return result;
 }
index 87ab89126f8b6494a1df0e5faaf4a1340124ab4e..63d1a92d2374166cfb51ffbfa64f5a487adb3869 100644 (file)
@@ -31,7 +31,7 @@ struct pb_kexec_data {
        char *args;
 };
 
        char *args;
 };
 
-int pb_run_kexec(const struct pb_kexec_data *kd);
+int pb_run_kexec(const struct pb_kexec_data *kd, int dry_run);
 int pb_start_daemon(void);
 
 unsigned int pb_elf_hash(const char *str);
 int pb_start_daemon(void);
 
 unsigned int pb_elf_hash(const char *str);
index 4d154eee067502cff1d93a4ee6ba44bc2cde31e1..9a22265811bd3c87cb49e4191a817160d24d2ff0 100644 (file)
@@ -45,8 +45,8 @@ static void print_usage(void)
 {
        print_version();
        printf(
 {
        print_version();
        printf(
-"Usage: petitboot-nc [-d, --start-daemon] [-h, --help] [-l, --log log-file]\n"
-"                    [-V, --version]\n");
+"Usage: petitboot-nc [-d, --dry-run] [-h, --help] [-l, --log log-file]\n"
+"                    [-s, --start-daemon] [-V, --version]\n");
 }
 
 /**
 }
 
 /**
@@ -60,9 +60,10 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no};
  */
 
 struct opts {
  */
 
 struct opts {
-       enum opt_value start_daemon;
+       enum opt_value dry_run;
        enum opt_value show_help;
        const char *log_file;
        enum opt_value show_help;
        const char *log_file;
+       enum opt_value start_daemon;
        enum opt_value show_version;
 };
 
        enum opt_value show_version;
 };
 
@@ -73,13 +74,14 @@ struct opts {
 static int opts_parse(struct opts *opts, int argc, char *argv[])
 {
        static const struct option long_options[] = {
 static int opts_parse(struct opts *opts, int argc, char *argv[])
 {
        static const struct option long_options[] = {
-               {"start-daemon", no_argument,       NULL, 'd'},
+               {"dry-run",      no_argument,       NULL, 'd'},
                {"help",         no_argument,       NULL, 'h'},
                {"log",          required_argument, NULL, 'l'},
                {"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},
        };
                {"version",      no_argument,       NULL, 'V'},
                { NULL,          0,                 NULL, 0},
        };
-       static const char short_options[] = "dhl:V";
+       static const char short_options[] = "dhl:sV";
        static const struct opts default_values = {
                .log_file = "/var/log/petitboot/petitboot-nc.log",
        };
        static const struct opts default_values = {
                .log_file = "/var/log/petitboot/petitboot-nc.log",
        };
@@ -95,7 +97,7 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
 
                switch (c) {
                case 'd':
 
                switch (c) {
                case 'd':
-                       opts->start_daemon = opt_yes;
+                       opts->dry_run = opt_yes;
                        break;
                case 'h':
                        opts->show_help = opt_yes;
                        break;
                case 'h':
                        opts->show_help = opt_yes;
@@ -103,6 +105,9 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
                case 'l':
                        opts->log_file = optarg;
                        break;
                case 'l':
                        opts->log_file = optarg;
                        break;
+               case 's':
+                       opts->start_daemon = opt_yes;
+                       break;
                case 'V':
                        opts->show_version = opt_yes;
                        break;
                case 'V':
                        opts->show_version = opt_yes;
                        break;
@@ -124,6 +129,7 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
 struct pb_cui {
        struct pmenu *mm;
        struct cui *cui;
 struct pb_cui {
        struct pmenu *mm;
        struct cui *cui;
+       struct opts opts;
 };
 
 static struct pb_cui *pb_from_cui(struct cui *cui)
 };
 
 static struct pb_cui *pb_from_cui(struct cui *cui)
@@ -148,7 +154,7 @@ static int pb_kexec_cb(struct cui *cui, struct cui_opt_data *cod)
 
        assert(pb->cui->current == &pb->cui->main->scr);
 
 
        assert(pb->cui->current == &pb->cui->main->scr);
 
-       return pb_run_kexec(cod->kd);
+       return pb_run_kexec(cod->kd, pb->opts.dry_run);
 }
 
 /**
 }
 
 /**
@@ -231,29 +237,28 @@ static void sig_handler(int signum)
 int main(int argc, char *argv[])
 {
        static struct sigaction sa;
 int main(int argc, char *argv[])
 {
        static struct sigaction sa;
-       static struct opts opts;
        int result;
        int cui_result;
 
        int result;
        int cui_result;
 
-       result = opts_parse(&opts, argc, argv);
+       result = opts_parse(&pb.opts, argc, argv);
 
        if (result) {
                print_usage();
                return EXIT_FAILURE;
        }
 
 
        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;
        }
 
                print_usage();
                return EXIT_SUCCESS;
        }
 
-       if (opts.show_version == opt_yes) {
+       if (pb.opts.show_version == opt_yes) {
                print_version();
                return EXIT_SUCCESS;
        }
 
                print_version();
                return EXIT_SUCCESS;
        }
 
-       if (strcmp(opts.log_file, "-")) {
-               FILE *log = fopen(opts.log_file, "a");
+       if (strcmp(pb.opts.log_file, "-")) {
+               FILE *log = fopen(pb.opts.log_file, "a");
 
                assert(log);
                pb_log_set_stream(log);
 
                assert(log);
                pb_log_set_stream(log);
@@ -278,7 +283,7 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
                return EXIT_FAILURE;
        }
 
-       pb.cui = cui_init(&pb, pb_kexec_cb, NULL, opts.start_daemon);
+       pb.cui = cui_init(&pb, pb_kexec_cb, NULL, pb.opts.start_daemon);
 
        if (!pb.cui)
                return EXIT_FAILURE;
 
        if (!pb.cui)
                return EXIT_FAILURE;
index 7cf510a44c2ebefebf485e3a6fb5f9f25bd5f158..1e665b38384a9c874ce8a86298f287c54f6ff530 100644 (file)
@@ -199,7 +199,7 @@ fail_menu:
        return NULL;
 }
 
        return NULL;
 }
 
-static int kexec_cb(__attribute__((unused)) struct pbt_client *client, struct pb_opt_data *opt_data)
+static int kexec_cb(struct pbt_client *client, struct pb_opt_data *opt_data)
 {
        int result;
 
 {
        int result;
 
@@ -207,7 +207,7 @@ static int kexec_cb(__attribute__((unused)) struct pbt_client *client, struct pb
 
        pb_log("%s: %s\n", __func__, opt_data->name);
 
 
        pb_log("%s: %s\n", __func__, opt_data->name);
 
-       result = pb_run_kexec(opt_data->kd);
+       result = pb_run_kexec(opt_data->kd, client->dry_run);
 
        return result;
 }
 
        return result;
 }
@@ -331,7 +331,7 @@ int main(int argc, char *argv[])
        }
 
        client = pbt_client_init(opts.backend, 900, 300, kexec_cb,
        }
 
        client = pbt_client_init(opts.backend, 900, 300, kexec_cb,
-               opts.start_daemon);
+               opts.start_daemon, opts.dry_run);
 
        if (!client) {
                ui_result = EXIT_FAILURE;
 
        if (!client) {
                ui_result = EXIT_FAILURE;
index 711248a61dec2da4870f835f0d24538948804f3e..1170b34555664c449fdbb12f0c3cdaf19541cc9b 100644 (file)
@@ -262,10 +262,10 @@ static void pbt_client_destructor(struct pbt_client *client)
        memset(client, 0, sizeof(*client));
 }
 
        memset(client, 0, sizeof(*client));
 }
 
-struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int width,
-       unsigned int height,
+struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
+       unsigned int width, unsigned int height,
        int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *),
        int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *),
-       int start_deamon)
+       int start_deamon, int dry_run)
 {
        struct pbt_client *pbt_client;
        unsigned int i;
 {
        struct pbt_client *pbt_client;
        unsigned int i;
@@ -282,6 +282,7 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int w
 
        pbt_client->sig = "pbt_client";
        pbt_client->kexec_cb = kexec_cb;
 
        pbt_client->sig = "pbt_client";
        pbt_client->kexec_cb = kexec_cb;
+       pbt_client->dry_run = dry_run;
        pbt_client->frame.scr = pbt_scr_init(pbt_client, backend, width, height,
                NULL, NULL);
 
        pbt_client->frame.scr = pbt_scr_init(pbt_client, backend, width, height,
                NULL, NULL);
 
index 119bc9465065ab8cf2852574b7353c9ced8c4070..014d5b2dc5f94f8b103da90d21eb65515f33a83c 100644 (file)
@@ -42,6 +42,7 @@ void pbt_frame_status_printf(struct pbt_frame *frame, const char *format, ...);
 
 struct pbt_client {
        const char *sig;
 
 struct pbt_client {
        const char *sig;
+       int dry_run;
        struct pb_signal_data signal_data;
        void *client_data;
        int (*kexec_cb)(struct pbt_client *pbt_client, struct pb_opt_data *pod);
        struct pb_signal_data signal_data;
        void *client_data;
        int (*kexec_cb)(struct pbt_client *pbt_client, struct pb_opt_data *pod);
@@ -53,7 +54,7 @@ struct pbt_client {
 struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
        unsigned int width, unsigned int height,
        int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *),
 struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
        unsigned int width, unsigned int height,
        int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *),
-       int start_deamon);
+       int start_deamon, int dry_run);
 void pbt_client_destroy(struct pbt_client *client);
 void pbt_client_resize(struct pbt_client *client);
 
 void pbt_client_destroy(struct pbt_client *client);
 void pbt_client_resize(struct pbt_client *client);
 
index a8c1ea5fe2408acfceda14079087fc62e2373eda..84e824e412e530f70f6427948b611ea48e071733 100644 (file)
@@ -34,8 +34,9 @@ void pbt_print_usage(void)
 {
        pbt_print_version();
        printf(
 {
        pbt_print_version();
        printf(
-"Usage: petitboot-twin [-d, --start-daemon] [-h, --help] [-l, --log log-file]\n"
-"                      [-r, --reset-defaults][-t, --timeout] [-V, --version]\n"
+"Usage: petitboot-twin [-d, --dry-run] [-h, --help] [-l, --log log-file]\n"
+"                      [-r, --reset-defaults] [-s, --start-daemon]\n"
+"                      [-t, --timeout] [-V, --version]\n"
 "                      [[-f --fbdev] | [-x --x11]]\n");
 }
 
 "                      [[-f --fbdev] | [-x --x11]]\n");
 }
 
@@ -46,17 +47,18 @@ void pbt_print_usage(void)
 int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[])
 {
        static const struct option long_options[] = {
 int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[])
 {
        static const struct option long_options[] = {
-               {"start-daemon",   no_argument,       NULL, 'd'},
+               {"dry-run",        no_argument,       NULL, 'd'},
                {"fbdev",          no_argument,       NULL, 'f'},
                {"help",           no_argument,       NULL, 'h'},
                {"log",            required_argument, NULL, 'l'},
                {"reset-defaults", no_argument,       NULL, 'r'},
                {"fbdev",          no_argument,       NULL, 'f'},
                {"help",           no_argument,       NULL, 'h'},
                {"log",            required_argument, NULL, 'l'},
                {"reset-defaults", no_argument,       NULL, 'r'},
+               {"start-daemon",   no_argument,       NULL, 's'},
                {"timeout",        no_argument,       NULL, 't'},
                {"version",        no_argument,       NULL, 'V'},
                {"x11",            no_argument,       NULL, 'x'},
                { NULL, 0, NULL, 0},
        };
                {"timeout",        no_argument,       NULL, 't'},
                {"version",        no_argument,       NULL, 'V'},
                {"x11",            no_argument,       NULL, 'x'},
                { NULL, 0, NULL, 0},
        };
-       static const char short_options[] = "dfhl:trVx";
+       static const char short_options[] = "dfhl:strVx";
        static const struct pbt_opts default_values = {
                .backend = pbt_twin_x11,
                .log_file = "/var/log/petitboot/petitboot-twin.log",
        static const struct pbt_opts default_values = {
                .backend = pbt_twin_x11,
                .log_file = "/var/log/petitboot/petitboot-twin.log",
@@ -73,7 +75,7 @@ int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[])
 
                switch (c) {
                case 'd':
 
                switch (c) {
                case 'd':
-                       opts->start_daemon = pbt_opt_yes;
+                       opts->dry_run = pbt_opt_yes;
                        break;
                case 'f':
                        opts->backend = pbt_twin_fbdev;
                        break;
                case 'f':
                        opts->backend = pbt_twin_fbdev;
@@ -84,6 +86,9 @@ int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[])
                case 'l':
                        opts->log_file = optarg;
                        break;
                case 'l':
                        opts->log_file = optarg;
                        break;
+               case 's':
+                       opts->start_daemon = pbt_opt_yes;
+                       break;
                case 't':
                        opts->use_timeout = pbt_opt_yes;
                        break;
                case 't':
                        opts->use_timeout = pbt_opt_yes;
                        break;
index 47985a1002cebee672b665566260aa51f82572cb..e5af71ab856201acd76ec2334a223599eda85bfc 100644 (file)
@@ -31,11 +31,12 @@ enum pbt_opt_value {pbt_opt_undef = 0, pbt_opt_yes, pbt_opt_no};
  */
 
 struct pbt_opts {
  */
 
 struct pbt_opts {
-       enum pbt_opt_value start_daemon;
        enum pbt_twin_backend backend;
        enum pbt_twin_backend backend;
+       enum pbt_opt_value dry_run;
        enum pbt_opt_value show_help;
        const char *log_file;
        enum pbt_opt_value reset_defaults;
        enum pbt_opt_value show_help;
        const char *log_file;
        enum pbt_opt_value reset_defaults;
+       enum pbt_opt_value start_daemon;
        enum pbt_opt_value use_timeout;
        enum pbt_opt_value show_version;
 };
        enum pbt_opt_value use_timeout;
        enum pbt_opt_value show_version;
 };