forked from alexfru/dflat20
-
Notifications
You must be signed in to change notification settings - Fork 2
/
runshell.c
45 lines (37 loc) · 851 Bytes
/
runshell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#if MACOS
typedef void (*sighandler_t) (int);
#endif
#ifdef COSMO
extern void _exit(int);
#endif
int
runshell(void)
{
int status, ret, pid;
sighandler_t save_quit;
sighandler_t save_int;
save_quit = signal(SIGQUIT, SIG_IGN);
save_int = signal(SIGINT, SIG_IGN);
if ((pid = fork()) == -1) {
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", (char*)0);
_exit(127);
}
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, SIG_IGN);
/* wait for child termination*/
while ((ret = waitpid(pid, &status, 0)) != pid)
continue;
signal(SIGQUIT, save_quit);
signal(SIGINT, save_int);
return status;
}