X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fsystem%2Fsystem.c;h=6e80b24ec1eaac9176629af6799f292546c668a1;hp=7371445a876d0bdbd8e7ad2d7da49a5aa266e743;hb=51c6aaf7864eb65779d548ee2549caa357f71e2c;hpb=c763f15030565eef2e8b28fdf471ef3e7dd9b933 diff --git a/lib/system/system.c b/lib/system/system.c index 7371445..6e80b24 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -17,14 +17,17 @@ #include "system.h" const struct pb_system_apps pb_system_apps = { - .cp = "/bin/cp", - .kexec = "/sbin/kexec", - .mount = "/bin/mount", - .shutdown = "/sbin/shutdown", - .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, + .ip = HOST_PROG_IP, + .udhcpc = HOST_PROG_UDHCPC, }; int pb_mkdir_recursive(const char *dir) @@ -98,73 +101,3 @@ int pb_rmdir_recursive(const char *base, const char *dir) return 0; } - -/** - * pb_run_cmd - Run the supplied command. - * @cmd_argv: An argument list array for execv. - */ - -int pb_run_cmd(const char *const *cmd_argv) -{ -#if defined(DEBUG) - enum {do_debug = 1}; -#else - enum {do_debug = 0}; -#endif - int status; - pid_t pid; - - if (do_debug) { - const char *const *p = cmd_argv; - - pb_log("%s: ", __func__); - while (*p) { - pb_log("%s ", *p); - p++; - } - pb_log("\n"); - } else - pb_log("%s: %s\n", __func__, cmd_argv[0]); - - pid = fork(); - - if (pid == -1) { - pb_log("%s: fork failed: %s\n", __func__, strerror(errno)); - return -1; - } - - if (pid == 0) { - int log = fileno(pb_log_get_stream()); - - /* Redirect child output to log. */ - - status = dup2(log, STDOUT_FILENO); - assert(status != -1); - - status = dup2(log, STDERR_FILENO); - assert(status != -1); - - execvp(cmd_argv[0], (char *const *)cmd_argv); - pb_log("%s: exec failed: %s\n", __func__, strerror(errno)); - exit(EXIT_FAILURE); - } - - if (waitpid(pid, &status, 0) == -1) { - pb_log("%s: waitpid failed: %s\n", __func__, - strerror(errno)); - return -1; - } - - if (do_debug && WIFSIGNALED(status) && WTERMSIG(status) == SIGINT) - pb_log("%s: signaled\n", __func__); - - if (!WIFEXITED(status)) { - pb_log("%s: %s failed\n", __func__, cmd_argv[0]); - return -1; - } - - if (WEXITSTATUS(status)) - pb_log("%s: WEXITSTATUS %d\n", __func__, WEXITSTATUS(status)); - - return WEXITSTATUS(status); -}