OSDN Git Service

Convert all the strong_aliases to weak that are cancelable in libpthread
[uclinux-h8/uClibc.git] / libc / stdlib / system.c
1 /*
2  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
3  *
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  */
6
7 #include <stdio.h>
8 #include <stddef.h>
9 #include <signal.h>
10 #include <unistd.h>
11 #include <sys/wait.h>
12
13 libc_hidden_proto(_exit)
14 libc_hidden_proto(wait4)
15 libc_hidden_proto(execl)
16 libc_hidden_proto(signal)
17 libc_hidden_proto(vfork)
18
19 /* uClinux-2.0 has vfork, but Linux 2.0 doesn't */
20 #include <sys/syscall.h>
21 #if ! defined __NR_vfork
22 #define vfork fork      
23 libc_hidden_proto(fork)
24 #endif
25
26 int __libc_system(char *command)
27 {
28         int wait_val, pid;
29         __sighandler_t save_quit, save_int, save_chld;
30
31         if (command == 0)
32                 return 1;
33
34         save_quit = signal(SIGQUIT, SIG_IGN);
35         save_int = signal(SIGINT, SIG_IGN);
36         save_chld = signal(SIGCHLD, SIG_DFL);
37
38         if ((pid = vfork()) < 0) {
39                 signal(SIGQUIT, save_quit);
40                 signal(SIGINT, save_int);
41                 signal(SIGCHLD, save_chld);
42                 return -1;
43         }
44         if (pid == 0) {
45                 signal(SIGQUIT, SIG_DFL);
46                 signal(SIGINT, SIG_DFL);
47                 signal(SIGCHLD, SIG_DFL);
48
49                 execl("/bin/sh", "sh", "-c", command, (char *) 0);
50                 _exit(127);
51         }
52         /* Signals are not absolutly guarenteed with vfork */
53         signal(SIGQUIT, SIG_IGN);
54         signal(SIGINT, SIG_IGN);
55
56 #if 0
57         __printf("Waiting for child %d\n", pid);
58 #endif
59
60         if (wait4(pid, &wait_val, 0, 0) == -1)
61                 wait_val = -1;
62
63         signal(SIGQUIT, save_quit);
64         signal(SIGINT, save_int);
65         signal(SIGCHLD, save_chld);
66         return wait_val;
67 }
68 weak_alias(__libc_system,system)