]> git.saurik.com Git - apple/libc.git/blob - stdlib/FreeBSD/system.c.patch
Libc-498.1.5.tar.gz
[apple/libc.git] / stdlib / FreeBSD / system.c.patch
1 --- system.c.orig 2003-05-20 15:23:25.000000000 -0700
2 +++ system.c 2006-06-24 18:48:47.000000000 -0700
3 @@ -49,6 +49,16 @@
4 #include "un-namespace.h"
5 #include "libc_private.h"
6
7 +#if __DARWIN_UNIX03
8 +#include <pthread.h>
9 +
10 +static pthread_mutex_t __systemfn_mutex = PTHREAD_MUTEX_INITIALIZER;
11 +extern int __unix_conforming;
12 +#ifdef VARIANT_CANCELABLE
13 +extern void _pthread_testcancel(pthread_t thread, int isconforming);
14 +#endif /* VARIANT_CANCELABLE */
15 +#endif /* __DARWIN_UNIX03 */
16 +
17 int
18 __system(command)
19 const char *command;
20 @@ -58,9 +68,24 @@
21 struct sigaction ign, intact, quitact;
22 sigset_t newsigblock, oldsigblock;
23
24 - if (!command) /* just checking... */
25 - return(1);
26 +#if __DARWIN_UNIX03
27 + if (__unix_conforming == 0)
28 + __unix_conforming = 1;
29 +#ifdef VARIANT_CANCELABLE
30 + _pthread_testcancel(pthread_self(), 1);
31 +#endif /* VARIANT_CANCELABLE */
32 +#endif /* __DARWIN_UNIX03 */
33 +
34 + if (!command) { /* just checking... */
35 + if (access(_PATH_BSHELL, F_OK) == -1) /* if no sh or no access */
36 + return(0);
37 + else
38 + return(1);
39 + }
40
41 +#if __DARWIN_UNIX03
42 + pthread_mutex_lock(&__systemfn_mutex);
43 +#endif /* __DARWIN_UNIX03 */
44 /*
45 * Ignore SIGINT and SIGQUIT, block SIGCHLD. Remember to save
46 * existing signal dispositions.
47 @@ -83,6 +108,9 @@
48 (void)_sigaction(SIGINT, &intact, NULL);
49 (void)_sigaction(SIGQUIT, &quitact, NULL);
50 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
51 +#if __DARWIN_UNIX03
52 + pthread_mutex_unlock(&__systemfn_mutex);
53 +#endif /* __DARWIN_UNIX03 */
54 execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL);
55 _exit(127);
56 default: /* parent */
57 @@ -95,6 +123,9 @@
58 (void)_sigaction(SIGINT, &intact, NULL);
59 (void)_sigaction(SIGQUIT, &quitact, NULL);
60 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
61 +#if __DARWIN_UNIX03
62 + pthread_mutex_unlock(&__systemfn_mutex);
63 +#endif /* __DARWIN_UNIX03 */
64 return(pid == -1 ? -1 : pstat);
65 }
66