]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/Extras/libh/subshell.c
Remove final traces of TMA support
[nmh] / docs / historical / mh-jun-1982 / Extras / libh / subshell.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #include "../h/errors.h"
9
10 subshell(str)
11 char *str;
12 {
13 register s2, s3;
14 char *a2, *a3;
15 register pid;
16 char st[2];
17 /* if str is non null, exec it as a command to the shell */
18 /* and return immediately */
19 /* if str is the null string, simply spawn a sub-shell */
20
21 if (str == 0 || *str == 0) {
22 a2 = 0;
23 a3 = 0;
24 } else {
25 a2 = "-c";
26 a3 = str;
27 }
28 pid = fork();
29 if (pid == 0) {
30 execl("/bin/sh", "-", a2, a3, 0);
31 error("no shell!");
32 }
33 if (pid == -1) {
34 type(2, errno == EAGAIN? "system": "your");
35 type(2, " process limit reached\n");
36 return(-1);
37 }
38 s2 = signal(2,1);
39 s3 = signal(3,1);
40 while(pid != wait(&st));
41 signal(2,s2);
42 signal(3,s3);
43 return(st[1]);
44 }