added depend label
[unix-history] / usr / src / usr.bin / uucp / shio.c
CommitLineData
d78f3cba 1#ifndef lint
46b15d8a 2static char sccsid[] = "@(#)shio.c 5.2 (Berkeley) %G%";
d78f3cba
SL
3#endif
4
5#include "uucp.h"
6#include <signal.h>
7
d78f3cba
SL
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];
46b15d8a 24 extern int errno;
d78f3cba
SL
25
26 if (fi == NULL)
46b15d8a 27 fi = DEVNULL;
d78f3cba 28 if (fo == NULL)
46b15d8a 29 fo = DEVNULL;
d78f3cba
SL
30
31 DEBUG(3, "shio - %s\n", cmd);
46b15d8a
RC
32#ifdef SIGCHLD
33 signal(SIGCHLD, SIG_IGN);
34#endif SIGCHLD
d78f3cba
SL
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);
46b15d8a
RC
43 if (user == NULL || (gninfo(user, &uid, path) != 0)
44 || setuid(uid))
d78f3cba
SL
45 setuid(getuid());
46 f = open(subfile(fi), 0);
46b15d8a
RC
47 if (f != 0) {
48 logent(fi, "CAN'T READ");
49 exit(-errno);
50 }
d78f3cba
SL
51 close(1);
52 f = creat(subfile(fo), 0666);
46b15d8a
RC
53 if (f != 1) {
54 logent(fo, "CAN'T WRITE");
55 exit(-errno);
56 }
d78f3cba 57 execl(SHELL, "sh", "-c", cmd, (char *)0);
46b15d8a 58 exit(100+errno);
d78f3cba 59 }
46b15d8a
RC
60 while ((ret = wait(&status)) != pid && ret != -1)
61 ;
d78f3cba 62 DEBUG(3, "status %d\n", status);
46b15d8a 63 return status;
d78f3cba 64}