2 * Support for run-program.
15 spawn(char *program, char *argv[], char *envp[], char *pty_name,
16 int stdin, int stdout, int stderr)
26 /* Put us in our own process group. */
29 /* Unblock all signals. */
31 sigprocmask(SIG_SETMASK, &set, NULL);
33 /* If we are supposed to be part of some other pty, go for it. */
36 fd = open("/dev/tty", O_RDWR, 0);
38 ioctl(fd, TIOCNOTTY, 0);
43 fd = open(pty_name, O_RDWR, 0);
50 /* Set up stdin, stdout, and stderr. */
58 /* Close all other fds. */
59 for (fd = sysconf(_SC_OPEN_MAX) - 1; fd >= 3; fd--)
62 /* Exec the program. */
63 execve(program, argv, envp);
65 /* It didn't work, so try /bin/sh. */
68 execve("/bin/sh", argv - 1, envp);
70 /* The exec didn't work, flame out. */