|
|
1.1 root 1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: *
6: * @(#)system_.c 5.3 5/29/90
7: */
8:
9: /*
10: * execute a unix command
11: *
12: * calling sequence:
13: * iexit = system(command)
14: * where:
15: * iexit will return the exit status of the command
16: * command is a character string containing the command to be executed
17: */
18:
19: #include "../libI77/fiodefs.h"
20: #include "../libI77/f_errno.h"
21: #include <sys/param.h>
22: #ifndef NCARGS
23: #define NCARGS 256
24: #endif
25:
26:
27: long system_(s, n)
28: char *s;
29: long n;
30: {
31: char buf[NCARGS - 50];
32: long i;
33:
34: if (n >= sizeof buf)
35: return(-(long)(errno=F_ERARG));
36: for (i = 0; i < MXUNIT; i++)
37: flush_(&i);
38: g_char(s, n, buf);
39: return((long)system(buf));
40: }
41:
42: /*
43: * this is a sane version of the libc routine.
44: */
45:
46: #include <sys/signal.h>
47: #include <stdlib.h>
48: #include <string.h>
49:
50: system(s)
51: char *s;
52: {
53: register sig_t istat, qstat;
54: int status, pid, w;
55: char *shname, *shell;
56:
57: if ((shell = getenv("SHELL")) == NULL)
58: shell = "/bin/sh";
59:
60: if (shname = rindex(shell, '/'))
61: shname++;
62: else
63: shname = shell;
64:
65: if ((pid = vfork()) == 0) {
66: execl(shell, shname, "-c", s, (char *)0);
67: _exit(127);
68: }
69: if (pid == -1)
70: return(-1);
71:
72: istat = signal(SIGINT, SIG_IGN);
73: qstat = signal(SIGQUIT, SIG_IGN);
74: while ((w = wait(&status)) != pid && w != -1)
75: ;
76: if (w == -1)
77: status = -1;
78: (void)signal(SIGINT, istat);
79: (void)signal(SIGQUIT, qstat);
80: return(status);
81: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.