summaryrefslogtreecommitdiffstats
path: root/ui/ncurses
diff options
context:
space:
mode:
authorGeoff Levand <geoff@infradead.org>2012-03-30 16:58:32 -0700
committerGeoff Levand <geoff@infradead.org>2012-03-30 18:08:57 -0700
commit52b9db95764fcdee9195113d7df225634a19c9f4 (patch)
treec1d649ca1316a816430728ce097acb1806f2fad9 /ui/ncurses
parent45e253470f2cd7c6dfc38e7f533c62c454039873 (diff)
downloadtalos-petitboot-52b9db95764fcdee9195113d7df225634a19c9f4.tar.gz
talos-petitboot-52b9db95764fcdee9195113d7df225634a19c9f4.zip
Cleanup --dry-run option code
Signed-off-by: Geoff Levand <geoff@infradead.org>
Diffstat (limited to 'ui/ncurses')
-rw-r--r--ui/ncurses/generic-main.c21
-rw-r--r--ui/ncurses/nc-cui.c7
-rw-r--r--ui/ncurses/nc-cui.h3
-rw-r--r--ui/ncurses/ps3-main.c2
4 files changed, 19 insertions, 14 deletions
diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c
index 9a22265..dfeb1ba 100644
--- a/ui/ncurses/generic-main.c
+++ b/ui/ncurses/generic-main.c
@@ -129,7 +129,6 @@ 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)
@@ -154,7 +153,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, pb->opts.dry_run);
+ return pb_run_kexec(cod->kd, pb->cui->dry_run);
}
/**
@@ -176,7 +175,9 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui)
m->on_open = cui_on_open;
- m->scr.frame.title = talloc_strdup(m, "Petitboot");
+ m->scr.frame.title = talloc_asprintf(m,
+ "Petitboot (" PACKAGE_VERSION ")%s",
+ (pb_cui->cui->dry_run ? " (dry-run)" : ""));
m->scr.frame.help = talloc_strdup(m,
"ESC=exit, Enter=accept, e=edit, o=open");
m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot");
@@ -239,26 +240,27 @@ int main(int argc, char *argv[])
static struct sigaction sa;
int result;
int cui_result;
+ struct opts opts;
- result = opts_parse(&pb.opts, argc, argv);
+ result = opts_parse(&opts, argc, argv);
if (result) {
print_usage();
return EXIT_FAILURE;
}
- if (pb.opts.show_help == opt_yes) {
+ if (opts.show_help == opt_yes) {
print_usage();
return EXIT_SUCCESS;
}
- if (pb.opts.show_version == opt_yes) {
+ if (opts.show_version == opt_yes) {
print_version();
return EXIT_SUCCESS;
}
- if (strcmp(pb.opts.log_file, "-")) {
- FILE *log = fopen(pb.opts.log_file, "a");
+ if (strcmp(opts.log_file, "-")) {
+ FILE *log = fopen(opts.log_file, "a");
assert(log);
pb_log_set_stream(log);
@@ -283,7 +285,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- pb.cui = cui_init(&pb, pb_kexec_cb, NULL, pb.opts.start_daemon);
+ pb.cui = cui_init(&pb, pb_kexec_cb, NULL, opts.start_daemon,
+ opts.dry_run);
if (!pb.cui)
return EXIT_FAILURE;
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
index 09e7a57..7db482b 100644
--- a/ui/ncurses/nc-cui.c
+++ b/ui/ncurses/nc-cui.c
@@ -111,7 +111,7 @@ int cui_run_cmd(struct pmenu_item *item)
def_prog_mode();
- result = pb_run_cmd(cmd_argv, 1);
+ result = pb_run_cmd(cmd_argv, 1, 0);
reset_prog_mode();
redrawwin(cui->current->main_ncw);
@@ -151,7 +151,7 @@ static int cui_run_kexec(struct pmenu_item *item)
clear();
mvaddstr(1, 0, "system is going down now...");
refresh();
- sleep(60);
+ sleep(cui->dry_run ? 1 : 60);
}
pb_log("%s: failed: %s\n", __func__, cod->kd->image);
@@ -534,7 +534,7 @@ static struct discover_client_ops cui_client_ops = {
struct cui *cui_init(void* platform_info,
int (*on_kexec)(struct cui *, struct cui_opt_data *),
- int (*js_map)(const struct js_event *e), int start_deamon)
+ int (*js_map)(const struct js_event *e), int start_deamon, int dry_run)
{
struct cui *cui;
struct discover_client *client;
@@ -552,6 +552,7 @@ struct cui *cui_init(void* platform_info,
cui->platform_info = platform_info;
cui->on_kexec = on_kexec;
cui->timer.handle_timeout = cui_handle_timeout;
+ cui->dry_run = dry_run;
/* Loop here for scripts that just started the server. */
diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h
index a4ac2e8..90eef1c 100644
--- a/ui/ncurses/nc-cui.h
+++ b/ui/ncurses/nc-cui.h
@@ -51,6 +51,7 @@ struct cui {
enum pb_nc_sig c_sig;
sig_atomic_t abort;
sig_atomic_t resize;
+ int dry_run;
struct nc_scr *current;
struct pmenu *main;
struct ui_timer timer;
@@ -62,7 +63,7 @@ struct cui {
struct cui *cui_init(void* platform_info,
int (*on_kexec)(struct cui *, struct cui_opt_data *),
- int (*js_map)(const struct js_event *e), int start_deamon);
+ int (*js_map)(const struct js_event *e), int start_deamon, int dry_run);
struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr);
int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item);
int cui_ked_run(struct pmenu_item *item);
diff --git a/ui/ncurses/ps3-main.c b/ui/ncurses/ps3-main.c
index 69913ed..26d2591 100644
--- a/ui/ncurses/ps3-main.c
+++ b/ui/ncurses/ps3-main.c
@@ -307,7 +307,7 @@ static int ps3_kexec_cb(struct cui *cui, struct cui_opt_data *cod)
} else
altered_args = 0;
- result = pb_run_kexec(cod->kd);
+ result = pb_run_kexec(cod->kd, ps3->cui->dry_run);
if (altered_args) {
talloc_free(cod->kd->args);
OpenPOWER on IntegriCloud