--- /dev/null
+## $Id$ --*- sh -*--
+
+case "$(hostname -s)" in
+ ensc-pc) BASE=/mnt/nfs/src/util-vserver.devel;;
+ delenn) BASE=/mnt/home/ensc/src/util-vserver.devel;;
+ *) BASE=/home/ensc/src/util-vserver.devel;;
+esac
+
+PACKAGE='util-vserver'
+PACKAGE_BUGREPORT='enrico.scholz@informatik.tu-chemnitz.de'
+PACKAGE_NAME='util-vserver'
+PACKAGE_STRING='util-vserver 0.23.89.1'
+PACKAGE_TARNAME='util-vserver'
+PACKAGE_VERSION='0.23.89.1'
+
+__CONFDIR='/etc/vservers'
+__INCLUDEDIR='/usr/include'
+__INITRDDIR='/etc/init.d'
+__LEGACYDIR=$BASE/scripts/legacy
+__LIBDIR=/usr/lib
+__LOCKDIR=/var/lock
+__PKGLIBDEFAULTDIR=$BASE/distrib/misc
+__PKGSTATEDIR='/var/run/vservers'
+__PKGSTATEREVDIR='/var/run/vservers.rev'
+__SBINDIR=$BASE/src
+__SYSCONFDIR='/usr/local/etc'
+__VSHELPERSTATEDIR='/var/run/vshelper'
+
+__DISTRIBDIR=$BASE/distrib
+__PKGLIBDIR=$BASE/scripts
+__RUNDIR=$__PKGSTATEDIR
+
+__DEFAULT_VSERVERDIR='/vservers'
+__DEFAULT_VSERVERPKGDIR='/vservers/.pkg'
+
+_CAPCHROOT="$BASE/src/capchroot"
+_CHAINECHO="$BASE/src/chain-echo"
+_CHBIND="$BASE/src/chbind"
+_CHCONTEXT="$BASE/scripts/chcontext"
+_CHCONTEXT_COMPAT="$BASE/src/chcontext-compat"
+_CHROOT_CAT="$BASE/src/chroot-cat"
+_CHROOT_RM="$BASE/src/chroot-rm"
+_EXEC_CD="$BASE/src/exec-cd"
+_EXEC_ULIMIT="$BASE/src/exec-ulimit"
+_FAKE_RUNLEVEL="$BASE/src/fakerunlevel"
+_FILETIME="$BASE/src/filetime"
+_INITSYNC_MINIT_START=:
+_LIB_FUNCTIONS="$BASE/scripts/functions"
+_LIB_VSERVER_SETUP_FUNCTIONS="$BASE/scripts/vserver-setup.functions"
+_LIB_VSERVER_BUILD_FUNCTIONS="$BASE/scripts/vserver-build.functions"
+_LIB_VSERVER_BUILD_FUNCTIONS_APT="$BASE/scripts/vserver-build.functions.apt"
+_LIB_VSERVER_BUILD_FUNCTIONS_RPM="$BASE/scripts/vserver-build.functions.rpm"
+_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT="$BASE/scripts/vserver-build.functions.pkgmgmt"
+_LOCKFILE="$BASE/src/lockfile"
+_MASK2PREFIX="$BASE/src/mask2prefix"
+_PKGMGMT="$BASE/scripts/pkgmgmt"
+_READLINK="$BASE/src/readlink"
+_REBOOTMGR="$BASE/src/rebootmgr"
+_RPM_FAKE_SO="$BASE/src/.libs/rpm-fake.so"
+_SAVE_CTXINFO="$BASE/src/save_ctxinfo"
+_SAVE_S_CONTEXT="$BASE/scripts/legacy/save_s_context"
+_SECURE_MOUNT="$BASE/src/secure-mount"
+_SETATTR="$BASE/src/setattr"
+_VAPT_GET="$BASE/scripts/vapt-get"
+_VAPT_GET_WORKER="$BASE/scripts/vapt-get-worker"
+_VATTRIBUTE="$BASE/src/vattribute"
+_VCONTEXT="$BASE/src/vcontext"
+_VKILL="$BASE/src/vkill"
+_VLIMIT="$BASE/src/vlimit"
+_VNAMESPACE="$BASE/src/vnamespace"
+_VPKG="$BASE/scripts/vpkg"
+_VPROCUNHIDE="$BASE/scripts/vprocunhide"
+_VPS="$BASE/src/vps"
+_VRPM="$BASE/scripts/vrpm"
+_VRPM_PRELOAD="$BASE/scripts/vrpm-preload"
+_VRPM_WORKER="$BASE/scripts/vrpm-worker"
+_VSCHED="$BASE/src/vsched"
+_VSERVER="$BASE/scripts/vserver"
+_VSERVER_LEGACY="$BASE/scripts/legacy/vserver"
+_VSERVER_BUILD="$BASE/scripts/vserver-build"
+_VSERVER_INFO="$BASE/src/vserver-info"
+_VSHELPER="$BASE/scripts/vshelper"
+_VSHELPER_SYNC="$BASE/src/vshelper-sync"
+_VSOMETHING="$BASE/scripts/vsomething"
+_VUNAME="$BASE/src/vuname"
+_VUNIFY="$BASE/src/vunify"
+_VYUM="$BASE/scripts/vyum"
+_VYUM_WORKER="$BASE/scripts/vyum-worker"
+
+_AWK="/bin/awk"
+_CAT="/bin/cat"
+_CHOWN="/bin/chown"
+_CMP="/usr/bin/cmp"
+_CP="/bin/cp"
+_DIRNAME="/usr/bin/dirname"
+_EGREP="/bin/egrep"
+_ENV="/bin/env"
+_GREP="/bin/grep"
+_IP="/sbin/ip"
+_IPTABLES="/sbin/iptables"
+_LN="/bin/ln"
+_LN_S="$_LN -s"
+_MKDIR="/bin/mkdir"
+_MKFIFO="/usr/bin/mkfifo"
+_MKTEMP="/bin/mktemp"
+_MKTEMPDIR="$_MKTEMP -d"
+_MODPROBE="/sbin/modprobe"
+_MOUNT="/bin/mount"
+_MV="/bin/mv"
+_NAMEIF="/sbin/nameif"
+_NICE="/bin/nice"
+_RM="/bin/rm"
+_RMDIR="/bin/rmdir"
+_RMMOD="/sbin/rmmod"
+_SED="/bin/sed"
+_SH="/bin/sh"
+_TAC="/usr/bin/tac"
+_TAR="/bin/tar"
+_TOUCH="/bin/touch"
+_TTY="/usr/bin/tty"
+_UMOUNT="/bin/umount"
+_VCONFIG="/sbin/vconfig"
+_WC="/usr/bin/wc"
+_WGET="/usr/bin/wget"
+
+# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=106057
+WORKAROUND_106057=1
+# /var/lib/rpm is hardcoded into apt-get which does not honor the
+# %_dbpath variable therefore
+# http://distro2.conectiva.com.br/pipermail/apt-rpm/2003-October/001985.html
+WORKAROUND_APT_DBPATH=1
--- /dev/null
+// $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 <vserver.h>
+#include <getopt.h>
+#include <errno.h>
+#include <assert.h>
+
+#define ENSC_WRAPPERS_PREFIX "vcontext: "
+#include <wrappers.h>
+
+#define CMD_HELP 0x1000
+#define CMD_VERSION 0x1001
+#define CMD_NID 0x4000
+#define CMD_CREATE 0x4001
+#define CMD_MIGRATE 0x4003
+#define CMD_SILENT 0x4007
+#define CMD_SILENTEXIST 0x400c
+
+struct option const
+CMDLINE_OPTIONS[] = {
+ { "help", no_argument, 0, CMD_HELP },
+ { "version", no_argument, 0, CMD_VERSION },
+ { "nid", required_argument, 0, CMD_NID },
+ { "create", no_argument, 0, CMD_CREATE },
+ { "migrate", required_argument, 0, CMD_MIGRATE },
+ { "silent", no_argument, 0, CMD_SILENT },
+ { "silentexist", no_argument, 0, CMD_SILENTEXIST },
+ { 0,0,0,0 }
+};
+
+struct Arguments {
+ bool do_create;
+ bool do_migrate;
+ bool is_silentexist;
+ int verbosity;
+ nid_t nid;
+};
+
+int wrapper_exit_code = 255;
+
+static void
+showHelp(char const *cmd)
+{
+ WRITE_MSG(1, "Usage:\n ");
+ WRITE_STR(1, cmd);
+ WRITE_MSG(1,
+ " --create <opts>* [--] <program> <args>*\n ");
+ WRITE_STR(1, cmd);
+ WRITE_MSG(1,
+ " --migrate <opts>* [--] <program> <args>*\n");
+ WRITE_STR(1, cmd);
+ WRITE_MSG(1,
+ " --add|--del <ip>/[<prefix>|<mask>] <opts>* [--] <program> <args>*\n");
+ WRITE_STR(1, cmd);
+ WRITE_MSG(1,
+ " (--flag <flags>*)|(--caps <caps>*) <opts>* [--] <program> <args>*\n"
+ "\n"
+ "<opts> can be:\n"
+ " --nid <nid> ... operate on network context <nid>; in combination\n"
+ " with '--create' the network context <nid> instead of\n"
+ " a dynamic one will be created, and with '--migrate\n"
+ " the context <nid> instead of the current one will\n"
+ " be entered\n"
+ " --silent ... be silent\n"
+ " --silentexist ... be silent when context exists already; usefully\n"
+ " for '--create' only\n"
+ "\n"
+ "'vnet --create' exits with code 254 iff the context exists already.\n"
+ "\n"
+ "Please report bugs to " PACKAGE_BUGREPORT "\n");
+
+ exit(0);
+}
+
+
+static void
+showVersion()
+{
+ WRITE_MSG(1,
+ "vnet " VERSION " -- manages the creation of network contexts\n"
+ "This program is part of " PACKAGE_STRING "\n\n"
+ "Copyright (C) 2004 Enrico Scholz\n"
+ VERSION_COPYRIGHT_DISCLAIMER);
+ exit(0);
+}
+
+static inline ALWAYSINLINE int
+doit(struct Arguments const *args, char *argv[])
+{
+ nid_t nid;
+
+ if (args->do_create) {
+ nid = vc_net_create_context(args->nid);
+ if (nid==VC_NONID) {
+ switch (errno) {
+ case EEXIST :
+ if (!args->is_silentexist)
+ perror(ENSC_WRAPPERS_PREFIX "vc_net_create_context()");
+ return 254;
+ default :
+ perror(ENSC_WRAPPERS_PREFIX "vc_net_create_context()");
+ return wrapper_exit_code;
+ }
+ }
+ tellContext(nid, args->verbosity>=1);
+ }
+ else
+ nid = args->nid;
+
+
+}
+
+
+int main (int argc, char *argv[])
+{
+ struct Arguments args = {
+ .do_create = false,
+ .do_migrate = false,
+ .is_silentexist = false,
+ .verbosity = 1,
+ .nid = VC_DYNAMIC_NID,
+ };
+
+ 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_NID : args.nid = optarg(nid); break;
+ case CMD_CREATE : args.do_create = true; break;
+ case CMD_MIGRATE : args.do_migrate = true; break;
+ case CMD_SILENTEXIST : args.is_silentexist = true; break;
+ case CMD_SILENT : --args.verbosity; break;
+
+ default :
+ WRITE_MSG(2, "Try '");
+ WRITE_STR(2, argv[0]);
+ WRITE_MSG(2, " --help\" for more information.\n");
+ return 255;
+ break;
+ }
+ }
+
+ if (args.nid==VC_DYNAMIC_NID && args.do_migrate)
+ args.nid = Evc_get_task_nid(0);
+
+ if (!args.do_create && !args.do_migrate)
+ WRITE_MSG(2, "Neither '--create' nor '--migrate specified; try '--help' for more information\n");
+ else if (args.do_create && args.do_migrate)
+ WRITE_MSG(2, "Can not specify '--create' and '--migrate' at the same time; try '--help' for more information\n");
+ else if (!args.do_create && args.nid==VC_DYNAMIC_NID)
+ WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "Can not migrate to an unknown context\n");
+ else if (optind>=argc)
+ WRITE_MSG(2, "No command given; use '--help' for more information.\n");
+ else
+ return doit(&args, argv);
+
+ return 255;
+}