1 #include <sys/wait.h> 2 3 #include <stdio.h> 4 5 #include "../general/general.h" 6 #include "../api/api.h" 7 8 #include "../general/globals.h" 9 10 11 static int shell_pid = 0; 12 13 static int 14 child_died() 15 { 16 union wait *status; 17 18 while ((pid = wait3(status, WNOHANG, 0)) > 0) { 19 if (pid == shell_pid) { 20 shell_active = 0; 21 } 22 } 23 signal(SIGCHLD, child_died); 24 } 25 26 /* 27 * shell_continue() actually runs the command, and looks for API 28 * requests coming back in. 29 * 30 * We are called from the main loop in telnet.c. 31 */ 32 33 int 34 shell_continue() 35 { 36 return shell_active; 37 } 38 39 40 /* 41 * Called from telnet.c to fork a lower command.com. We 42 * use the spint... routines so that we can pick up 43 * interrupts generated by application programs. 44 */ 45 46 47 int 48 shell(argc,argv) 49 int argc; 50 char *argv[]; 51 { 52 if ((shell_pid = fork()) { 53 shell_active = 1; /* We are running down below */ 54 child_killed(); /* Start up signal handler */ 55 } else { /* New process */ 56 register int i; 57 58 for (i = 3; i < 30; i++) { 59 (void) close(i); 60 } 61 if (argc == 1) { /* Just get a shell */ 62 char *cmdname; 63 64 cmdname = getenv("SHELL"); 65 execlp(cmdname, cmdname, 0); 66 perror("Exec'ing new shell...\n"); 67 exit(1); 68 } else { 69 execvp(argv[1], &argv[1]); 70 perror("Exec'ing command.\n"); 71 exit(1); 72 } 73 /*NOTREACHED*/ 74 } 75 return 1; /* Go back to main loop */ 76 } 77