OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [stdlib/] [system.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <stdio.h>
2
#include <stddef.h>
3
#include <signal.h>
4
#include <unistd.h>
5
#include <sys/wait.h>
6
 
7
/* uClinux-2.0 has vfork, but Linux 2.0 doesn't */
8
#include <sys/syscall.h>
9
#if ! defined __NR_vfork
10
#define vfork fork      
11
#endif
12
 
13
int __libc_system(char *command)
14
{
15
        int wait_val, pid;
16
        __sighandler_t save_quit, save_int, save_chld;
17
 
18
        if (command == 0)
19
                return 1;
20
 
21
        save_quit = signal(SIGQUIT, SIG_IGN);
22
        save_int = signal(SIGINT, SIG_IGN);
23
        save_chld = signal(SIGCHLD, SIG_DFL);
24
 
25
        if ((pid = vfork()) < 0) {
26
                signal(SIGQUIT, save_quit);
27
                signal(SIGINT, save_int);
28
                signal(SIGCHLD, save_chld);
29
                return -1;
30
        }
31
        if (pid == 0) {
32
                signal(SIGQUIT, SIG_DFL);
33
                signal(SIGINT, SIG_DFL);
34
                signal(SIGCHLD, SIG_DFL);
35
 
36
                execl("/bin/sh", "sh", "-c", command, (char *) 0);
37
                _exit(127);
38
        }
39
        /* Signals are not absolutly guarenteed with vfork */
40
        signal(SIGQUIT, SIG_IGN);
41
        signal(SIGINT, SIG_IGN);
42
 
43
#if 0
44
        printf("Waiting for child %d\n", pid);
45
#endif
46
 
47
        if (wait4(pid, &wait_val, 0, 0) == -1)
48
                wait_val = -1;
49
 
50
        signal(SIGQUIT, save_quit);
51
        signal(SIGINT, save_int);
52
        signal(SIGCHLD, save_chld);
53
        return wait_val;
54
}
55
weak_alias(__libc_system, system)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.