2 * support for the Lisp function RUN-PROGRAM and friends
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
18 #include <sys/types.h>
21 #include <sys/ioctl.h>
22 #if defined(SVR4) || defined(__linux__)
26 int spawn(char *program, char *argv[], char *envp[], char *pty_name,
27 int stdin, int stdout, int stderr)
35 /* Put us in our own process group. */
38 #elif defined(SVR4) || defined(__linux__)
44 /* If we are supposed to be part of some other pty, go for it. */
46 #if !defined(hpux) && !defined(SVR4)
47 fd = open("/dev/tty", O_RDWR, 0);
49 ioctl(fd, TIOCNOTTY, 0);
54 fd = open(pty_name, O_RDWR, 0);
61 /* Set up stdin, stdout, and stderr */
69 /* Close all other fds. */
71 for (fd = sysconf(_SC_OPEN_MAX)-1; fd >= 3; fd--)
74 for (fd = getdtablesize()-1; fd >= 3; fd--)
78 /* Exec the program. */
79 execve(program, argv, envp);
81 /* It didn't work, so try /bin/sh. */
84 execve("/bin/sh", argv-1, envp);
86 /* The exec didn't work, flame out. */