Remove vnamespace in favor of vspace and a small wrapper around it.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Fri, 31 Oct 2008 04:21:52 +0000 (04:21 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Fri, 31 Oct 2008 04:21:52 +0000 (04:21 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2816 94cd875c-1c1d-0410-91d2-eb244daf1a30

scripts/Makefile-files
scripts/util-vserver-vars.pathsubst
scripts/vnamespace [new file with mode: 0755]
scripts/vserver-build.debootstrap
scripts/vsomething
src/Makefile-files
src/vnamespace.c [deleted file]

index 695317e..988d531 100644 (file)
@@ -92,14 +92,15 @@ scripts_sbin_src_PRGS =             scripts/chbind \
                                scripts/vdispatch-conf \
                                scripts/vemerge \
                                scripts/vesync \
+                               scripts/vmount \
+                               scripts/vnamespace \
                                scripts/vpstree \
                                scripts/vrpm \
                                scripts/vserver \
                                scripts/vsomething \
                                scripts/vtop \
                                scripts/vupdateworld \
-                               scripts/vyum \
-                               scripts/vmount
+                               scripts/vyum
 
 scripts_sbin_gen_PRGS =
 scripts_sbincfg_gen_DTA =
index 9a27c3e..ae8e0e0 100644 (file)
@@ -84,7 +84,7 @@ _VHASHIFY="$__PKGLIBDIR/vhashify"
 _VKILL="$__SBINDIR/vkill"
 _VLIMIT="$__SBINDIR/vlimit"
 _VMEMCTRL="$__SBINDIR/vmemctrl"
-_VNAMESPACE="$__SBINDIR/vnamespace"
+_VNAMESPACE="$__SBINDIR/vspace --mount --fs"
 _VPKG="$__PKGLIBDIR/vpkg"
 _VPROCUNHIDE="$__PKGLIBDIR/vprocunhide"
 _VPS="$__SBINDIR/vps"
diff --git a/scripts/vnamespace b/scripts/vnamespace
new file mode 100755 (executable)
index 0000000..657a935
--- /dev/null
@@ -0,0 +1,60 @@
+#! /bin/bash
+# $Id$
+
+# Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+# Copyright (C) 2008 Daniel Hokka Zakrisson
+#  
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#  
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#  
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
+test -e "$UTIL_VSERVER_VARS" || {
+    echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
+    exit 1
+}
+. "$UTIL_VSERVER_VARS"
+. "$_LIB_FUNCTIONS"
+
+function showHelp()
+{
+    echo \
+$"Usage: $1 <operation> [--] [<program> <args>*]
+
+<operation> can be one of:
+    --new|-n          ...  create new namespace and execute <program> there;
+                           <program> is mandatory in this case
+    --enter|-e <xid>  ...  enter the namespace of context <xid> and execute
+                           <program> there; <program> is mandatory in this
+                           case
+    --set|-s          ...  make current namespace the namespace of the
+                           current context
+    --cleanup|-c      ...  remove all mounts from the namespace of the
+                           current context
+
+Please report bugs to $PACKAGE_BUGREPORT"
+    exit $2
+}
+
+function showVersion()
+{
+    echo \
+$"vnamespace $PACKAGE_VERSION -- manages filesystem-namespace
+This program is part of $PACKAGE_STRING
+
+Copyright (C) 2004 Enrico Scholz
+This program is free software; you may redistribute it under the terms of
+the GNU General Public License.  This program has absolutely no warranty."
+    exit $1
+}
+
+exec $_VSPACE --mount --fs "$@"
index ba2dd56..78e5f11 100644 (file)
@@ -164,7 +164,7 @@ fi
 export MIRROR
 test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE"  "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
 mv "$VDIR"/dev "$VDIR"/dev.X
-"$_VNAMESPACE" --new -- \
+$_VNAMESPACE --new -- \
     "$DEBOOTSTRAP" $options "$@" "$DISTRIBUTION" "$VDIR" "$MIRROR" "$script" || :   ## HACK: ignore all errors...
 fixupDebian "$VDIR"
 test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
index 3ae3762..40185e5 100755 (executable)
@@ -112,7 +112,7 @@ for i in "${vservers[@]}"; do
              $_VSERVER "$i" status &> /dev/null || \
                CHBIND_CMD=()
              callInNamespace "$i" \
-               "$_VNAMESPACE" --new -- \
+               $_VNAMESPACE --new -- \
                "${CHBIND_CMD[@]}" \
                "$VSOMETHING_WORKER" "$i" "$@" )
        fi
index 3ffda07..ae5c293 100644 (file)
@@ -60,7 +60,6 @@ DIETPROGS +=          src/chcontext-compat \
                        src/sigexec \
                        src/vattribute \
                        src/vlimit \
-                       src/vnamespace \
                        src/vunify \
                        src/vuname \
                        src/rpm-fake-resolver \
@@ -158,7 +157,6 @@ sbin_PROGRAMS +=    src/exec-cd \
                        src/vcontext \
                        src/vlimit \
                        src/vkill \
-                       src/vnamespace \
                        src/vrsetup \
                        src/vsched \
                        src/vserver-stat \
@@ -248,10 +246,6 @@ src_vattribute_SOURCES =   src/vattribute.c
 src_vattribute_LDADD =         $(VSERVER_LDADDS)
 src_vattribute_LDFLAGS =       $(VSERVER_LDFLGS)
 
-src_vnamespace_SOURCES =       src/vnamespace.c
-src_vnamespace_LDADD =         $(VSERVER_LDADDS) $(LIBINTERNAL)
-src_vnamespace_LDFLAGS =       $(VSERVER_LDFLGS)
-
 src_rpm_fake_resolver_SOURCES  =  src/rpm-fake-resolver.c
 src_rpm_fake_resolver_LDADD    =  $(VSERVER_LDADDS)
 src_rpm_fake_resolver_LDFLAGS  =  $(VSERVER_LDFLGS)
diff --git a/src/vnamespace.c b/src/vnamespace.c
deleted file mode 100644 (file)
index d840fbb..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-// $Id$    --*- c -*--
-
-// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
-//  
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//  
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//  
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include "util.h"
-#include <lib_internal/sys_clone.h>
-
-#include <vserver.h>
-
-#include <getopt.h>
-#include <libgen.h>
-#include <errno.h>
-#include <signal.h>
-#include <sched.h>
-
-#define ENSC_WRAPPERS_PREFIX   "vnamespace: "
-#define ENSC_WRAPPERS_UNISTD   1
-#define ENSC_WRAPPERS_VSERVER  1
-#include <wrappers.h>
-
-#define CMD_HELP               0x1000
-#define CMD_VERSION            0x1001
-
-int            wrapper_exit_code  =  255;
-
-struct option const
-CMDLINE_OPTIONS[] = {
-  { "help",       no_argument,       0, CMD_HELP },
-  { "version",    no_argument,       0, CMD_VERSION },
-  { "new",        no_argument,       0, 'n' },
-  { "enter",      required_argument, 0, 'e' },
-  { "set",        no_argument,       0, 's' },
-  { "cleanup",    no_argument,       0, 'c' },
-  {0,0,0,0}
-};
-
-static void
-showHelp(int fd, char const *cmd, int res)
-{
-  WRITE_MSG(fd, "Usage: ");
-  WRITE_STR(fd, cmd);
-  WRITE_MSG(fd,
-           " <operation> [--] [<program> <args>*]\n"
-           "\n"
-           "<operation> can be one of:\n"
-           "    --new|-n          ...  create new namespace and execute <program> there;\n"
-           "                           <program> is mandatory in this case\n"
-           "    --enter|-e <xid>  ...  enter the namespace of context <xid> and execute\n"
-           "                           <program> there; <program> is mandatory in this\n"
-           "                           case\n"
-           "    --set|-s          ...  make current namespace the namespace of the\n"
-           "                           current context\n"
-           "    --cleanup|-c      ...  remove all mounts from the namespace of the\n"
-           "                           current context\n"
-           "\n"
-           "Please report bugs to " PACKAGE_BUGREPORT "\n");
-
-  exit(res);
-}
-
-static void
-showVersion()
-{
-  WRITE_MSG(1,
-           "vnamespace " VERSION " -- manages filesystem-namespace\n"
-           "This program is part of " PACKAGE_STRING "\n\n"
-           "Copyright (C) 2004 Enrico Scholz\n"
-           VERSION_COPYRIGHT_DISCLAIMER);
-  exit(0);
-}
-
-static void
-newNamespace(void)
-{
-  pid_t                pid;
-
-  signal(SIGCHLD, SIG_DFL);
-  
-#ifdef NDEBUG    
-  pid = sys_clone(CLONE_NEWNS|CLONE_VFORK|SIGCHLD, 0);
-#else
-  pid = sys_clone(CLONE_NEWNS|SIGCHLD, 0);
-#endif
-
-  switch (pid) {
-    case -1    :
-      perror("vnamespace: clone()");
-      exit(wrapper_exit_code);
-    case 0     :
-      break;
-    default    :
-      vc_exitLikeProcess(pid, wrapper_exit_code);
-  }
-}
-
-static void
-enterNamespace(xid_t xid, uint_least64_t mask)
-{
-  if (vc_enter_namespace(xid, mask)==-1) {
-    perror("vnamespace: vc_enter_namespace()");
-    exit(255);
-  }
-}
-
-static void
-setNamespace(xid_t xid, uint_least64_t mask)
-{
-  if (vc_set_namespace(xid, mask)==-1) {
-    perror("vnamespace: vc_set_namespace()");
-    exit(255);
-  }
-}
-
-static void
-cleanupNamespace()
-{
-  if (vc_cleanup_namespace()==-1) {
-    perror("vnamespace: vc_cleanup_namespace()");
-    exit(255);
-  }
-}
-
-int main(int argc, char *argv[])
-{
-  bool         do_new     = false;
-  bool         do_enter   = false;
-  bool         do_set     = false;
-  bool         do_cleanup = false;
-  xid_t                xid        = VC_NOCTX;
-  int          sum        = 0;
-  
-  while (1) {
-    int                c = getopt_long(argc, argv, "+nsce:", CMDLINE_OPTIONS, 0);
-    if (c==-1) break;
-
-    switch (c) {
-      case CMD_HELP    :  showHelp(1, argv[0], 0);
-      case CMD_VERSION :  showVersion();
-      case 'n'         :  do_new     = true; break;
-      case 's'         :  do_set     = true; break;
-      case 'c'         :  do_cleanup = true; break;
-      case 'e'         :
-       do_enter = true;
-       xid      = Evc_xidopt2xid(optarg,true);
-       break;
-
-      default          :
-       WRITE_MSG(2, "Try '");
-       WRITE_STR(2, argv[0]);
-       WRITE_MSG(2, " --help' for more information.\n");
-       return 255;
-       break;
-    }
-  }
-
-  sum = ((do_new ? 1 : 0) + (do_enter ? 1 : 0) +
-        (do_set ? 1 : 0) + (do_cleanup ? 1 : 0));
-  
-  if (sum==0)
-    WRITE_MSG(2, "No operation was specified; try '--help' for more information\n");
-  else if (sum>1)
-    WRITE_MSG(2, "Can not specify multiple operations; try '--help' for more information\n");
-  else if (optind==argc && (do_new || do_enter))
-    WRITE_MSG(2, "No command specified; try '--help' for more information\n");
-  else {
-    if      (do_new)     newNamespace();
-    else if (do_set)     setNamespace(VC_SAMECTX, CLONE_NEWNS|CLONE_FS);
-    else if (do_cleanup) cleanupNamespace();
-    else if (do_enter)   enterNamespace(xid, CLONE_NEWNS|CLONE_FS);
-
-    if (optind<argc)
-      EexecvpD(argv[optind], argv+optind);
-
-    return EXIT_SUCCESS;
-  }
-
-  return 255;
-}