Go to the documentation of this file.00001
00002
00003
00004
00005 #include <AvailabilityMacros.h>
00006 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 || !defined(MAC_OS_X_VERSION_10_2)
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #if defined(LIBC_SCCS) && !defined(lint)
00040 static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 6/4/93";
00041 #endif
00042
00043 #include <sys/wait.h>
00044 #include <signal.h>
00045 #include <unistd.h>
00046 #include <paths.h>
00047 #include <errno.h>
00048
00049 int system(const char *command);
00050
00051 int
00052 system(const char *command)
00053 {
00054 pid_t pid;
00055 int pstat;
00056 struct sigaction ign,
00057 intact,
00058 quitact;
00059 sigset_t newsigblock,
00060 oldsigblock;
00061
00062 if (!command)
00063 return (1);
00064
00065
00066
00067
00068
00069 ign.sa_handler = SIG_IGN;
00070 (void) sigemptyset(&ign.sa_mask);
00071 ign.sa_flags = 0;
00072 (void) sigaction(SIGINT, &ign, &intact);
00073 (void) sigaction(SIGQUIT, &ign, &quitact);
00074 (void) sigemptyset(&newsigblock);
00075 (void) sigaddset(&newsigblock, SIGCHLD);
00076 (void) sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
00077 switch (pid = fork())
00078 {
00079 case -1:
00080 break;
00081 case 0:
00082
00083
00084
00085
00086 (void) sigaction(SIGINT, &intact, NULL);
00087 (void) sigaction(SIGQUIT, &quitact, NULL);
00088 (void) sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
00089 execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL);
00090 _exit(127);
00091 default:
00092 do
00093 {
00094 pid = wait4(pid, &pstat, 0, (struct rusage *) 0);
00095 } while (pid == -1 && errno == EINTR);
00096 break;
00097 }
00098 (void) sigaction(SIGINT, &intact, NULL);
00099 (void) sigaction(SIGQUIT, &quitact, NULL);
00100 (void) sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
00101 return (pid == -1 ? -1 : pstat);
00102 }
00103
00104 #endif