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".
7 #if defined(_POSIX_SOURCE)
14 extern pid_t
_fork(void);
15 extern pid_t
_wait(int *);
16 extern void _exit(int);
17 extern void _execve(const char *path
, const char ** argv
, const char ** envp
);
18 extern int _close(int);
22 extern const char ***_penviron
;
23 static const char *exec_tab
[] = {
25 "-c", /* argument to the shell */
26 NULL
, /* to be filled with user command */
27 NULL
/* terminating NULL */
31 system(const char *str
)
33 int pid
, exitstatus
, waitval
;
36 if ((pid
= _fork()) < 0) return str
? -1 : 0;
39 for (i
= 3; i
<= OPEN_MAX
; i
++)
41 if (!str
) str
= "cd ."; /* just testing for a shell */
42 exec_tab
[2] = str
; /* fill in command */
43 _execve("/bin/sh", exec_tab
, *_penviron
);
44 /* get here if execve fails ... */
45 _exit(FAIL
); /* see manual page */
47 while ((waitval
= _wait(&exitstatus
)) != pid
) {
48 if (waitval
== -1) break;
51 /* no child ??? or maybe interrupted ??? */
55 if (exitstatus
== FAIL
<< 8) /* execve() failed */
57 else exitstatus
= 1; /* /bin/sh exists */