2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 /* $Id: system.c,v 1.5 1994/06/24 11:54:20 ceriel Exp $ */
7 #if defined(_POSIX_SOURCE)
13 extern int _fork(void);
14 extern int _wait(int *);
15 extern void _exit(int);
16 extern void _execve(const char *path, const char ** argv, const char ** envp);
17 extern void _close(int);
21 extern const char **_penvp;
22 static const char *exec_tab[] = {
24 "-c", /* argument to the shell */
25 NULL, /* to be filled with user command */
26 NULL /* terminating NULL */
30 system(const char *str)
32 int pid, exitstatus, waitval;
35 if ((pid = _fork()) < 0) return str ? -1 : 0;
38 for (i = 3; i <= 20; i++)
40 if (!str) str = "cd ."; /* just testing for a shell */
41 exec_tab[2] = str; /* fill in command */
42 _execve("/bin/sh", exec_tab, _penvp);
43 /* get here if execve fails ... */
44 _exit(FAIL); /* see manual page */
46 while ((waitval = _wait(&exitstatus)) != pid) {
47 if (waitval == -1) break;
50 /* no child ??? or maybe interrupted ??? */
54 if (exitstatus == FAIL << 8) /* execve() failed */
56 else exitstatus = 1; /* /bin/sh exists */