]> git.ozlabs.org Git - petitboot/blobdiff - lib/system/system.c
discover/udev: remove unnecessary udevadm references
[petitboot] / lib / system / system.c
index 65bd6bf57bc5391cd6bc91aec5f8b48a9f553987..13dc146821958561699598040948654b7a8cc78a 100644 (file)
 #include "system.h"
 
 const struct pb_system_apps pb_system_apps = {
-       .cp = "/bin/cp",
-       .kexec = "/sbin/kexec",
-       .mount = "/bin/mount",
-       .sftp = "/usr/bin/sftp",
-       .tftp = "/usr/bin/tftp",
-       .umount = "/bin/umount",
-       .wget = "/usr/bin/wget",
+       .prefix         = PREFIX,
+       .cp             = HOST_PROG_CP,
+       .kexec          = HOST_PROG_KEXEC,
+       .mount          = HOST_PROG_MOUNT,
+       .shutdown       = HOST_PROG_SHUTDOWN,
+       .sftp           = HOST_PROG_SFTP,
+       .tftp           = HOST_PROG_TFTP,
+       .umount         = HOST_PROG_UMOUNT,
+       .wget           = HOST_PROG_WGET,
 };
 
 int pb_mkdir_recursive(const char *dir)
@@ -101,9 +103,11 @@ int pb_rmdir_recursive(const char *base, const char *dir)
 /**
  * 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 pb_run_cmd(const char *const *cmd_argv, int wait, int dry_run)
 {
 #if defined(DEBUG)
        enum {do_debug = 1};
@@ -116,14 +120,19 @@ int pb_run_cmd(const char *const *cmd_argv)
        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();
 
@@ -148,6 +157,9 @@ int pb_run_cmd(const char *const *cmd_argv)
                exit(EXIT_FAILURE);
        }
 
+       if (!wait && !waitpid(pid, &status, WNOHANG))
+               return 0;
+
        if (waitpid(pid, &status, 0) == -1) {
                pb_log("%s: waitpid failed: %s\n", __func__,
                                strerror(errno));