X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fexec-remount.c;h=caa59705948fe338862d99f281cd4a664e86f8fd;hb=148ab3024621f97b9cf95091657db2448098bc66;hp=05157c7b61cd4cc4607500416a2b42ef81805157;hpb=52dfff5433ea99e7427e781a1db43b68cbfe9243;p=util-vserver.git diff --git a/src/exec-remount.c b/src/exec-remount.c index 05157c7..caa5970 100644 --- a/src/exec-remount.c +++ b/src/exec-remount.c @@ -38,24 +38,89 @@ #define CMD_HELP 0x1000 #define CMD_VERSION 0x1001 +#define CMD_MTAB 0x2001 + +#ifndef MNT_DETACH +#define MNT_DETACH 0x0002 +#endif + +static struct option const +CMDLINE_OPTIONS[] = { + { "help", no_argument, 0, CMD_HELP }, + { "version", no_argument, 0, CMD_VERSION }, + { "mtab", required_argument, 0, CMD_MTAB }, + { NULL, 0, 0, 0 } +}; int wrapper_exit_code = 255; +static void +showHelp(int fd, char const *cmd, int res) +{ + WRITE_MSG(fd, "Usage:\n "); + WRITE_STR(fd, cmd); + WRITE_MSG(fd, " [--mtab ] * -- *\n"); + WRITE_MSG(fd, "\n" + "Please report bugs to " PACKAGE_BUGREPORT "\n"); + exit(res); +} + +static void +showVersion(void) +{ + WRITE_MSG(1, + "exec-remount " VERSION " -- remounts specified mount points and executes a program\n" + "This program is part of " PACKAGE_STRING "\n\n" + "Copyright (c) 2008 Daniel Hokka Zakrisson\n" + VERSION_COPYRIGHT_DISCLAIMER); + exit(0); +} + +static void +do_remount(char const *mount) +{ + /* FIXME: Read this from mtab */ + if (strcmp(mount, "/proc") == 0) + Emount("proc", "proc", "proc", 0, NULL); + else if (strcmp(mount, "/sys") == 0) + Emount("sysfs", "sys", "sysfs", 0, NULL); + else { + WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "unknown mount point: "); + WRITE_STR(2, mount); + WRITE_MSG(2, "\n"); + } +} + int main(int argc, char *argv[]) { - int i = 1; - if (vc_isSupported(vcFEATURE_PIDSPACE)) { - /* FIXME: Get options from etc/mtab - * Get list of filesystems from argv - */ - if (umount("proc") == 0) - Emount("proc", "proc", "proc", 0, NULL); - if (umount("sys") == 0) - Emount("sysfs", "sys", "sysfs", 0, NULL); - } - if (strcmp(argv[i], "--") == 0) - i++; - EexecvpD(argv[i], argv+i); - /* NOTREACHED */ - return 1; + int i; + char const *mtab = "/etc/mtab"; + + while (1) { + int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); + if (c==-1) break; + + switch (c) { + case CMD_HELP : showHelp(1, argv[0], 0); + case CMD_VERSION : showVersion(); + case CMD_MTAB : mtab = optarg; break; + default : showHelp(2, argv[0], 1); + } + } + + for (i = optind; argv[i] != NULL && strcmp(argv[i], "--") != 0; i++) { + if (vc_isSupported(vcFEATURE_PIDSPACE)) { + /* + 1 to strip the leading / */ + if (umount2(argv[i] + 1, MNT_DETACH) == 0) + do_remount(argv[i]); + } + } + + if (argv[i] == NULL) + showHelp(2, argv[0], 1); + + i++; + EexecvpD(argv[i], argv+i); + /* NOTREACHED */ + return 1; }