[12748] | 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 | |
---|
[14412] | 18 | static const char rcsid[] = "$Id: suite.c,v 1.6 2000-03-15 20:53:36 ghudson Exp $"; |
---|
[12748] | 19 | |
---|
| 20 | #include <fcntl.h> |
---|
[13772] | 21 | #include <signal.h> |
---|
[12748] | 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; |
---|
[13772] | 35 | sigset_t mask; |
---|
[12748] | 36 | |
---|
[14042] | 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); |
---|
[12748] | 41 | close(fd); |
---|
| 42 | |
---|
[13772] | 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 | |
---|
[12748] | 50 | if (argc > 1 && !strncmp(argv[1], "-P", 2)) |
---|
| 51 | { |
---|
| 52 | whoami = argv[1] + 2; |
---|
[13065] | 53 | argv++; |
---|
| 54 | argc--; |
---|
[12748] | 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, "detach")) |
---|
| 70 | exit(detach_main(argc, argv)); |
---|
| 71 | else if (!strcmp(whoami, "fsid") || !strcmp(whoami, "nfsid")) |
---|
| 72 | exit(fsid_main(argc, argv)); |
---|
| 73 | else if (!strcmp(whoami, "zinit")) |
---|
| 74 | exit(zinit_main(argc, argv)); |
---|
| 75 | |
---|
| 76 | fprintf(stderr, "Not invoked with attach, detach, nfsid, fsid, zinit, add, or attachandrun!\n"); |
---|
| 77 | exit(1); |
---|
| 78 | } |
---|