added depend label
[unix-history] / usr / src / usr.bin / uucp / shio.c
... / ...
CommitLineData
1#ifndef lint
2static char sccsid[] = "@(#)shio.c 5.2 (Berkeley) %G%";
3#endif
4
5#include "uucp.h"
6#include <signal.h>
7
8/*******
9 * shio(cmd, fi, fo, user) execute shell of command with
10 * char *cmd, *fi, *fo; fi and fo as standard input/output
11 * char *user; user name
12 *
13 * return codes:
14 * 0 - ok
15 * non zero - failed - status from child
16 */
17
18shio(cmd, fi, fo, user)
19char *cmd, *fi, *fo, *user;
20{
21 int status, f;
22 int uid, pid, ret;
23 char path[MAXFULLNAME];
24 extern int errno;
25
26 if (fi == NULL)
27 fi = DEVNULL;
28 if (fo == NULL)
29 fo = DEVNULL;
30
31 DEBUG(3, "shio - %s\n", cmd);
32#ifdef SIGCHLD
33 signal(SIGCHLD, SIG_IGN);
34#endif SIGCHLD
35 if ((pid = fork()) == 0) {
36 signal(SIGINT, SIG_IGN);
37 signal(SIGHUP, SIG_IGN);
38 signal(SIGQUIT, SIG_IGN);
39 signal(SIGKILL, SIG_IGN);
40 close(Ifn);
41 close(Ofn);
42 close(0);
43 if (user == NULL || (gninfo(user, &uid, path) != 0)
44 || setuid(uid))
45 setuid(getuid());
46 f = open(subfile(fi), 0);
47 if (f != 0) {
48 logent(fi, "CAN'T READ");
49 exit(-errno);
50 }
51 close(1);
52 f = creat(subfile(fo), 0666);
53 if (f != 1) {
54 logent(fo, "CAN'T WRITE");
55 exit(-errno);
56 }
57 execl(SHELL, "sh", "-c", cmd, (char *)0);
58 exit(100+errno);
59 }
60 while ((ret = wait(&status)) != pid && ret != -1)
61 ;
62 DEBUG(3, "status %d\n", status);
63 return status;
64}