Mercurial > hg > octave-lyh
comparison src/system.c @ 3153:94fc53d82561
[project @ 1998-02-13 04:08:17 by jwe]
author | jwe |
---|---|
date | Fri, 13 Feb 1998 04:08:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3152:a34a56e2e567 | 3153:94fc53d82561 |
---|---|
1 #if defined (__CYGWIN32__) | |
2 | |
3 #include <sys/types.h> | |
4 #include <sys/wait.h> | |
5 #include <errno.h> | |
6 #include <signal.h> | |
7 #include <unistd.h> | |
8 #include <stdio.h> | |
9 | |
10 int | |
11 system (const char *cmd) | |
12 { | |
13 pid_t pid; | |
14 | |
15 int status = 1; | |
16 | |
17 struct sigaction ignore, saved_sigint, saved_sigquit; | |
18 | |
19 sigset_t child_mask, saved_mask; | |
20 | |
21 if (cmd) | |
22 { | |
23 ignore.sa_handler = SIG_IGN; | |
24 | |
25 sigemptyset (&ignore.sa_mask); | |
26 | |
27 ignore.sa_flags = 0; | |
28 | |
29 if (sigaction (SIGINT, &ignore, &saved_sigint) < 0) | |
30 return -1; | |
31 | |
32 if (sigaction (SIGQUIT, &ignore, &saved_sigquit) < 0) | |
33 return -1; | |
34 | |
35 sigemptyset (&child_mask); | |
36 | |
37 sigaddset (&child_mask, SIGCHLD); | |
38 | |
39 if (sigprocmask (SIG_BLOCK, &child_mask, &saved_mask) < 0) | |
40 return -1; | |
41 | |
42 if ((pid = fork ()) < 0) | |
43 status = -1; | |
44 else if (pid == 0) | |
45 { | |
46 sigaction (SIGINT, &saved_sigint, 0); | |
47 sigaction (SIGQUIT, &saved_sigquit, 0); | |
48 | |
49 sigprocmask (SIG_SETMASK, &saved_mask, 0); | |
50 | |
51 execl ("/bin/sh", "sh", "-c", cmd, 0); | |
52 | |
53 exit (127); | |
54 } | |
55 else | |
56 { | |
57 while (waitpid (pid, &status, 0) < 0) | |
58 { | |
59 if (errno != EINTR) | |
60 { | |
61 status = -1; | |
62 break; | |
63 } | |
64 } | |
65 } | |
66 | |
67 if (sigaction (SIGINT, &saved_sigint, 0) < 0) | |
68 return -1; | |
69 | |
70 if (sigaction (SIGQUIT, &saved_sigquit, 0) < 0) | |
71 return -1; | |
72 | |
73 if (sigprocmask (SIG_SETMASK, &saved_mask, 0) < 0) | |
74 return -1; | |
75 } | |
76 | |
77 return status; | |
78 } | |
79 | |
80 #if defined (TEST) | |
81 int | |
82 main (void) | |
83 { | |
84 system ("info"); | |
85 while (1) | |
86 { | |
87 printf ("foo-i-hithere\n"); | |
88 sleep (1); | |
89 } | |
90 return 0; | |
91 } | |
92 #endif | |
93 | |
94 #endif |