This commit was generated by cvs2svn to compensate for changes in r2826,
Daniel Hokka Zakrisson [Thu, 5 Jul 2007 18:38:05 +0000 (18:38 +0000)]
which included commits to RCS files with non-trunk default branches.

30 files changed:
contrib/yum-3.0.3-chroot.patch [new file with mode: 0644]
distrib/centos5/pkgs/01 [new file with mode: 0644]
distrib/centos5/pkgs/02 [new file with mode: 0644]
distrib/centos5/pkgs/03 [new file with mode: 0644]
distrib/centos5/yum.repos.d/CentOS-Base.repo [new file with mode: 0644]
distrib/centos5/yum/yum.conf [new file with mode: 0644]
distrib/etch/initpost [new file with mode: 0755]
distrib/etch/vserver-config.sh [new file with mode: 0755]
distrib/gentoo/net.vserver [new file with mode: 0644]
distrib/gentoo/reboot.sh [new file with mode: 0644]
distrib/gentoo/shutdown.sh [new file with mode: 0644]
distrib/misc/context.start [new file with mode: 0644]
distrib/misc/debootstrap.mirror [new file with mode: 0644]
gentoo/Makefile-files [new file with mode: 0644]
gentoo/util-vserver [new file with mode: 0644]
gentoo/vprocunhide [new file with mode: 0644]
gentoo/vservers.default [new file with mode: 0644]
kernel/device_cmd.h [new file with mode: 0644]
lib/syscall_schedinfo-v21.hc [new file with mode: 0644]
lib/syscall_schedinfo.c [new file with mode: 0644]
lib/syscall_setmapping-v21.hc [new file with mode: 0644]
lib/syscall_setmapping.c [new file with mode: 0644]
scripts/vserver-build.clone [new file with mode: 0644]
scripts/vserver-init.functions [new file with mode: 0755]
src/vclone.c [new file with mode: 0644]
src/vdevmap.c [new file with mode: 0644]
src/vsysctl.c [new file with mode: 0644]
sysv/util-vserver [new file with mode: 0755]
sysv/vprocunhide
sysv/vservers-legacy

