stdout_pair.read_fd = stdout_pair.write_fd = -1;
chain_open (stdin_fd, pp_args, p_child)     int stdin_fd;     t_pchar *pp_args;     pid_t *p_child;{  t_fd_pair stdout_pair = {-1, -1};  pid_t ch_id;  char *pz_cmd;  /*   *  Create a pipe it will be the child process' stdout,   *  and the parent will read from it.   */  if (pipe ((int *) &stdout_pair) < 0)    {      if (p_child != (pid_t *) NULL)        *p_child = NOPROCESS;      return -1;    }  /*   *  If we did not get an arg list, use the default   */  if (pp_args == (t_pchar *) NULL)    pp_args = def_args;  /*   *  If the arg list does not have a program,   *  assume the "SHELL" from the environment, or, failing   *  that, then sh.  Set argv[0] to whatever we decided on.   */  if (pz_cmd = *pp_args,      (pz_cmd == (char *) NULL) || (*pz_cmd == '\0'))    {      pz_cmd = getenv ("SHELL");      if (pz_cmd == (char *) NULL)        pz_cmd = "sh";    }#ifdef DEBUG_PRINT  printf ("START:  %s\n", pz_cmd);  {    int idx = 0;        while (pp_args[++idx] != (char *) NULL)      printf ("  ARG %2d:  %s\n", idx, pp_args[idx]);  }#endif  /*   *  Call fork() and see which process we become   */  ch_id = fork ();  switch (ch_id)    {    case NOPROCESS:             /* parent - error in call */      close (stdout_pair.read_fd);      close (stdout_pair.write_fd);      if (p_child != (pid_t *) NULL)        *p_child = NOPROCESS;      return -1;    default:                    /* parent - return opposite FD's */      if (p_child != (pid_t *) NULL)        *p_child = ch_id;#ifdef DEBUG_PRINT      printf ("for pid %d:  stdin from %d, stdout to %d\n"              "for parent:  read from %d\n",              ch_id, stdin_fd, stdout_pair.write_fd, stdout_pair.read_fd);#endif      close (stdin_fd);      close (stdout_pair.write_fd);      return stdout_pair.read_fd;    case NULLPROCESS:           /* child - continue processing */      break;    }  /*   *  Close the pipe end handed back to the parent process   */  close (stdout_pair.read_fd);  /*   *  Close our current stdin and stdout   */  close (STDIN_FILENO);  close (STDOUT_FILENO);  /*   *  Make the fd passed in the stdin, and the write end of   *  the new pipe become the stdout.   */  fcntl (stdout_pair.write_fd, F_DUPFD, STDOUT_FILENO);  fcntl (stdin_fd, F_DUPFD, STDIN_FILENO);  if (*pp_args == (char *) NULL)    *pp_args = pz_cmd;  execvp (pz_cmd, pp_args);  fprintf (stderr, "Error %d:  Could not execvp( '%s', ... ):  %s\n",           errno, pz_cmd, strerror (errno));  exit (EXIT_PANIC);}