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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [misc/] [system.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
 
2
#include <stddef.h>
3
#include <signal.h>
4
#include <unistd.h>
5
 
6
int
7
system(command)
8
char * command;
9
{
10
   int wait_val, wait_ret, pid;
11
   __sighandler_t save_quit, save_int, save_chld;
12
 
13
   if( command == 0 ) return 1;
14
 
15
   save_quit = signal(SIGQUIT, SIG_IGN);
16
   save_int  = signal(SIGINT,  SIG_IGN);
17
   save_chld = signal(SIGCHLD, SIG_DFL);
18
 
19
   if( (pid=vfork()) < 0 )
20
   {
21
      signal(SIGQUIT, save_quit);
22
      signal(SIGINT,  save_int);
23
      signal(SIGCHLD, save_chld);
24
      return -1;
25
   }
26
   if( pid == 0 )
27
   {
28
      signal(SIGQUIT, SIG_DFL);
29
      signal(SIGINT,  SIG_DFL);
30
      signal(SIGCHLD, SIG_DFL);
31
 
32
      execl("/bin/sh", "sh", "-c", command, (char*)0);
33
      _exit(127);
34
   }
35
   /* Signals are not absolutly guarenteed with vfork */
36
   signal(SIGQUIT, SIG_IGN);
37
   signal(SIGINT,  SIG_IGN);
38
 
39
   printf("Waiting for child %d\n", pid);
40
 
41
   if (wait4(pid, &wait_val, 0, 0) == -1)
42
      wait_val = -1;
43
 
44
   signal(SIGQUIT, save_quit);
45
   signal(SIGINT,  save_int);
46
   signal(SIGCHLD, save_chld);
47
   return wait_val;
48
}

powered by: WebSVN 2.1.0

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