argv[4] = "ro";
argv[5] = NULL;
- if (pb_run_cmd(argv, 1)) {
+ if (pb_run_cmd(argv, 1, 0)) {
/* Retry mount without ro option. */
argv[2] = ctx->mount_path;
argv[3] = NULL;
- if (pb_run_cmd(argv, 1))
+ if (pb_run_cmd(argv, 1, 0))
goto out_rmdir;
}
/**
* pb_run_cmd - Run the supplied command.
* @cmd_argv: An argument list array for execv.
+ * @wait: Wait for the child process to complete before returning.
+ * @dry_run: Don't actually fork and exec.
*/
-int pb_run_cmd(const char *const *cmd_argv, int wait)
+int pb_run_cmd(const char *const *cmd_argv, int wait, int dry_run)
{
#if defined(DEBUG)
enum {do_debug = 1};
if (do_debug) {
const char *const *p = cmd_argv;
- pb_log("%s: ", __func__);
+ pb_log("%s: %s", __func__, (dry_run ? "(dry-run) " : ""));
+
while (*p) {
pb_log("%s ", *p);
p++;
}
pb_log("\n");
} else
- pb_log("%s: %s\n", __func__, cmd_argv[0]);
+ pb_log("%s: %s%s\n", __func__, (dry_run ? "(dry-run) " : ""),
+ cmd_argv[0]);
+
+ if (dry_run)
+ return 0;
pid = fork();
extern const struct pb_system_apps pb_system_apps;
-int pb_run_cmd(const char *const *cmd_argv, int wait);
+int pb_run_cmd(const char *const *cmd_argv, int wait, int dry_run);
int pb_mkdir_recursive(const char *dir);
int pb_rmdir_recursive(const char *base, const char *dir);
*p++ = local; /* 7 */
*p++ = NULL; /* 8 */
- result = pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, 0);
talloc_free(opts);
*p++ = local; /* 4 */
*p++ = NULL; /* 5 */
- result = pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, 0);
if (result)
goto fail;
*p++ = url->port; /* 8 */
*p++ = NULL; /* 9 */
- result = pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, 0);
if (!result)
return local;
*p++ = local; /* 9 */
*p++ = NULL; /* 10 */
- result = pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, 0);
if (!result)
return local;
*p++ = "--no-check-certificate"; /* 6 */
*p++ = NULL; /* 7 */
- result = pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, 0);
if (result)
goto fail;
argv[0] = name;
argv[1] = NULL;
- result = pb_run_cmd(argv, 0);
+ result = pb_run_cmd(argv, 0, 0);
talloc_free(name);
*p++ = l_image; /* 5 */
*p++ = NULL; /* 6 */
- result = dry_run ? 0 : pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, dry_run);
if (result)
pb_log("%s: failed: (%d)\n", __func__, result);
*p++ = "now"; /* 3 */
*p++ = NULL; /* 4 */
- result = dry_run ? 0 : pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, dry_run);
/* On error, force a kexec with the -e option */
*p++ = "-e"; /* 2 */
*p++ = NULL; /* 3 */
- result = pb_run_cmd(argv, 1);
+ result = pb_run_cmd(argv, 1, 0);
}
if (result)
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;
struct pb_cui {
struct pmenu *mm;
struct cui *cui;
- struct opts opts;
};
static struct pb_cui *pb_from_cui(struct cui *cui)
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);
}
/**
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");
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);
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;
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);
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);
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;
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. */
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;
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);
} 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);
result = item->pbt_client->kexec_cb(item->pbt_client, opt_data);
if (!result) {
- //mvaddstr(1, 0, "system is going down now...");
- sleep(60);
+ sleep(item->pbt_client->dry_run ? 1 : 60);
}
pb_log("%s: failed: %s\n", __func__, opt_data->kd->image);