Commit | Line | Data |
---|---|---|
e804469b C |
1 | static char sccsid[] = "@(#)shio.c 4.1 (Berkeley) 9/11/82"; |
2 | ||
fea9ca7b C |
3 | #include "uucp.h" |
4 | ||
5 | ||
6 | /******* | |
7 | * shio(cmd, fi, fo, user) execute shell of command with | |
8 | * char *cmd, *fi, *fo; fi and fo as standard input/output | |
9 | * char *user; user name | |
10 | * | |
11 | * return codes: | |
12 | * 0 - ok | |
13 | * non zero - failed - status from child | |
14 | */ | |
15 | ||
16 | shio(cmd, fi, fo, user) | |
17 | char *cmd, *fi, *fo, *user; | |
18 | { | |
19 | int status, f; | |
20 | int uid, pid, ret; | |
21 | char path[MAXFULLNAME]; | |
22 | ||
23 | if (fi == NULL) | |
24 | fi = "/dev/null"; | |
25 | if (fo == NULL) | |
26 | fo = "/dev/null"; | |
27 | ||
28 | DEBUG(3, "shio - %s\n", cmd); | |
29 | if ((pid = fork()) == 0) { | |
30 | close(Ifn); | |
31 | close(Ofn); | |
32 | close(0); | |
33 | f = open(fi, 0); | |
34 | ASSERT(f == 0, "BAD OPEN fileno %d", f); | |
35 | close(1); | |
36 | f = creat(fo, 0666); | |
37 | ASSERT(f == 1, "BAD OPEN fileno %d", f); | |
38 | if (gninfo(user, &uid, path) == 0) | |
39 | setuid(uid); | |
40 | execl(SHELL, "sh", "-c", cmd, 0); | |
41 | exit(100); | |
42 | } | |
43 | while ((ret = wait(&status)) != pid && ret != -1); | |
44 | DEBUG(3, "status %d\n", status); | |
45 | return(status); | |
46 | } |