summaryrefslogtreecommitdiff
path: root/libc-0.0.4/misc/system.c
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1996-03-24 17:45:55 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:29:43 +0200
commitfe22c37817ce338fbbc90b239320248c270957fa (patch)
treed9550410c4a20bdd382fcc58d2d3d7c5e04e5245 /libc-0.0.4/misc/system.c
parenta7aba15e8efffb1c5d3097656f1a93955a64f01f (diff)
parent42192453ea219b80d0bf9f41e51e36d3d4d0740b (diff)
downloaddev86-fe22c37817ce338fbbc90b239320248c270957fa.tar.gz
Import Dev86-0.0.4.tar.gzv0.0.4
Diffstat (limited to 'libc-0.0.4/misc/system.c')
-rw-r--r--libc-0.0.4/misc/system.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libc-0.0.4/misc/system.c b/libc-0.0.4/misc/system.c
new file mode 100644
index 0000000..f48f68d
--- /dev/null
+++ b/libc-0.0.4/misc/system.c
@@ -0,0 +1,49 @@
+
+#include <stddef.h>
+#include <signal.h>
+
+int
+system(command)
+char * command;
+{
+ int wait_val, wait_ret, pid;
+ __sighandler_t save_quit;
+ __sighandler_t save_int;
+
+ if( command == 0 ) return 1;
+
+ save_quit = signal(SIGQUIT, SIG_IGN);
+ save_int = signal(SIGINT, SIG_IGN);
+
+ if( (pid=vfork()) < 0 )
+ {
+ signal(SIGQUIT, save_quit);
+ signal(SIGINT, save_int);
+ return -1;
+ }
+ if( pid == 0 )
+ {
+ signal(SIGQUIT, SIG_DFL);
+ signal(SIGINT, SIG_DFL);
+
+ execl("/bin/sh", "sh", "-c", command, (char*)0);
+ _exit(127);
+ }
+ /* Signals are not absolutly guarenteed with vfork */
+ signal(SIGQUIT, SIG_IGN);
+ signal(SIGINT, SIG_IGN);
+
+ do
+ {
+ if( (wait_ret = wait(&wait_val)) == -1 )
+ {
+ wait_val = -1;
+ break;
+ }
+ }
+ while( wait_ret != pid );
+
+ signal(SIGQUIT, save_quit);
+ signal(SIGINT, save_int);
+ return wait_val;
+}