1 | /* Copyright 1998 by the Massachusetts Institute of Technology. |
---|
2 | * |
---|
3 | * Permission to use, copy, modify, and distribute this |
---|
4 | * software and its documentation for any purpose and without |
---|
5 | * fee is hereby granted, provided that the above copyright |
---|
6 | * notice appear in all copies and that both that copyright |
---|
7 | * notice and this permission notice appear in supporting |
---|
8 | * documentation, and that the name of M.I.T. not be used in |
---|
9 | * advertising or publicity pertaining to distribution of the |
---|
10 | * software without specific, written prior permission. |
---|
11 | * M.I.T. makes no representations about the suitability of |
---|
12 | * this software for any purpose. It is provided "as is" |
---|
13 | * without express or implied warranty. |
---|
14 | */ |
---|
15 | |
---|
16 | /* main() for the attach suite */ |
---|
17 | |
---|
18 | static const char rcsid[] = "$Id: suite.c,v 1.5 1999-12-02 20:12:26 danw Exp $"; |
---|
19 | |
---|
20 | #include <fcntl.h> |
---|
21 | #include <signal.h> |
---|
22 | #include <stdio.h> |
---|
23 | #include <stdlib.h> |
---|
24 | #include <string.h> |
---|
25 | #include <unistd.h> |
---|
26 | |
---|
27 | #include "attach.h" |
---|
28 | #include "agetopt.h" |
---|
29 | |
---|
30 | char *whoami; |
---|
31 | |
---|
32 | int main(int argc, char **argv) |
---|
33 | { |
---|
34 | int fd; |
---|
35 | sigset_t mask; |
---|
36 | |
---|
37 | /* Make sure std* are open, for suid safety. */ |
---|
38 | do |
---|
39 | fd = open("/dev/null", O_RDONLY); |
---|
40 | while (fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO); |
---|
41 | close(fd); |
---|
42 | |
---|
43 | /* Block ^Z to prevent holding locks on the attachtab. */ |
---|
44 | sigemptyset(&mask); |
---|
45 | sigaddset(&mask, SIGTSTP); |
---|
46 | sigaddset(&mask, SIGTTOU); |
---|
47 | sigaddset(&mask, SIGTTIN); |
---|
48 | sigprocmask(SIG_BLOCK, &mask, NULL); |
---|
49 | |
---|
50 | if (argc > 1 && !strncmp(argv[1], "-P", 2)) |
---|
51 | { |
---|
52 | whoami = argv[1] + 2; |
---|
53 | argv++; |
---|
54 | argc--; |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | whoami = strrchr(argv[0], '/'); |
---|
59 | if (whoami) |
---|
60 | whoami++; |
---|
61 | else |
---|
62 | whoami = argv[0]; |
---|
63 | } |
---|
64 | |
---|
65 | if (!strcmp(whoami, "add")) |
---|
66 | exit(add_main(argc, argv)); |
---|
67 | else if (!strcmp(whoami, "attach")) |
---|
68 | exit(attach_main(argc, argv)); |
---|
69 | else if (!strcmp(whoami, "attachandrun")) |
---|
70 | exit(attachandrun_main(argc, argv)); |
---|
71 | else if (!strcmp(whoami, "detach")) |
---|
72 | exit(detach_main(argc, argv)); |
---|
73 | else if (!strcmp(whoami, "fsid") || !strcmp(whoami, "nfsid")) |
---|
74 | exit(fsid_main(argc, argv)); |
---|
75 | else if (!strcmp(whoami, "zinit")) |
---|
76 | exit(zinit_main(argc, argv)); |
---|
77 | |
---|
78 | fprintf(stderr, "Not invoked with attach, detach, nfsid, fsid, zinit, add, or attachandrun!\n"); |
---|
79 | exit(1); |
---|
80 | } |
---|