bb_copyfd_exact_size(archive_handle->src_fd, p[1], -file_header->size);
close(p[1]);
- if (safe_waitpid(pid, &status, 0) == -1)
- bb_perror_msg_and_die("waitpid");
+ status = wait_for_exitstatus(pid);
if (WIFEXITED(status) && WEXITSTATUS(status))
bb_error_msg_and_die("'%s' returned status %d",
archive_handle->tar__to_command, WEXITSTATUS(status));
void xsetegid(gid_t egid) FAST_FUNC;
void xseteuid(uid_t euid) FAST_FUNC;
void xchdir(const char *path) FAST_FUNC;
+void xfchdir(int fd) FAST_FUNC;
void xchroot(const char *path) FAST_FUNC;
void xsetenv(const char *key, const char *value) FAST_FUNC;
void bb_unsetenv(const char *key) FAST_FUNC;
* if (rc > 0) bb_error_msg("exit code: %d", rc & 0xff);
*/
int wait4pid(pid_t pid) FAST_FUNC;
+int wait_for_exitstatus(pid_t pid) FAST_FUNC;
/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
int spawn_and_wait(char **argv) FAST_FUNC;
/* Does NOT check that applet is NOFORK, just blindly runs it */
return WTERMSIG(status) + 0x180;
return 0;
}
+
+// Useful when we do know that pid is valid, and we just want to wait
+// for it to exit. Not existing pid is fatal. waitpid() status is not returned.
+int FAST_FUNC wait_for_exitstatus(pid_t pid)
+{
+ int exit_status, n;
+
+ n = safe_waitpid(pid, &exit_status, 0);
+ if (n < 0)
+ bb_perror_msg_and_die("waitpid");
+ return exit_status;
+}
bb_perror_msg_and_die("can't change directory to '%s'", path);
}
+void FAST_FUNC xfchdir(int fd)
+{
+ if (fchdir(fd))
+ bb_perror_msg_and_die("fchdir");
+}
+
void FAST_FUNC xchroot(const char *path)
{
if (chroot(path))
xsetenv(d->d_name, buf);
}
closedir(dir);
- if (fchdir(wdir) == -1)
- bb_perror_msg_and_die("fchdir");
+ xfchdir(wdir);
close(wdir);
}
}
}
-// TODO: move to libbb
-static int wait_for_exitstatus(pid_t pid)
-{
- int exit_status, n;
-
- n = safe_waitpid(pid, &exit_status, 0);
- if (n < 0)
- bb_perror_msg_and_die("waitpid");
- return exit_status;
-}
-
/*
* Longest possible path to a procfs file used in unshare. Must be able to
* contain the '/proc/' string, the '/ns/user' string which is the longest