- if (cpid == 0) {
- /* child */
- close(pipefd[0]); /* close read end */
- close(1); /* close stdout */
- dup(pipefd[1]); /* set stdout to the write end of the pipe */
- execlp(run->name, run->name, NULL);
- /* only gets here if exec failed */
- printf("Bail Out! exec %s failed: %s\n", run->name, strerror(errno));
- exit(EXIT_FAILURE);
- }
+ cpid = fork();
+ if (cpid == -1) {
+ perror("fork");
+ exit(EXIT_FAILURE);
+ }
+
+ if (cpid == 0) {
+ /* child */
+ close(pipefd[0]); /* close read end */
+ close(1); /* close stdout */
+ dup(pipefd[1]); /* set stdout to the write end of the pipe */
+ execlp(run->name, run->name, NULL);
+ /* only gets here if exec failed */
+ printf("Bail Out! exec %s failed: %s\n", run->name, strerror(errno));
+ exit(EXIT_FAILURE);
+ }