int fdin, fdout, fderr, fdcmd, pid;
int fdout, fderr, fdcmd, pid;
int forkCommand(char **args, int *outfd, int *errfd, int *cmdfd, int quiet) {   /* Fork command 'cmd', returning pid, and optionally pointer    * to open file descriptor fd */    int fdin, fdout, fderr, fdcmd, pid;    int outpipe[2], errpipe[2], fdpipe[2];    int ourpid;        if ( (pipe(outpipe)==-1) || (pipe(errpipe)==-1) || (pipe(fdpipe)==-1) ) {	perror("pipe");	return -1;    }        if (outfd) {       fdout = outpipe[1];      *outfd = outpipe[0];    } else {       if (!quiet)	 fdout=dup(1);    }    if (errfd) {       fderr = errpipe[1];      *errfd = errpipe[0];    } else {       if (!quiet)	 fderr=dup(2);    }    fdcmd = fdpipe[1];    if (cmdfd)      *cmdfd = fdpipe[0];    ourpid = getpid();    if ((pid = fork())==-1) {	perror("fork");	return -1;    }    /* We exec the command normally as the child. However, if we're getting passed     * back arguments via an fd, we'll exec it as the parent. Therefore, if Bill     * fucks up and we segfault or something, we don't kill rc.sysinit. */    if ( (cmdfd&&!pid) || (pid &&!cmdfd)) {	/* parent */	close(fdin);	close(fdout);	close(fderr);	close(fdcmd);	if (!pid)	  return ourpid;	else	  return pid;    } else {	/* kid */       if (outfd) { 	 if ( (dup2(fdout,1)==-1) ) {	    perror("dup2");	    exit(-1);	 }       } else if (quiet)	    if ((dup2(open("/dev/null",O_WRONLY),1))==-1) {	     perror("dup2");	     exit(-1);	    }       if (errfd)  {	 if ((dup2(fderr,2)==-1)) {	    perror("dup2");	    exit(-1);	 }       } else if (quiet) 	    if ((dup2(open("/dev/null",O_WRONLY),2))==-1)  {	       perror("dup2");	       exit(-1);	    }        if ((dup2(fdcmd,CMD_FD)==-1)) {	    perror("dup2");	    exit(-1);	}	close(fdout);	close(fderr);	close(fdcmd);	if (outfd)	  close(*outfd);	if (errfd)	  close(*errfd);	if (cmdfd)	  close(*cmdfd);	execvp(args[0],args);	perror("execvp");	exit(-1);    }}