/* ECP: FILEname=fig13_18.c */ /* 1*/ #include /* Other Includes Omitted For Brevity */ /* 2*/ int /* 3*/ WrongSystem( const char *Command ) /* 4*/ { /* 5*/ pid_t Pid; /* 6*/ int Status; /* 7*/ void ( *SaveIntr )( ), ( *SaveQuit )( ); /* 8*/ if( Command == NULL ) /* 9*/ return 1; /*10*/ Pid = fork( ); /*11*/ if( Pid < 0 ) /* Error */ /*12*/ return -1; /*13*/ if( Pid == 0 ) /* Child */ /*14*/ { /*15*/ execl( "/bin/sh", "sh", "-c", Command, NULL ); /*16*/ _exit( 127 ); /* execl Failed; Give Up On Child */ /*17*/ } /*18*/ /* Parent */ /*19*/ SaveIntr = signal( SIGINT, SIG_IGN ); /* Ignore */ /*20*/ SaveQuit = signal( SIGQUIT, SIG_IGN ); /* Signals */ /*21*/ waitpid( Pid, &Status, 0 ); /*22*/ signal( SIGINT, SaveIntr ); /* Restore */ /*23*/ signal( SIGQUIT, SaveQuit ); /* Signals */ /*24*/ return Status; /*25*/ }