This is execute.c in view mode; [Download] [Up]
#include <bsd/libc.h> /* first to get rid of pre-comp warning */ #include <mach/mach.h> /* first to get rid of pre-comp warning */ #include <stdio.h> #include <signal.h> #include <sys/wait.h> #include "fatals.h" #include "allocate.h" #include "execute.h" /* * execute() does an execvp using the argv passed to it. If the parameter * verbose is non-zero the command is printed to stderr. A non-zero return * value indicates success zero indicates failure. */ int execute( char **argv, long verbose) { char *name, **p; int forkpid, waitpid, termsig; union wait waitstatus; name = argv[0]; if(verbose){ fprintf(stderr, "+ %s ", name); p = &(argv[1]); while(*p != (char *)0) fprintf(stderr, "%s ", *p++); fprintf(stderr, "\n"); } forkpid = fork(); if(forkpid == -1) system_fatal("can't fork a new process to execute: %s", name); if(forkpid == 0){ if(execvp(name, argv) == -1) system_fatal("can't find or exec: %s", name); return(1); /* can't get here, removes a warning from the compiler */ } else{ waitpid = wait(&waitstatus); if(waitpid == -1) system_fatal("wait on forked process %d failed", forkpid); termsig = waitstatus.w_termsig; if(termsig != 0 && termsig != SIGINT) fatal("fatal error in %s", name); return(waitstatus.w_retcode == 0 && termsig == 0); } }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.