X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fboot.c;h=d9c606f9a5914acbf79104f1f90e79f337f2a2b3;hp=f9b0223bdf43c42adc30ba439b71ee156eb59a30;hb=823958fb;hpb=d20e98b93afaf25faca4db2a3583c191bdabe439;ds=sidebyside diff --git a/discover/boot.c b/discover/boot.c index f9b0223..d9c606f 100644 --- a/discover/boot.c +++ b/discover/boot.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -244,29 +245,44 @@ static void run_boot_hooks(struct boot_task *task, boot_status_fn status_fn, for (i = 0; i < n; i++) { const char *argv[2] = { NULL, NULL }; - char *path, *buf; - int buf_len, rc; + struct process *process; + char *path; + int rc; path = join_paths(task, boot_hook_dir, hooks[i]->d_name); - if (access(path, X_OK)) + if (access(path, X_OK)) { + talloc_free(path); continue; + } - pb_log("running boot hook %s\n", hooks[i]->d_name); + process = process_create(task); argv[0] = path; - rc = pb_run_cmd_pipe(argv, 1, task->dry_run, task, - &buf, &buf_len); - - /* if the hook returned with BOOT_HOOK_EXIT_UPDATE, - * then we process stdout to look for updated params - */ - if (rc == BOOT_HOOK_EXIT_UPDATE) { - boot_hook_update(task, hooks[i]->d_name, buf); - boot_hook_setenv(task); + process->path = path; + process->argv = argv; + process->keep_stdout = true; + + pb_log("running boot hook %s\n", hooks[i]->d_name); + + rc = process_run_sync(process); + if (rc) { + pb_log("boot hook exec failed!\n"); + + } else if (WIFEXITED(process->exit_status) && + WEXITSTATUS(process->exit_status) + == BOOT_HOOK_EXIT_UPDATE) { + /* if the hook returned with BOOT_HOOK_EXIT_UPDATE, + * then we process stdout to look for updated params + */ + if (rc == BOOT_HOOK_EXIT_UPDATE) { + boot_hook_update(task, hooks[i]->d_name, + process->stdout_buf); + boot_hook_setenv(task); + } } - talloc_free(buf); + process_release(process); talloc_free(path); }