]> git.ozlabs.org Git - petitboot/blobdiff - lib/system/system.c
ui/ncurses: Remove pmenu_item_replace
[petitboot] / lib / system / system.c
index 13dc146821958561699598040948654b7a8cc78a..917d44447532361218eb8939b6870edc9a46a16e 100644 (file)
@@ -26,13 +26,21 @@ const struct pb_system_apps pb_system_apps = {
        .tftp           = HOST_PROG_TFTP,
        .umount         = HOST_PROG_UMOUNT,
        .wget           = HOST_PROG_WGET,
+       .ip             = HOST_PROG_IP,
+       .udhcpc         = HOST_PROG_UDHCPC,
 };
 
+#ifndef TFTP_TYPE
+#define TFTP_TYPE TFTP_TYPE_UNKNOWN
+#endif
+
+enum tftp_type tftp_type = TFTP_TYPE;
+
 int pb_mkdir_recursive(const char *dir)
 {
        struct stat statbuf;
+       int rc, mode = 0755;
        char *str, *sep;
-       int mode = 0755;
 
        if (!*dir)
                return 0;
@@ -49,6 +57,8 @@ int pb_mkdir_recursive(const char *dir)
        str = talloc_strdup(NULL, dir);
        sep = strchr(*str == '/' ? str + 1 : str, '/');
 
+       rc = 0;
+
        while (1) {
 
                /* terminate the path at sep */
@@ -57,7 +67,8 @@ int pb_mkdir_recursive(const char *dir)
 
                if (mkdir(str, mode) && errno != EEXIST) {
                        pb_log("mkdir(%s): %s\n", str, strerror(errno));
-                       return -1;
+                       rc = -1;
+                       break;
                }
 
                if (!sep)
@@ -70,7 +81,7 @@ int pb_mkdir_recursive(const char *dir)
 
        talloc_free(str);
 
-       return 0;
+       return rc;
 }
 
 int pb_rmdir_recursive(const char *base, const char *dir)
@@ -83,12 +94,12 @@ int pb_rmdir_recursive(const char *base, const char *dir)
 
        cur = talloc_strdup(NULL, dir);
 
-       while (strcmp(base, dir)) {
+       while (strcmp(base, cur)) {
 
-               rmdir(dir);
+               rmdir(cur);
 
                /* null-terminate at the last slash */
-               pos = strrchr(dir, '/');
+               pos = strrchr(cur, '/');
                if (!pos)
                        break;
 
@@ -99,83 +110,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.
- * @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 dry_run)
-{
-#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: %s", __func__, (dry_run ? "(dry-run) " : ""));
-
-               while (*p) {
-                       pb_log("%s ", *p);
-                       p++;
-               }
-               pb_log("\n");
-       } else
-               pb_log("%s: %s%s\n", __func__, (dry_run ? "(dry-run) " : ""),
-                       cmd_argv[0]);
-
-       if (dry_run)
-               return 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 (!wait && !waitpid(pid, &status, WNOHANG))
-               return 0;
-
-       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);
-}