+ _exit (EXIT_FAILURE);
+ }
+
+ if (flag_copy_stdin) {
+ int fd = flags & COMMAND_FLAG_FD_MASK;
+
+ stdin_pid = fork ();
+ if (stdin_pid == -1) {
+ perror ("fork");
+ abort ();
+ }
+
+ if (stdin_pid == 0) { /* Child process copying stdin. */
+ close (so_fd[0]);
+ close (so_fd[1]);
+ close (se_fd[0]);
+ close (se_fd[1]);
+
+ close (1);
+ dup2 (stdin_fd[1], 1);
+ close (stdin_fd[0]);
+ close (stdin_fd[1]);
+
+ if (chroot (sysroot) == -1) {
+ perror ("chroot");
+ _exit (EXIT_FAILURE);
+ }
+
+ ssize_t n;
+ char buffer[BUFSIZ];
+ while ((n = read (fd, buffer, sizeof buffer)) > 0) {
+ if (xwrite (1, buffer, n) == -1)
+ /* EPIPE error indicates the command process has exited
+ * early. If the command process fails that will be caught
+ * by the daemon, and if not, then it's not an error.
+ */
+ _exit (errno == EPIPE ? EXIT_SUCCESS : EXIT_FAILURE);
+ }
+
+ if (n == -1) {
+ perror ("read");
+ _exit (EXIT_FAILURE);
+ }
+
+ if (close (fd) == -1) {
+ perror ("close");
+ _exit (EXIT_FAILURE);
+ }
+
+ _exit (EXIT_SUCCESS);
+ }
+
+ close (fd);
+ close (stdin_fd[0]);
+ close (stdin_fd[1]);