2 #if defined(HAVE_CONFIG_H)
11 #include <sys/types.h>
15 #include <talloc/talloc.h>
18 const struct pb_system_apps pb_system_apps = {
20 .kexec = "/sbin/kexec",
21 .mount = "/bin/mount",
22 .sftp = "/usr/bin/sftp",
23 .tftp = "/usr/bin/tftp",
24 .umount = "/bin/umount",
25 .wget = "/usr/bin/wget",
28 int pb_mkdir_recursive(const char *dir)
37 if (!stat(dir, &statbuf)) {
38 if (!S_ISDIR(statbuf.st_mode)) {
39 pb_log("%s: %s exists, but isn't a directory\n",
46 str = talloc_strdup(NULL, dir);
47 sep = strchr(*str == '/' ? str + 1 : str, '/');
51 /* terminate the path at sep */
55 if (mkdir(str, mode) && errno != EEXIST) {
56 pb_log("mkdir(%s): %s\n", str, strerror(errno));
63 /* reset dir to the full path */
65 sep = strchr(sep + 1, '/');
73 int pb_rmdir_recursive(const char *base, const char *dir)
77 /* sanity check: make sure that dir is within base */
78 if (strncmp(base, dir, strlen(base)))
81 cur = talloc_strdup(NULL, dir);
83 while (strcmp(base, dir)) {
87 /* null-terminate at the last slash */
88 pos = strrchr(dir, '/');
101 * pb_run_cmd - Run the supplied command.
102 * @cmd_argv: An argument list array for execv.
105 int pb_run_cmd(const char *const *cmd_argv)
116 const char *const *p = cmd_argv;
118 pb_log("%s: ", __func__);
125 pb_log("%s: %s\n", __func__, cmd_argv[0]);
129 pb_log("%s: fork failed: %s\n", __func__, strerror(errno));
134 execvp(cmd_argv[0], (char *const *)cmd_argv);
135 pb_log("%s: exec failed: %s\n", __func__, strerror(errno));
139 if (waitpid(pid, &status, 0) == -1) {
140 pb_log("%s: waitpid failed: %s\n", __func__,
145 if (do_debug && WIFSIGNALED(status) && WTERMSIG(status) == SIGINT)
146 pb_log("%s: signaled\n", __func__);
148 if (!WIFEXITED(status)) {
149 pb_log("%s: %s failed\n", __func__, cmd_argv[0]);
153 if (WEXITSTATUS(status))
154 pb_log("%s: WEXITSTATUS %d\n", __func__, WEXITSTATUS(status));
156 return WEXITSTATUS(status);