| | 41 | #define CMD_MTAB 0x2001 |
|---|
| | 42 | |
|---|
| | 43 | static struct option const |
|---|
| | 44 | CMDLINE_OPTIONS[] = { |
|---|
| | 45 | { "help", no_argument, 0, CMD_HELP }, |
|---|
| | 46 | { "version", no_argument, 0, CMD_VERSION }, |
|---|
| | 47 | { "mtab", required_argument, 0, CMD_MTAB }, |
|---|
| | 48 | { NULL, 0, 0, 0 } |
|---|
| | 49 | }; |
|---|
| | 53 | static void |
|---|
| | 54 | showHelp(int fd, char const *cmd, int res) |
|---|
| | 55 | { |
|---|
| | 56 | WRITE_MSG(fd, "Usage:\n "); |
|---|
| | 57 | WRITE_STR(fd, cmd); |
|---|
| | 58 | WRITE_MSG(fd, " [--mtab <file>] <mount points>* -- <command> <args>*\n"); |
|---|
| | 59 | WRITE_MSG(fd, "\n" |
|---|
| | 60 | "Please report bugs to " PACKAGE_BUGREPORT "\n"); |
|---|
| | 61 | exit(res); |
|---|
| | 62 | } |
|---|
| | 63 | |
|---|
| | 64 | static void |
|---|
| | 65 | showVersion(void) |
|---|
| | 66 | { |
|---|
| | 67 | WRITE_MSG(1, |
|---|
| | 68 | "exec-remount " VERSION " -- remounts specified mount points and executes a program\n" |
|---|
| | 69 | "This program is part of " PACKAGE_STRING "\n\n" |
|---|
| | 70 | "Copyright (c) 2008 Daniel Hokka Zakrisson\n" |
|---|
| | 71 | VERSION_COPYRIGHT_DISCLAIMER); |
|---|
| | 72 | exit(0); |
|---|
| | 73 | } |
|---|
| | 74 | |
|---|
| | 75 | static void |
|---|
| | 76 | do_remount(char const *mount) |
|---|
| | 77 | { |
|---|
| | 78 | /* FIXME: Read this from mtab */ |
|---|
| | 79 | if (strcmp(mount, "/proc") == 0) |
|---|
| | 80 | Emount("proc", "proc", "proc", 0, NULL); |
|---|
| | 81 | else if (strcmp(mount, "/sys") == 0) |
|---|
| | 82 | Emount("sysfs", "sys", "sysfs", 0, NULL); |
|---|
| | 83 | else { |
|---|
| | 84 | WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "unknown mount point: "); |
|---|
| | 85 | WRITE_STR(2, mount); |
|---|
| | 86 | WRITE_MSG(2, "\n"); |
|---|
| | 87 | } |
|---|
| | 88 | } |
|---|
| | 89 | |
|---|
| 46 | | int i = 1; |
|---|
| 47 | | if (vc_isSupported(vcFEATURE_PIDSPACE)) { |
|---|
| 48 | | /* FIXME: Get options from etc/mtab |
|---|
| 49 | | * Get list of filesystems from argv |
|---|
| 50 | | */ |
|---|
| 51 | | if (umount("proc") == 0) |
|---|
| 52 | | Emount("proc", "proc", "proc", 0, NULL); |
|---|
| 53 | | if (umount("sys") == 0) |
|---|
| 54 | | Emount("sysfs", "sys", "sysfs", 0, NULL); |
|---|
| 55 | | } |
|---|
| 56 | | if (strcmp(argv[i], "--") == 0) |
|---|
| 57 | | i++; |
|---|
| 58 | | EexecvpD(argv[i], argv+i); |
|---|
| 59 | | /* NOTREACHED */ |
|---|
| 60 | | return 1; |
|---|
| | 92 | int i; |
|---|
| | 93 | char const *mtab = "/etc/mtab"; |
|---|
| | 94 | |
|---|
| | 95 | while (1) { |
|---|
| | 96 | int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); |
|---|
| | 97 | if (c==-1) break; |
|---|
| | 98 | |
|---|
| | 99 | switch (c) { |
|---|
| | 100 | case CMD_HELP : showHelp(1, argv[0], 0); |
|---|
| | 101 | case CMD_VERSION : showVersion(); |
|---|
| | 102 | case CMD_MTAB : mtab = optarg; break; |
|---|
| | 103 | default : showHelp(2, argv[0], 1); |
|---|
| | 104 | } |
|---|
| | 105 | } |
|---|
| | 106 | |
|---|
| | 107 | for (i = optind; argv[i] != NULL && strcmp(argv[i], "--") != 0; i++) { |
|---|
| | 108 | if (vc_isSupported(vcFEATURE_PIDSPACE)) { |
|---|
| | 109 | /* + 1 to strip the leading / */ |
|---|
| | 110 | if (umount2(argv[i] + 1, MNT_DETACH) == 0) |
|---|
| | 111 | do_remount(argv[i]); |
|---|
| | 112 | } |
|---|
| | 113 | } |
|---|
| | 114 | |
|---|
| | 115 | if (argv[i] == NULL) |
|---|
| | 116 | showHelp(2, argv[0], 1); |
|---|
| | 117 | |
|---|
| | 118 | i++; |
|---|
| | 119 | EexecvpD(argv[i], argv+i); |
|---|
| | 120 | /* NOTREACHED */ |
|---|
| | 121 | return 1; |
|---|