lib/process: replace pb_run_cmd_pipe
[petitboot] / discover / boot.c
index f9b0223bdf43c42adc30ba439b71ee156eb59a30..d9c606f9a5914acbf79104f1f90e79f337f2a2b3 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <log/log.h>
 #include <pb-protocol/pb-protocol.h>
+#include <process/process.h>
 #include <system/system.h>
 #include <talloc/talloc.h>
 #include <url/url.h>
@@ -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);
        }