From 98da0aa445864dcc7d87aec5be996a2e46247d46 Mon Sep 17 00:00:00 2001 From: wlott <wlott> Date: Wed, 4 Aug 1993 11:25:08 +0000 Subject: [PATCH] Initial revision --- lisp/runprog.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lisp/runprog.c diff --git a/lisp/runprog.c b/lisp/runprog.c new file mode 100644 index 000000000..3ecd58bc0 --- /dev/null +++ b/lisp/runprog.c @@ -0,0 +1,66 @@ +/* + * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/runprog.c,v 1.1 1993/08/04 11:25:08 wlott Exp $ + * + * Support for run-program. + * + */ + +#include <sys/file.h> +#include <sys/ioctl.h> + +int spawn(char *program, char *argv[], char *envp[], char *pty_name, + int stdin, int stdout, int stderr) +{ + int pid = fork(); + int fd; + + if (pid != 0) + return pid; + + /* Put us in our own process group. */ +#ifdef hpux + setsid(); +#else + setpgrp(0, getpid()); +#endif + + /* If we are supposed to be part of some other pty, go for it. */ + if (pty_name) { +#ifndef hpux + fd = open("/dev/tty", O_RDWR, 0); + if (fd >= 0) { + ioctl(fd, TIOCNOTTY, 0); + close(fd); + } +#endif + + fd = open(pty_name, O_RDWR, 0); + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + close(fd); + } + + /* Set up stdin, stdout, and stderr */ + if (stdin >= 0) + dup2(stdin, 0); + if (stdout >= 0) + dup2(stdout, 1); + if (stderr >= 0) + dup2(stderr, 2); + + /* Close all other fds. */ + for (fd = getdtablesize()-1; fd >= 3; fd--) + close(fd); + + /* Exec the program. */ + execve(program, argv, envp); + + /* It didn't work, so try /bin/sh. */ + argv[0] = program; + argv[-1] = "sh"; + execve("/bin/sh", argv-1, envp); + + /* The exec didn't work, flame out. */ + exit(1); +} -- GitLab