diff --git a/contrib/yum-3.0.3-chroot.patch b/contrib/yum-3.0.3-chroot.patch
new file mode 100644 (file)
index 0000000..6bac70a
--- /dev/null
@@ -0,0 +1,167 @@
+--- yum-3.0.3/docs/yum.conf.5.chroot   2006-11-17 08:10:32.000000000 +0100
++++ yum-3.0.3/docs/yum.conf.5  2007-01-16 20:28:39.000000000 +0100
+@@ -23,8 +23,10 @@
+ following options:
+ .IP \fBcachedir\fR
+-Directory where yum should store its cache and db files. The default is
+-`/var/cache/yum'.
++Directory where yum should store its cache and db files. The default
++is `/var/cache/yum'. Unless the prefixes `hostfs://' or `chrootfs://'
++are used, some magic will be applied to determine the real path in
++combination with `--installroot'.
+ .IP \fBkeepcache\fR
+ Either `1' or `0'. Determines whether or not yum keeps the cache
+@@ -40,6 +42,10 @@
+ repositories defined in /etc/yum.conf to form the complete set of repositories
+ that yum will use.
++Unless the prefixes `hostfs://' or `chrootfs://' are used, some magic
++will be applied to determine the real path in combination with
++`--installroot'.
++
+ .IP \fBdebuglevel\fR
+ Debug message output level. Practical range is 0\-10. Default is `2'.
+@@ -47,7 +53,10 @@
+ Error message output level. Practical range is 0\-10. Default is `2'.
+ .IP \fBlogfile\fR
+-Full directory and file name for where yum should write its log file.
++Full directory and file name for where yum should write its log
++file. Unless the prefixes `hostfs://' or `chrootfs://' are used,
++some magic will be applied to determine the real path in combination
++with `--installroot'.
+ .IP \fBgpgcheck\fR
+ Either `1' or `0'. This tells yum whether or not it should perform a GPG
+--- yum-3.0.3/yum/config.py.chroot     2006-12-07 18:25:02.000000000 +0100
++++ yum-3.0.3/yum/config.py    2007-01-16 20:28:39.000000000 +0100
+@@ -464,6 +464,26 @@
+     pluginpath = ListOption(['/usr/lib/yum-plugins'])
+     pluginconfpath = ListOption(['/etc/yum/pluginconf.d'])
++    def getRootedPath(self, path, enforce_default=False, defaults_to_host=False):
++        instroot = getattr(self, 'installroot', None)
++        if instroot==None:
++            return path
++
++        if   path.startswith('hostfs://'):   res = path[9:]
++        elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:]
++        else:
++            tmp = instroot + '/' + path
++
++            if enforce_default:
++                if defaults_to_host:    res = path
++                else:                   res = tmp
++            else:
++                if os.path.exists(tmp): res = tmp
++                elif defaults_to_host:  res = path
++                else:                   res = tmp
++
++        return res
++
+ class YumConf(StartupConf):
+     '''
+     Configuration option definitions for yum.conf\'s [main] section.
+@@ -476,6 +496,7 @@
+     cachedir = Option('/var/cache/yum')
+     keepcache = BoolOption(True)
+     logfile = Option('/var/log/yum.log')
++    lockfile = Option('/var/run/yum.pid')
+     reposdir = ListOption(['/etc/yum/repos.d', '/etc/yum.repos.d'])
+     syslog_ident = Option()
+     syslog_facility = Option('LOG_DAEMON')
+@@ -602,9 +623,9 @@
+     yumconf.populate(startupconf._parser, 'main')
+     # Apply the installroot to directory options
+-    for option in ('cachedir', 'logfile'):
++    for option in ('cachedir', 'logfile', 'lockfile'):
+         path = getattr(yumconf, option)
+-        setattr(yumconf, option, yumconf.installroot + path)
++        setattr(yumconf, option, yumconf.getRootedPath(path))
+     
+     # Add in some extra attributes which aren't actually configuration values 
+     yumconf.yumvar = yumvars
+--- yum-3.0.3/yum/__init__.py.chroot   2007-01-07 21:09:27.000000000 +0100
++++ yum-3.0.3/yum/__init__.py  2007-01-16 20:32:04.000000000 +0100
+@@ -169,8 +169,7 @@
+         # (typically /etc/yum.repos.d and /etc/yum/repos.d)
+         parser = ConfigParser()
+         for reposdir in self.conf.reposdir:
+-            if os.path.exists(self.conf.installroot+'/'+reposdir):
+-                reposdir = self.conf.installroot + '/' + reposdir
++            reposdir  = self.conf.getRootedPath(reposdir)
+             if os.path.isdir(reposdir):
+                 for repofn in glob.glob('%s/*.repo' % reposdir):
+@@ -523,17 +522,15 @@
+             
+         self.verbose_logger.log(logginglevels.INFO_2, 'Finished')
+         
+-    def doLock(self, lockfile = YUM_PID_FILE):
++    def doLock(self):
+         """perform the yum locking, raise yum-based exceptions, not OSErrors"""
+         
+         # if we're not root then we don't lock - just return nicely
+         if self.conf.uid != 0:
+             return
+-            
+-        root = self.conf.installroot
+-        lockfile = root + '/' + lockfile # lock in the chroot
+-        lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra /
+-        
++
++        lockfile = self.conf.lockfile
++
+         mypid=str(os.getpid())    
+         while not self._lock(lockfile, mypid, 0644):
+             fd = open(lockfile, 'r')
+@@ -558,16 +555,15 @@
+                     msg = 'Existing lock %s: another copy is running. Aborting.' % lockfile
+                     raise Errors.LockError(0, msg)
+     
+-    def doUnlock(self, lockfile = YUM_PID_FILE):
++    def doUnlock(self):
+         """do the unlock for yum"""
+         
+         # if we're not root then we don't lock - just return nicely
+         if self.conf.uid != 0:
+             return
+         
+-        root = self.conf.installroot
+-        lockfile = root + '/' + lockfile # lock in the chroot
+-        
++        lockfile=self.conf.lockfile
++
+         self._unlock(lockfile)
+         
+     def _lock(self, filename, contents='', mode=0777):
+--- yum-3.0.3/cli.py.chroot    2006-12-08 00:27:08.000000000 +0100
++++ yum-3.0.3/cli.py   2007-01-16 20:28:39.000000000 +0100
+@@ -131,7 +131,7 @@
+                 action="store_true", default=False, 
+                 help="run entirely from cache, don't update cache")
+         self.optparser.add_option("-c", "", dest="conffile", action="store", 
+-                default='/etc/yum.conf', help="config file location", 
++                default=None, help="config file location", 
+                 metavar=' [config file]')
+         self.optparser.add_option("-R", "", dest="sleeptime", action="store", 
+                 type='int', default=None, help="maximum command wait time",
+@@ -188,9 +188,12 @@
+         # If the conf file is inside the  installroot - use that.
+         # otherwise look for it in the normal root
+-        if opts.installroot:
+-            if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
++        if opts.conffile==None:
++            opts.conffile = '/etc/yum.conf'
++            if opts.installroot and os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
+                 opts.conffile = opts.installroot+'/'+opts.conffile
++        
++        if opts.installroot:
+             root=opts.installroot
+         else:
+             root = '/'
diff --git a/distrib/centos5/pkgs/01 b/distrib/centos5/pkgs/01
new file mode 100644 (file)
index 0000000..1a5ef72
--- /dev/null
@@ -0,0 +1 @@
+glibc
diff --git a/distrib/centos5/pkgs/02 b/distrib/centos5/pkgs/02
new file mode 100644 (file)
index 0000000..9ec5d2b
--- /dev/null
@@ -0,0 +1,3 @@
+--reinstall
+
+filesystem
diff --git a/distrib/centos5/pkgs/03 b/distrib/centos5/pkgs/03
new file mode 100644 (file)
index 0000000..64ab4a7
--- /dev/null
@@ -0,0 +1,2 @@
+coreutils
+setup
diff --git a/distrib/centos5/yum.repos.d/CentOS-Base.repo b/distrib/centos5/yum.repos.d/CentOS-Base.repo
new file mode 100644 (file)
index 0000000..a4281a2
--- /dev/null
@@ -0,0 +1,61 @@
+# CentOS-Base.repo
+#
+# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
+# The mirror system uses the connecting IP address of the client and the
+# update status of each mirror to pick mirrors that are updated to and
+# geographically close to the client.  You should use this for CentOS updates
+# unless you are manually picking other mirrors.
+#
+# If the mirrorlist= does not work for you, as a fall back you can try the 
+# remarked out baseurl= line instead.
+#
+#
+
+[base]
+name=CentOS-5 - Base
+mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=os
+#baseurl=http://mirror.centos.org/centos/5/os/$basearch/
+gpgcheck=1
+gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
+
+#released updates 
+[updates]
+name=CentOS-5 - Updates
+mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=updates
+#baseurl=http://mirror.centos.org/centos/5/updates/$basearch/
+gpgcheck=1
+gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
+
+#packages used/produced in the build but not released
+[addons]
+name=CentOS-5 - Addons
+mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=addons
+#baseurl=http://mirror.centos.org/centos/5/addons/$basearch/
+gpgcheck=1
+gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
+
+#additional packages that may be useful
+[extras]
+name=CentOS-5 - Extras
+mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=extras
+#baseurl=http://mirror.centos.org/centos/5/extras/$basearch/
+gpgcheck=1
+gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
+
+#additional packages that extend functionality of existing packages
+[centosplus]
+name=CentOS-5 - Plus
+mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=centosplus
+#baseurl=http://mirror.centos.org/centos/5/centosplus/$basearch/
+gpgcheck=1
+enabled=0
+gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
+
+#contrib - packages by Centos Users
+[contrib]
+name=CentOS-5 - Contrib
+mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=contrib
+#baseurl=http://mirror.centos.org/centos/5/contrib/$basearch/
+gpgcheck=1
+enabled=0
+gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
diff --git a/distrib/centos5/yum/yum.conf b/distrib/centos5/yum/yum.conf
new file mode 100644 (file)
index 0000000..952f111
--- /dev/null
@@ -0,0 +1,10 @@
+[main]
+cachedir=@YUMCACHEDIR@
+reposdir=@YUMETCDIR@/yum.repos.d
+debuglevel=1
+logfile=@YUMLOGDIR@/log
+lockfile=@YUMLOCKDIR@/yum.pid
+pkgpolicy=newest
+distroverpkg=centos-release
+installonlypkgs=
+exactarch=0
diff --git a/distrib/etch/initpost b/distrib/etch/initpost
new file mode 100755 (executable)
index 0000000..bd6e698
--- /dev/null
@@ -0,0 +1,130 @@
+#!/bin/bash
+
+# Copyright (C) 2006 Benedikt Boehm <hollow@gentoo.org>
+#  
+# 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.
+
+## Called as: initpost <cfgdir> <path of util-vserver-vars>
+
+# setup environment
+cfgdir="$1"
+vdir="$cfgdir"/vdir
+. "$2"
+
+
+# vserver name
+NAME=$(< "$cfgdir"/name)
+
+# debian mirror
+MIRROR=$3
+
+# debian distribution
+DIST="etch"
+
+
+# go to vdir for chroot-sh
+pushd "$vdir" &>/dev/null
+
+
+# helper for sed in chroot
+chrootsed() {
+       local file="$1"
+       shift
+       
+       sedtmp=$($_MKTEMP chrootsed.XXXXXX)
+       
+       $_CHROOT_SH cat "$file" | $_SED "$@" > $sedtmp
+       $_CHROOT_SH truncate "$file"  < $sedtmp
+       
+       $_RM -f $sedtmp
+}
+
+
+# create a locale.gen if needed.
+if test -n "$LANG" && test "$LANG" != "C"; then
+       echo $LANG $(locale charmap) | $_CHROOT_SH append /etc/locale.gen
+fi
+
+
+# make apt and friends work
+$_CHROOT_SH truncate /etc/apt/sources.list <<EOF
+deb $MIRROR/ $DIST main
+deb-src $MIRROR/ $DIST main
+
+deb http://security.debian.org $DIST/updates main
+EOF
+
+
+# setting hostname
+if test -r "$cfgdir"/uts/nodename; then
+       $_CHROOT_SH truncate /etc/hostname < "$cfgdir"/uts/nodename
+fi
+
+
+# setting default /etc/hosts
+$_CHROOT_SH truncate /etc/hosts <<EOF
+# /etc/hosts
+
+127.0.0.1      localhost
+
+# The following lines are desirable for IPv6 capable hosts
+# (added automatically by netbase upgrade)
+
+::1    ip6-localhost ip6-loopback
+fe00::0 ip6-localnet
+ff00::0 ip6-mcastprefix
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
+ff02::3 ip6-allhosts
+EOF
+
+
+# copy proxy server statement from host if any
+if test -f /etc/apt/apt.conf; then
+       $_CHROOT_SH truncate /etc/apt/apt.conf < /etc/apt/apt.conf
+fi
+
+
+# fix gettys in inittab
+if $_CHROOT_SH testfile /etc/inittab; then
+       chrootsed /etc/inittab \
+               -e 's/\(^[^#].*getty.*$\)/#\1/'
+fi
+
+
+# fix /proc/cmdline in sendsigs
+if $_CHROOT_SH testfile /etc/init.d/sendsigs; then
+       chrootsed /etc/init.d/sendsigs \
+               -e 's/^\(\s\+splash_back\)$/#\1/'
+fi
+
+# from here on we need to do things live in the server
+$_CHROOT_SH truncate   /vserver-config.sh < "$__DISTRIBDIR"/etch/vserver-config.sh
+$_CHROOT_SH chmod 0755 /vserver-config.sh
+
+echo
+echo ">>> Executing post install script ... "
+echo
+
+# start vserver before we can exec anything inside it
+vserver $NAME start
+
+# run the configure commands from within the server
+vserver $NAME exec /vserver-config.sh
+$_CHROOT_SH rm /vserver-config.sh
+
+# stop the vserver
+vserver $NAME stop
+
+popd &>/dev/null
diff --git a/distrib/etch/vserver-config.sh b/distrib/etch/vserver-config.sh
new file mode 100755 (executable)
index 0000000..bceae55
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+REMOVE_LINKS="
+bootlogd
+checkfs
+checkroot
+halt
+hwclock.sh
+ifupdown
+klogd
+libdevmapper1.02
+makedev
+module-init-tools
+mountall.sh
+mountdevsubfs.sh
+mountnfs.sh
+mountkernfs.sh
+mountvirtfs
+networking
+reboot
+setserial
+single
+stop-bootlogd
+stop-bootlogd-single
+umountfs
+umountnfs.sh
+umountroot
+urandom
+"
+
+aptitude update
+LANG=C aptitude install locales
+
+test -x /usr/sbin/locale-gen && /usr/sbin/locale-gen
+
+for link in $REMOVE_LINKS; do
+       update-rc.d -f $link remove
+done
+
diff --git a/distrib/gentoo/net.vserver b/distrib/gentoo/net.vserver
new file mode 100644 (file)
index 0000000..8348277
--- /dev/null
@@ -0,0 +1,16 @@
+#!/sbin/runscript
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+depend() {
+        provide net
+}
+
+start() {
+        return 0
+}
+
+stop() {
+        return 0
+}
diff --git a/distrib/gentoo/reboot.sh b/distrib/gentoo/reboot.sh
new file mode 100644 (file)
index 0000000..c5fcea9
--- /dev/null
@@ -0,0 +1,5 @@
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# gentoo init style needs this (and nothing else)
+exit 0
diff --git a/distrib/gentoo/shutdown.sh b/distrib/gentoo/shutdown.sh
new file mode 100644 (file)
index 0000000..c5fcea9
--- /dev/null
@@ -0,0 +1,5 @@
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# gentoo init style needs this (and nothing else)
+exit 0
diff --git a/distrib/misc/context.start b/distrib/misc/context.start
new file mode 100644 (file)
index 0000000..c5da56a
--- /dev/null
@@ -0,0 +1 @@
+40000
diff --git a/distrib/misc/debootstrap.mirror b/distrib/misc/debootstrap.mirror
new file mode 100644 (file)
index 0000000..04ed33b
--- /dev/null
@@ -0,0 +1 @@
+http://ftp.debian.org/debian
diff --git a/gentoo/Makefile-files b/gentoo/Makefile-files
new file mode 100644 (file)
index 0000000..fb03479
--- /dev/null
@@ -0,0 +1,31 @@
+## $Id$  -*- makefile -*-
+
+## Copyright (C) 2003 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; either version 2, or (at your option)
+## any later version.
+##  
+## 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.
+##  
+
+AM_INSTALLCHECK_STD_OPTIONS_EXEMPT +=  \
+                       $(gentoo_src_SCRPTS)
+
+gentoo_src_SCRPTS =    gentoo/vprocunhide \
+                       gentoo/vservers.default \
+                       gentoo/util-vserver
+
+EXTRA_DIST +=          $(gentoo_src_SCRPTS)
+
+if HAVE_GENTOO_INIT
+initrd_SCRIPTS +=      $(gentoo_src_SCRPTS)
+endif
diff --git a/gentoo/util-vserver b/gentoo/util-vserver
new file mode 100644 (file)
index 0000000..1827326
--- /dev/null
@@ -0,0 +1,72 @@
+#!/sbin/runscript
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+set_helper() {
+       local f="/proc/sys/kernel/vshelper"
+       if [ -e "$f" ]; then
+               echo "$_VSHELPER" > "$f"
+       fi
+       return 0
+}
+
+kill_contexts() {
+       local xid
+       for xid in `ls -1 /proc/virtual`; do
+               [ "$xid" = "info" -o "$xid" = "status" ] && continue
+               $_VATTRIBUTE --xid $xid --set --flag ~persistent
+               $_VKILL --xid $xid -s 15
+               sleep 3
+               $_VKILL --xid $xid -s 9
+       done
+       local alive=0
+       for xid in `ls -1 /proc/virtual`; do
+               [ "$xid" = "info" -o "$xid" = "status" ] && continue
+               let alive+=1
+       done
+       return $alive
+}
+
+start() {
+       : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
+       if [[ ! -e ${UTIL_VSERVER_VARS} ]]; then
+               eerror "Cannot find util-vserver installation"
+               eerror "(the file '$UTIL_VSERVER_VARS' would be expected)"
+               return 1
+       fi
+       
+       source ${UTIL_VSERVER_VARS}
+       source "$_LIB_FUNCTIONS"
+       source "$__PKGLIBDIR/vserver.functions"
+
+       ebegin "Setting vshelper path to $_VSHELPER"
+       set_helper
+       eend $?
+
+       ebegin "Loading default device map"
+       loadDeviceMap 0 "$__CONFDIR/.defaults/apps/vdevmap"
+       eend $?
+}
+
+stop() {
+       : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
+       if [[ ! -e ${UTIL_VSERVER_VARS} ]]; then
+               eerror "Cannot find util-vserver installation"
+               eerror "(the file '$UTIL_VSERVER_VARS' would be expected)"
+               return 1
+       fi
+       
+       source ${UTIL_VSERVER_VARS}
+       source "$_LIB_FUNCTIONS"
+       source "$__PKGLIBDIR/vserver.functions"
+
+       ebegin "Stopping all running guests"
+       $_START_VSERVERS -j 1 --all --stop
+       eend $?
+
+       ebegin "Killing all running contexts"
+       kill_contexts
+       eend $?
+}
+
+# vim:ts=4:filetype=gentoo-init-d
diff --git a/gentoo/vprocunhide b/gentoo/vprocunhide
new file mode 100644 (file)
index 0000000..d7199ca
--- /dev/null
@@ -0,0 +1,20 @@
+#!/sbin/runscript
+# Copyright 1999-2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+start() {
+       : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
+       if [[ ! -e ${UTIL_VSERVER_VARS} ]]; then
+               eerror "Cannot find util-vserver installation"
+               eerror "(the file '$UTIL_VSERVER_VARS' would be expected)"
+               return 1
+       fi
+       
+       source ${UTIL_VSERVER_VARS}
+       
+       ebegin "Fixing /proc entries visibility"
+       ${_VPROCUNHIDE}
+       eend $?
+}
+
+# vim:ts=4:filetype=gentoo-init-d
diff --git a/gentoo/vservers.default b/gentoo/vservers.default
new file mode 100644 (file)
index 0000000..f4416eb
--- /dev/null
@@ -0,0 +1,19 @@
+#!/sbin/runscript
+# Copyright 1999-2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+       need util-vserver vprocunhide
+}
+
+start() {
+       MARK=${SVCNAME#vservers.} /usr/lib/util-vserver/vserver-wrapper start
+}
+
+stop() {
+       MARK=${SVCNAME#vservers.} /usr/lib/util-vserver/vserver-wrapper stop
+}
+
+
+
+# vim:ts=4:filetype=gentoo-init-d
diff --git a/kernel/device_cmd.h b/kernel/device_cmd.h
new file mode 100644 (file)
index 0000000..5ebf825
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _VX_DEVICE_CMD_H
+#define _VX_DEVICE_CMD_H
+
+
+/*  device vserver commands */
+
+#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
+
+struct vcmd_set_mapping_v0 {
+       const char *device;
+       const char *target;
+       uint32_t flags;
+};
+
+
+#endif /* _VX_DEVICE_CMD_H */
diff --git a/lib/syscall_schedinfo-v21.hc b/lib/syscall_schedinfo-v21.hc
new file mode 100644 (file)
index 0000000..f153cbb
--- /dev/null
@@ -0,0 +1,41 @@
+// $Id: syscall_schedinfo-v21.hc 2449 2007-01-10 18:53:07Z dhozac $    --*- c++ -*--
+
+// Copyright (C) 2007 Daniel Hokka Zakrisson <daniel@hozac.com>
+//  
+// 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
+
+static inline ALWAYSINLINE int
+vc_sched_info_v21(xid_t ctx, struct vc_sched_info *info)
+{
+  int ret;
+  struct vcmd_sched_info param = { .cpu_id = info->cpu_id, .bucket_id = info->bucket_id };
+
+  ret = vserver(VCMD_sched_info, CTX_USER2KERNEL(ctx), &param);
+  if (ret)
+    return ret;
+
+#define G(ATTR)        info->ATTR = param.ATTR
+  G(user_msec);
+  G(sys_msec);
+  G(hold_msec);
+  G(token_usec);
+  G(vavavoom);
+
+  return 0;
+}
diff --git a/lib/syscall_schedinfo.c b/lib/syscall_schedinfo.c
new file mode 100644 (file)
index 0000000..f91c48b
--- /dev/null
@@ -0,0 +1,39 @@
+// $Id: syscall_schedinfo.c 2449 2007-01-10 18:53:07Z dhozac $    --*- c++ -*--
+
+// Copyright (C) 2007 Daniel Hokka Zakrisson <daniel@hozac.com>
+//  
+// 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 "vserver.h"
+#include "vserver-internal.h"
+#include "virtual.h"
+
+#if defined(VC_ENABLE_API_V21)
+#  include "syscall_schedinfo-v21.hc"
+#endif
+
+#if defined(VC_ENABLE_API_V21)
+
+int
+vc_sched_info(xid_t ctx, struct vc_sched_info *info)
+{
+  CALL_VC(CALL_VC_V21(vc_sched_info, ctx, info));
+}
+
+#endif
diff --git a/lib/syscall_setmapping-v21.hc b/lib/syscall_setmapping-v21.hc
new file mode 100644 (file)
index 0000000..10c6be6
--- /dev/null
@@ -0,0 +1,29 @@
+// $Id: syscall_setmapping-v21.hc 2427 2006-12-12 01:39:54Z dhozac $    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+// Copyright (C) 2006 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.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+static inline ALWAYSINLINE int
+vc_set_mapping_v21(xid_t xid, const char *device, const char *target, uint32_t flags)
+{
+  struct vcmd_set_mapping_v0 data = { .device = device, .target = target, .flags = flags };
+  return vserver(VCMD_set_mapping, xid, &data);
+}
diff --git a/lib/syscall_setmapping.c b/lib/syscall_setmapping.c
new file mode 100644 (file)
index 0000000..23583db
--- /dev/null
@@ -0,0 +1,38 @@
+// $Id: syscall_setmapping.c 2427 2006-12-12 01:39:54Z dhozac $    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+// Copyright (C) 2006 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.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include "virtual.h"
+
+#if defined(VC_ENABLE_API_V21)
+#  include "syscall_setmapping-v21.hc"
+#endif
+
+#if defined(VC_ENABLE_API_V21)
+int
+vc_set_mapping(xid_t xid, const char *device, const char *target, uint32_t flags)
+{
+  CALL_VC(CALL_VC_V21(vc_set_mapping, xid, device, target, flags));
+}
+#endif
diff --git a/scripts/vserver-build.clone b/scripts/vserver-build.clone
new file mode 100644 (file)
index 0000000..7cac25b
--- /dev/null
@@ -0,0 +1,70 @@
+# $Id: vserver-build.clone 2494 2007-02-11 00:45:04Z dhozac $  --*- sh -*--
+
+# Copyright (C) 2003 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.
+
+tmp=$(getopt -o '+d:s:o:' --long debug,pkgmgmt,source: -n "$0" -- "$@") || exit 1
+eval set -- "$tmp"
+
+. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
+
+DISTRIBUTION=:
+use_pkgmgmt=
+SOURCE=
+while true; do
+    case "$1" in
+       -d)             DISTRIBUTION=$2; shift;;
+       --debug)        set -x;;
+       --pkgmgmt)      use_pkgmgmt=1;;
+       -s|--source)    SOURCE=$2; shift;;
+       --)             shift; break ;;
+       *)              echo "vserver-build.clone: internal error: unrecognized option '$1'" >&2
+                       exit 1
+                       ;;
+    esac
+    shift
+done
+
+if test -d "$SOURCE"; then
+    :
+elif test -d "$__CONFDIR/$SOURCE"; then
+    SOURCE=`getPhysicalDir "$__CONFDIR/$SOURCE/vdir"`
+elif test -d "$__DEFAULT_VSERVERDIR/$SOURCE"; then
+    SOURCE=`getPhysicalDir "$__DEFAULT_VSERVERDIR/$SOURCE"`
+else
+    SOURCE=
+fi
+
+test -n "$SOURCE" || panic $"vserver-build.clone: valid --source argument required"
+
+getDistribution '' 1
+
+base.init
+test -z "$use_pkgmgmt" || pkgmgmt.initVariables
+
+base.initFilesystem "$OPTION_FORCE"
+test -z "$use_pkgmgmt" || pkgmgmt.initFilesystem "$OPTION_FORCE"
+
+
+setup_writeOption "$VSERVER_NAME"
+setup_writeInitialFstab
+
+test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE" "$SETUP_CONFDIR"  "$UTIL_VSERVER_VARS"
+
+$_VCLONE "$SOURCE"/ "$VDIR"/
+
+test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+
+base.setSuccess
diff --git a/scripts/vserver-init.functions b/scripts/vserver-init.functions
new file mode 100755 (executable)
index 0000000..1f1255a
--- /dev/null
@@ -0,0 +1,50 @@
+#! /bin/bash
+
+# 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.
+
+if test -e /etc/init.d/functions; then
+    . /etc/init.d/functions
+    _beginResult() { echo -n "$@..."; }
+    _postResult() { echo; }
+    lockfile=/var/lock/subsys/$LOCKFILE
+elif test -e /etc/gentoo-release; then
+    . /sbin/functions.sh
+    _beginResult() { ebegin "$@"; }
+    _postResult() { :; }
+    success() { eend 0; }
+    passed()  { eend 0; }
+    failure() { eend 1; }
+    lockfile=/var/lock/vservers/$LOCKFILE
+else
+    _beginResult() { echo -n "$@..."; }
+    _postResult() { :; }
+    success() { echo .; }
+    passed()  { echo .; }
+    failure() { echo ERROR; }
+    lockfile=/var/run/$LOCKFILE
+fi
+
+function _endResult()
+{
+    local rc=$1
+    case "$rc" in
+       (0)     success;;
+       (2)     passed; rc=0;;
+       (*)     failure;;
+    esac
+    _postResult
+    return $rc
+}
diff --git a/src/vclone.c b/src/vclone.c
new file mode 100644 (file)
index 0000000..f4a994b
--- /dev/null
@@ -0,0 +1,214 @@
+// $Id: vclone.c 2494 2007-02-11 00:45:04Z dhozac $    --*- c -*--
+
+// Copyright (C) 2007 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.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "util.h"
+#include "vserver.h"
+
+#include "lib_internal/pathinfo.h"
+#include "lib_internal/unify.h"
+
+#include <unistd.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <errno.h>
+#include <assert.h>
+#include <utime.h>
+#include <libgen.h>
+#include <sys/param.h>
+
+#define ENSC_WRAPPERS_PREFIX   "vclone: "
+#define ENSC_WRAPPERS_UNISTD   1
+#define ENSC_WRAPPERS_FCNTL    1
+#define ENSC_WRAPPERS_DIRENT   1
+#include <wrappers.h>
+
+#define CMD_HELP               0x8000
+#define CMD_VERSION            0x8001
+
+struct WalkdownInfo
+{
+    PathInfo   state;
+    PathInfo   src;
+    PathInfo   dst;
+};
+
+struct Arguments {
+    unsigned int       verbosity;
+};
+
+static struct WalkdownInfo             global_info;
+static struct Arguments const *                global_args;
+
+int wrapper_exit_code = 1;
+
+struct option const
+CMDLINE_OPTIONS[] = {
+  { "help",     no_argument,       0, CMD_HELP },
+  { "version",  no_argument,       0, CMD_VERSION },
+  { 0,0,0,0 }
+};
+
+
+static void
+showHelp(int fd, char const *cmd, int res)
+{
+  VSERVER_DECLARE_CMD(cmd);
+  
+  WRITE_MSG(fd, "Usage:\n  ");
+  WRITE_STR(fd, cmd);
+  WRITE_MSG(fd,
+           " <source> <absolute path to destination>\n\n"
+           "Please report bugs to " PACKAGE_BUGREPORT "\n");
+  exit(res);
+}
+
+static void
+showVersion()
+{
+  WRITE_MSG(1,
+           "vclone " VERSION " -- clones a guest\n"
+           "This program is part of " PACKAGE_STRING "\n\n"
+           "Copyright (C) 2007 Daniel Hokka Zakrisson\n"
+           VERSION_COPYRIGHT_DISCLAIMER);
+  exit(0);
+}
+
+int Global_getVerbosity() {
+  return global_args->verbosity;
+}
+
+bool Global_doRenew() {
+  return true;
+}
+
+#include "vserver-visitdir.hc"
+
+static uint64_t
+visitDirEntry(struct dirent const *ent)
+{
+  char const *                 dirname  = ent->d_name;
+  if (isDotfile(dirname)) return 0;
+
+  uint64_t                     res      = 1;
+  PathInfo                     src_path = global_info.state;
+  PathInfo                     src_d_path = {
+    .d = dirname,
+    .l = strlen(dirname)
+  };
+  char                         path_buf[ENSC_PI_APPSZ(src_path, src_d_path)];
+  struct stat                  f_stat = { .st_dev = 0 };
+
+  PathInfo_append(&src_path, &src_d_path, path_buf);
+
+  
+  if (lstat(dirname, &f_stat)==-1)
+    perror(ENSC_WRAPPERS_PREFIX "lstat()");
+  else {
+    PathInfo           dst_path = global_info.dst;
+    char               dst_path_buf[ENSC_PI_APPSZ(dst_path, src_path)];
+
+    PathInfo_append(&dst_path, &src_path, dst_path_buf);
+
+    /* skip files that already exist */
+    if (access(dst_path.d, F_OK)!=-1)
+      res = 0;
+    else if (S_ISREG(f_stat.st_mode) && Unify_isIUnlinkable(src_d_path.d) == unifyBUSY) {
+      Elink(src_d_path.d, dst_path.d);
+      res = 0;
+    }
+    else {
+      if (!Unify_copy(src_d_path.d, &f_stat, dst_path.d)) {
+       perror(ENSC_WRAPPERS_PREFIX "Unify_copy()");
+       exit(wrapper_exit_code);
+      }
+      res = 0;
+    }
+    if (S_ISDIR(f_stat.st_mode))
+      res = visitDir(dirname, &f_stat);
+  }
+
+  return res;
+}
+
+int main(int argc, char *argv[])
+{
+  struct Arguments     args = {
+    .verbosity         =  0,
+  };
+  uint64_t             res;
+  int                  num_args;
+
+  global_args = &args;
+  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();
+      default          :
+       WRITE_MSG(2, "Try '");
+       WRITE_STR(2, argv[0]);
+       WRITE_MSG(2, " --help' for more information.\n");
+       return EXIT_FAILURE;
+       break;
+    }
+  }
+
+  num_args = argc - optind;
+  if (num_args < 1) {
+    WRITE_MSG(2, "Source is missing; try '");
+    WRITE_STR(2, argv[0]);
+    WRITE_MSG(2, " --help' for more information.\n");
+    return EXIT_FAILURE;
+  }
+  else if (num_args < 2) {
+    WRITE_MSG(2, "Destination is missing; try '");
+    WRITE_STR(2, argv[0]);
+    WRITE_MSG(2, " --help' for more information.\n");
+    return EXIT_FAILURE;
+  }
+  else if (num_args > 2) {
+    WRITE_MSG(2, "Too many arguments; try '");
+    WRITE_STR(2, argv[0]);
+    WRITE_MSG(2, " --help' for more information.\n");
+    return EXIT_FAILURE;
+  }
+  else if (*argv[optind+1] != '/') {
+    WRITE_MSG(2, "The destination must be an absolute path; try '");
+    WRITE_STR(2, argv[0]);
+    WRITE_MSG(2, " --help' for more information.\n");
+    return EXIT_FAILURE;
+  }
+  ENSC_PI_SETSTR(global_info.src, argv[optind]);
+  ENSC_PI_SETSTR(global_info.dst, argv[optind+1]);
+
+  if (global_args->verbosity>3)
+    WRITE_MSG(1, "Starting to traverse directories...\n");
+
+  Echdir(global_info.src.d);
+  res = visitDir("/", 0);
+  
+  return res>0 ? 1 : 0;
+}
diff --git a/src/vdevmap.c b/src/vdevmap.c
new file mode 100644 (file)
index 0000000..5b70b51
--- /dev/null
@@ -0,0 +1,136 @@
+// $Id: vdevmap.c 2490 2007-02-05 20:45:25Z dhozac $    --*- c -*--
+
+// Copyright (C) 2006 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.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "util.h"
+#include <lib/internal.h>
+
+#include <vserver.h>
+
+#include <getopt.h>
+#include <errno.h>
+
+#define ENSC_WRAPPERS_PREFIX   "vdevmap: "
+#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  =  1;
+
+struct option const
+CMDLINE_OPTIONS[] = {
+  { "help",       no_argument,       0, CMD_HELP },
+  { "version",    no_argument,       0, CMD_VERSION },
+  { "xid",        required_argument, 0, 'x' },
+  { "open",       no_argument,       0, 'o' },
+  { "create",     no_argument,       0, 'c' },
+  { "remap",      no_argument,       0, 'r' },
+  { "flags",      required_argument, 0, 'f' },
+  { "device",     required_argument, 0, 'd' },
+  { "target",     required_argument, 0, 't' },
+  {0,0,0,0}
+};
+
+static void
+showHelp(int fd, char const *cmd)
+{
+  WRITE_MSG(fd, "Usage: ");
+  WRITE_STR(fd, cmd);
+  WRITE_MSG(fd,
+           " --xid <xid> [--flags <flags>] [--open] [--create] [--remap] [--device <dev>] [--target <dev>]\n"
+           "\n"
+           "Please report bugs to " PACKAGE_BUGREPORT "\n");
+
+  exit(0);
+}
+
+static void
+showVersion()
+{
+  WRITE_MSG(1,
+           "vdevmap " VERSION " -- manages device mappings\n"
+           "This program is part of " PACKAGE_STRING "\n\n"
+           "Copyright (C) 2006 Daniel Hokka Zakrisson\n"
+           VERSION_COPYRIGHT_DISCLAIMER);
+  exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+  xid_t                xid             = VC_NOCTX;
+  bool         allow_open      = false;
+  bool         allow_create    = false;
+  bool         do_remap        = false;
+  uint32_t     flags           = 0;
+  char         *device         = NULL;
+  char         *target         = NULL;
+  unsigned long        tmp             = 0;
+  
+  while (1) {
+    int                c = getopt_long(argc, argv, "+x:ocrf:d:t:", CMDLINE_OPTIONS, 0);
+    if (c==-1) break;
+
+    switch (c) {
+      case CMD_HELP    :  showHelp(1, argv[0]);
+      case CMD_VERSION :  showVersion();
+      case 'x'         :  xid = Evc_xidopt2xid(optarg, true);  break;
+      case 'o'         :  allow_open = true;                   break;
+      case 'c'         :  allow_create = true;                 break;
+      case 'r'         :  do_remap = true;                     break;
+      case 'd'         :  device = optarg;                     break;
+      case 't'         :  target = optarg;                     break;
+      case 'f'         :
+       if (!isNumberUnsigned(optarg, &tmp, false)) {
+         WRITE_MSG(2, "Invalid flags argument: '");
+         WRITE_STR(2, optarg);
+         WRITE_MSG(2, "'; try '--help' for more information\n");
+         return EXIT_FAILURE;
+       }
+       flags |= (uint32_t) tmp;
+       break;
+
+      default          :
+       WRITE_MSG(2, "Try '");
+       WRITE_STR(2, argv[0]);
+       WRITE_MSG(2, " --help' for more information.\n");
+       return EXIT_FAILURE;
+       break;
+    }
+  }
+
+  if (allow_open)      flags |= VC_DATTR_OPEN;
+  if (allow_create)    flags |= VC_DATTR_CREATE;
+  if (do_remap)                flags |= VC_DATTR_REMAP;
+
+  if (xid==VC_NOCTX)
+    WRITE_MSG(2, "No xid specified; try '--help' for more information\n");
+  else if (optind!=argc)
+    WRITE_MSG(2, "Unused argument(s); try '--help' for more information\n");
+  else if (vc_set_mapping(xid, device, target, flags)==-1)
+      perror("vc_set_mapping()");
+  else
+    return EXIT_SUCCESS;
+
+  return EXIT_FAILURE;
+}
diff --git a/src/vsysctl.c b/src/vsysctl.c
new file mode 100644 (file)
index 0000000..0613e88
--- /dev/null
@@ -0,0 +1,181 @@
+// $Id: vsysctl.c 2466 2007-01-21 08:02:44Z dhozac $    --*- c -*--
+
+// Copyright (C) 2007 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.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "util.h"
+#include <lib/internal.h>
+
+#include <vserver.h>
+
+#include <stdio.h>
+#include <getopt.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <dirent.h>
+
+#define ENSC_WRAPPERS_PREFIX   "vsysctl: "
+#define ENSC_WRAPPERS_UNISTD   1
+#define ENSC_WRAPPERS_FCNTL    1
+#define ENSC_WRAPPERS_DIRENT   1
+#define ENSC_WRAPPERS_VSERVER  1
+#define ENSC_WRAPPERS_IO       1
+#include <wrappers.h>
+
+
+#define PROC_SYS_DIRECTORY     "/proc/sys"
+
+
+#define CMD_HELP               0x1000
+#define CMD_VERSION            0x1001
+#define CMD_XID                        0x4000
+#define CMD_DIR                        0x4001
+#define CMD_MISSINGOK          0x4002
+
+int            wrapper_exit_code  =  1;
+
+struct option const
+CMDLINE_OPTIONS[] = {
+  { "help",       no_argument,       0, CMD_HELP },
+  { "version",    no_argument,       0, CMD_VERSION },
+  { "xid",        required_argument, 0, CMD_XID },
+  { "dir",        required_argument, 0, CMD_DIR },
+  { "missingok",  no_argument,       0, CMD_MISSINGOK },
+  {0,0,0,0}
+};
+
+static void
+showHelp(int fd, char const *cmd)
+{
+  WRITE_MSG(fd, "Usage: ");
+  WRITE_STR(fd, cmd);
+  WRITE_MSG(fd,
+           " --xid <xid> --dir <directory> [--missingok] -- <command> <args>*\n"
+           "\n"
+           "Please report bugs to " PACKAGE_BUGREPORT "\n");
+
+  exit(0);
+}
+
+static void
+showVersion()
+{
+  WRITE_MSG(1,
+           "vsysctl " VERSION " -- sets sysctl values during guest boot\n"
+           "This program is part of " PACKAGE_STRING "\n\n"
+           "Copyright (C) 2007 Daniel Hokka Zakrisson\n"
+           VERSION_COPYRIGHT_DISCLAIMER);
+  exit(0);
+}
+
+void handle_setting(const char *dir, const char *name)
+{
+  int  len_dir = strlen(dir), len_name = strlen(name);
+  char filename[len_dir+1+len_name+sizeof("/setting")];
+  char setting[128], value[128], *ptr;
+  int  fd;
+  size_t setting_len, value_len;
+
+  strcpy(filename, dir);
+  *(filename+len_dir) = '/';
+  strcpy(filename+len_dir+1, name);
+
+#define READFILE(f) \
+  strcpy(filename+len_dir+1+len_name, "/" #f); \
+  fd = EopenD(filename, O_RDONLY, 0); \
+  f##_len = Eread(fd, f, sizeof(f)); \
+  if (f##_len == sizeof(f)) { \
+    errno = EOVERFLOW; \
+    perror(ENSC_WRAPPERS_PREFIX "read"); \
+    exit(EXIT_FAILURE); \
+  } \
+  f[f##_len] = '\0'; \
+  Eclose(fd);
+
+  READFILE(setting);
+  READFILE(value);
+
+  /* replace all . with / in setting to get a filename */
+  for (ptr = strchr(setting, '.'); ptr; ptr = strchr(ptr, '.'))
+    *ptr = '/';
+
+  /* we just want the first line, and not the linefeed */
+  if ((ptr = strchr(setting, '\n')) != NULL)
+    *ptr = '\0';
+
+  fd = EopenD(setting, O_WRONLY, 0);
+  EwriteAll(fd, value, value_len);
+  Eclose(fd);
+}
+
+int main(int argc, char *argv[])
+{
+  xid_t                xid     = VC_NOCTX;
+  const char   *dir    = NULL;
+  bool         missing = false;
+  
+  while (1) {
+    int                c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
+    if (c==-1) break;
+
+    switch (c) {
+      case CMD_HELP    :  showHelp(1, argv[0]);
+      case CMD_VERSION :  showVersion();
+      case CMD_XID     :  xid = Evc_xidopt2xid(optarg, true);  break;
+      case CMD_DIR     :  dir = optarg;                        break;
+      case CMD_MISSINGOK:  missing = true;                     break;
+
+      default          :
+       WRITE_MSG(2, "Try '");
+       WRITE_STR(2, argv[0]);
+       WRITE_MSG(2, " --help' for more information.\n");
+       return EXIT_FAILURE;
+       break;
+    }
+  }
+
+  if (dir != NULL) {
+    int                  curdir = EopenD(".", O_RDONLY, 0);
+    DIR                  *dp;
+    struct dirent *de;
+
+    Echdir(PROC_SYS_DIRECTORY);
+
+    dp = opendir(dir);
+    if (dp != NULL) {
+      while ((de = Ereaddir(dp)) != NULL) {
+       if (*de->d_name == '.')
+         continue;
+       handle_setting(dir, de->d_name);
+      }
+      Eclosedir(dp);
+    }
+    else if (!missing) {
+      perror(ENSC_WRAPPERS_PREFIX "opendir");
+      exit(wrapper_exit_code);
+    }
+
+    Efchdir(curdir);
+  }
+
+  Eexecvp(argv[optind], argv+optind);
+  return EXIT_FAILURE;
+}
diff --git a/sysv/util-vserver b/sysv/util-vserver
new file mode 100755 (executable)
index 0000000..fe0be29
--- /dev/null
@@ -0,0 +1,109 @@
+#!/bin/bash
+#
+# util-vserver  sets the path to vshelper and kills all guest processes
+#
+# chkconfig: 2345 10 90
+# description: Sets the path to vshelper and kills all guest processes
+
+: ${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"
+
+LOCKFILE=util-vserver
+. "$_LIB_VSERVER_INIT_FUNCTIONS"
+. "$_LIB_FUNCTIONS"
+. "$__PKGLIBDIR/vserver.functions"
+
+
+function set_helper()
+{
+    local f="/proc/sys/kernel/vshelper"
+    if test -e "$f"; then
+       echo "$_VSHELPER" > "$f"
+       return 0
+    else
+       return 2
+    fi
+}
+
+function kill_contexts()
+{
+    local xid
+    for xid in `ls -1 /proc/virtual`; do
+       test "$xid" = "info" -o "$xid" = "status" && continue
+       $_VATTRIBUTE --xid $xid --set --flag ~persistent
+       $_VKILL --xid $xid -s 15
+       sleep 3
+       $_VKILL --xid $xid -s 9
+    done
+    local alive=0
+    for xid in `ls -1 /proc/virtual`; do
+       test "$xid" = "info" -o "$xid" = "status" && continue
+       let alive+=1
+    done
+    test $alive = 0
+}
+
+function create_dirs()
+{
+    $_MKDIR -p "$__RUNDIR" && $_MKDIR -p "$__VSHELPERSTATEDIR" && $_MKDIR -p `getPhysicalDir "$__PKGSTATEREVDIR"`
+}
+
+function start()
+{
+    _beginResult $"Creating required directories"
+    create_dirs
+    _endResult $?
+    _beginResult $"Setting path to vshelper"
+    set_helper
+    _endResult $?
+    local retval=$?
+    _beginResult $"Loading default device map"
+    loadDeviceMap 0 "$__CONFDIR/.defaults/apps/vdevmap"
+    _endResult $?
+    test "$retval" -ne 0 || touch "$lockfile"
+    return $retval
+}
+
+function stop()
+{
+    # Stop all running, but non-default guests"
+    _beginResult $"Stopping all running guests"
+    $_START_VSERVERS -j 1 --all --stop
+    _endResult $?
+    _beginResult $"Killing all running contexts"
+    kill_contexts
+    _endResult $?
+    local retval=$?
+    $_RM -f "$lockfile"
+    return $retval
+}
+
+function restart()
+{
+    stop
+    start
+}
+
+case "$1" in
+    start|stop|restart)        $1;;
+    reload)            ;;
+    condrestart)
+       test -f $lockfile && restart || :
+       ;;
+    status)
+       test -f $lockfile && {
+           echo $"Path to vshelper has been set"
+           exit 0
+       }
+       echo $"Path to vshelper has not been set"
+       exit 1
+       ;;
+    *)
+        echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
+       exit 2
+       ;;
+esac
index 17a2cd4..285c1fb 100755 (executable)
@@ -14,36 +14,23 @@ test -e "$UTIL_VSERVER_VARS" || {
 
 $_VSERVER_INFO - FEATURE iattr || exit 0
 
-f=/etc/rc.d/init.d/functions
-if test -e "$f"; then
-    . "$f"
-    lockfile=/var/lock/subsys/vprocunhide
-else
-    success() { echo .; }
-    passed()  { echo .; }
-    failure() { echo ERROR; }
-    lockfile=/var/run/vprocunhide
-fi
+LOCKFILE=vprocunhide
+. "$_LIB_VSERVER_INIT_FUNCTIONS"
 
 
 function start()
 {
-    echo -n $"Fixing /proc entries visibility..."
+    _beginResult $"Fixing /proc entries visibility"
     $_VPROCUNHIDE
-    retval=$?
-    case "$retval" in
-       0)      success;;
-       2)      passed; retval=0;;
-       *)      failure;
-    esac
-    echo
+    _endResult $?
+    local retval=$?
     test "$retval" -ne 0 || touch "$lockfile"
     return $retval
 }
 
 function stop()
 {
-    rm -f "$lockfile"
+    $_RM -f "$lockfile"
 }
 
 function restart()
index 6e41071..9de2572 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# chkconfig: 345 98 02
+# chkconfig: - 98 02
 # description: The vservers service is used to start and stop all
 #              the virtual servers.