Preparations for actually reading mtab.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Mon, 25 Aug 2008 22:57:09 +0000 (22:57 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Mon, 25 Aug 2008 22:57:09 +0000 (22:57 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2776 94cd875c-1c1d-0410-91d2-eb244daf1a30

scripts/vserver.start
src/exec-remount.c

index cd3df9f..d49bfdf 100644 (file)
@@ -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 -- \
index 05157c7..d2b693c 100644 (file)
 
 #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 <file>] <mount points>* -- <command> <args>*\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;
 }