close(fd);
}
+/**
+ * waitchild() - Wait for a process to exit successfully
+ * @pid: PID of the process to wait for
+ *
+ * Wait for a process to exit successfully. If it exits with a non-zero return
+ * code, then exit() with the same status.
+ */
+static void waitchild(int pid)
+{
+ int rc, status;
+
+ do {
+ rc = waitpid(pid, &status, 0);
+ if (rc < 0) {
+ if (errno == EINTR)
+ continue;
+ err(EXIT_FAILURE, _("waitpid failed"));
+ }
+ if (WIFEXITED(status) &&
+ WEXITSTATUS(status) != EXIT_SUCCESS)
+ exit(WEXITSTATUS(status));
+ } while (rc < 0);
+}
+
static void bind_ns_files_from_child(pid_t *child, int fds[2])
{
char ch;
if (npersists && (pid || !forkit)) {
/* run in parent */
if (pid_bind && (unshare_flags & CLONE_NEWNS)) {
- int rc;
char ch = PIPE_SYNC_BYTE;
/* signal child we are ready */
fds[1] = -1;
/* wait for bind_ns_files_from_child() */
- do {
- rc = waitpid(pid_bind, &status, 0);
- if (rc < 0) {
- if (errno == EINTR)
- continue;
- err(EXIT_FAILURE, _("waitpid failed"));
- }
- if (WIFEXITED(status) &&
- WEXITSTATUS(status) != EXIT_SUCCESS)
- return WEXITSTATUS(status);
- } while (rc < 0);
+ waitchild(pid_bind);
} else
/* simple way, just bind */
bind_ns_files(getpid());