From 859c1061d8e71309382f147a2497b272bf0abb9b Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Mon, 25 Aug 2008 22:57:09 +0000 Subject: [PATCH] Preparations for actually reading mtab. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2776 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- scripts/vserver.start | 2 +- src/exec-remount.c | 91 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/scripts/vserver.start b/scripts/vserver.start index cd3df9f..d49bfdf 100644 --- a/scripts/vserver.start +++ b/scripts/vserver.start @@ -144,7 +144,7 @@ if $_VSERVER_INFO - FEATURE migrate; then ${OPTION_STRACE:+$_STRACE -fF -o /tmp/vserver-start.$$} \ ${USE_VNAMESPACE:+$_VNAMESPACE --set -- } \ $_VSPACE --set "${OPTS_VSPACE[@]}" -- \ - $_EXEC_REMOUNT -- \ + $_EXEC_REMOUNT /proc /sys -- \ $_VLIMIT --dir "$VSERVER_DIR"/rlimits --missingok -- \ $_VSCHED --xid self --force "${OPTS_VSCHED[@]}" -- \ $_VSYSCTL --xid self --dir "$VSERVER_DIR"/sysctl --missingok -- \ diff --git a/src/exec-remount.c b/src/exec-remount.c index 05157c7..d2b693c 100644 --- a/src/exec-remount.c +++ b/src/exec-remount.c @@ -38,24 +38,85 @@ #define CMD_HELP 0x1000 #define CMD_VERSION 0x1001 +#define CMD_MTAB 0x2001 + +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; } -- 1.8.1.5