linuxcaps.h: ${kernelincludedir}/linux/capability.h Makefile
@rm -f $@
echo '#include <stdint.h>' >$@.tmp
- sed -e 's!^#include .*!!g;s!\<__u32\>!uint32_t!g' $< >>$@.tmp
+ sed -e 's!^#include .*!!g;s!\<__u32\>!uint32_t!g;s!\<__user\>!!g;' $< >>$@.tmp
@-chmod --reference $< $@.tmp &>/dev/null
mv -f $@.tmp $@
@chmod a-w $@
who wrote and maintains the 'vserver' package on which util-vserver
is based on
+Sam Vilain,
+ for providing man-pages and patches used in the Debian package
+
+
all the other people, who contributed to the original 'vserver' package
dnl
AC_PREREQ(2.57)
-AC_INIT(util-vserver, 0.24.191, enrico.scholz@informatik.tu-chemnitz.de)
+AC_INIT(util-vserver, 0.25.190, enrico.scholz@informatik.tu-chemnitz.de)
AC_CONFIG_SRCDIR([src/capchroot.c])
AC_CONFIG_HEADER([config.h])
[],
[supported_apis=ALL])
-test x"$supported_apis" != xALL || supported_apis='legacy,compat'
+test x"$supported_apis" != xALL || supported_apis='legacy,compat,v11'
old_IFS=$IFS
IFS=,;
for i in $supported_apis; do
case "$i" in
compat) AC_DEFINE(VC_ENABLE_API_COMPAT, 1, [Enable support for compatibily syscall API]);;
legacy) AC_DEFINE(VC_ENABLE_API_LEGACY, 1, [Enable support for old, /proc parsing API]);;
+ v11) AC_DEFINE(VC_ENABLE_API_V11, 1, [Enable support for API of vserver 1.1.x]);;
*) AC_MSG_ERROR(['$i' is not a supported API]);;
esac
done
IFS=$old_IFS
AC_MSG_RESULT([$supported_apis])
+AC_CHECK_HEADERS([ext2fs/ext2fs.h], [],
+ [AC_CHECK_HEADERS([linux/ext2_fs.h], [],
+ [AC_MSG_ERROR([Sorry, do not know, how to include 'ext2fs.h'])])])
+
AC_CHECK_FUNCS([sys_virtual_context])
AC_CHECK_DECLS(MS_MOVE,,,[#include <linux/fs.h>])
AC_CHECK_TYPES(ctx_t,,,[#include <sys/types.h>])
lib_management_SRCS = lib/getvservername.c \
lib/getvservercfgstyle.c \
lib/getvservervdir.c
+lib_v11_SRCS = lib/syscall_rlimit.c
PKGCONFIG_FILES = lib/util-vserver
lib/int2str.c \
lib/capabilities.c \
$(lib_legacy_SRCS) \
- $(lib_management_SRCS)
+ $(lib_management_SRCS) \
+ $(lib_v11_SRCS)
lib_HDRS = lib/vserver.h
lib_XHDRS = lib/syscall-compat.hc \
lib/syscall-legacy.hc \
+ lib/syscall_rlimit-v11.hc \
lib/getctx-compat.hc \
lib/getctx-legacy.hc \
lib/getinitpid-compat.hc \
msg.remove_cap = remove_cap;
msg.flags = flags;
- return sys_virtual_context(VC_CMD(COMPAT, 1, 1), ctx, &msg);
+ return sys_virtual_context(VC_CMD(COMPAT, 1, 1), CTX_USER2KERNEL(ctx), &msg);
}
static inline ALWAYSINLINE int
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// 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.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define KERN2USR(LIMIT) \
+ (((LIMIT)==CRLIM_INFINITY) ? VC_LIM_INFINITY : \
+ ((LIMIT)==CRLIM_KEEP) ? VC_LIM_KEEP : (LIMIT))
+
+#define USR2KERN(LIMIT) \
+ (((LIMIT)==VC_LIM_INFINITY) ? CRLIM_INFINITY : \
+ ((LIMIT)==VC_LIM_KEEP) ? CRLIM_KEEP : (LIMIT))
+
+static inline ALWAYSINLINE int
+vc_get_rlimit_v11(ctx_t ctx, int resource, struct vc_rlimit *lim)
+{
+ struct vcmd_ctx_rlimit_v0 vc_lim;
+ int rc;
+
+ vc_lim.id = resource;
+ rc = sys_virtual_context(VC_CMD(RLIMIT, 1, 0), CTX_USER2KERNEL(ctx), &vc_lim);
+ lim->min = KERN2USR(vc_lim.minimum);
+ lim->soft = KERN2USR(vc_lim.softlimit);
+ lim->hard = KERN2USR(vc_lim.maximum);
+
+ return rc;
+}
+
+static inline ALWAYSINLINE int
+vc_set_rlimit_v11(ctx_t ctx, int resource, struct vc_rlimit const *lim)
+{
+ struct vcmd_ctx_rlimit_v0 vc_lim;
+
+ vc_lim.id = resource;
+ vc_lim.minimum = USR2KERN(lim->min);
+ vc_lim.softlimit = USR2KERN(lim->soft);
+ vc_lim.maximum = USR2KERN(lim->hard);
+
+ return sys_virtual_context(VC_CMD(RLIMIT, 2, 0), CTX_USER2KERNEL(ctx), &vc_lim);
+}
+
+static inline ALWAYSINLINE int
+vc_get_rlimit_mask_v11(ctx_t ctx, int UNUSED tmp, struct vc_rlimit_mask *lim)
+{
+ struct vcmd_ctx_rlimit_v0 vc_lim;
+ int rc;
+
+ rc = sys_virtual_context(VC_CMD(RLIMIT, 3, 0), CTX_USER2KERNEL(ctx), &vc_lim);
+
+ lim->min = vc_lim.minimum;
+ lim->soft = vc_lim.softlimit;
+ lim->hard = vc_lim.maximum;
+
+ return rc;
+}
+
+#undef KERN2USR
+#undef USR2KERN
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// 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.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include "internal.h"
+#include "linuxvirtual.h"
+
+#ifdef VC_ENABLE_API_V11
+# include "syscall_rlimit-v11.hc"
+#endif
+
+#if defined (VC_ENABLE_API_V11)
+
+int
+vc_get_rlimit(ctx_t ctx, int resource, struct vc_rlimit *lim)
+{
+ CALL_VC(CALL_VC_V11(vc_get_rlimit, ctx, resource, lim));
+}
+
+int
+vc_set_rlimit(ctx_t ctx, int resource, struct vc_rlimit const *lim)
+{
+ CALL_VC(CALL_VC_V11(vc_set_rlimit, ctx, resource, lim));
+}
+
+int
+vc_get_rlimit_mask(ctx_t ctx, struct vc_rlimit_mask *lim)
+{
+ CALL_VC(CALL_VC_V11(vc_get_rlimit_mask, ctx, 0, lim));
+}
+
+
+#endif
#define _LINUX_VIRTUAL_H
#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
-#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
+#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
#define VC_VERSION(c) ((c) & 0xFFF)
-#define VC_CMD(c,i,v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
- | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
+#define VC_CMD(c,i,v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
+ | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
+
+/*
+
+ Syscall Matrix V2.2
+
+ |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
+ |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
+ |INFO |SETUP | |MOVE | | | | | |
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+ SYSTEM |VERSION| | | | | | |DEVICES| |
+ HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+ CPU | | | | | | | |SCHED. | |
+ PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+ MEMORY | | | | | | | |SWAP | |
+ | 16| 17| 18| 19| 20| 21| | 22| 23|
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+ NETWORK| | | | | | | |SERIAL | |
+ | 24| 25| 26| 27| 28| 29| | 30| 31|
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+ DISK | | | | | | | | | |
+ VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+ OTHER | | | | | | | | | |
+ | 40| 41| 42| 43| 44| 45| | 46| 47|
+ =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
+ SPECIAL| | | | | | | | | |
+ | 48| 49| 50| 51| 52| 53| | 54| 55|
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+ SPECIAL| | | | |RLIMIT |SYSCALL| | |COMPAT |
+ | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
+ -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
+
+*/
#define VC_CAT_VERSION 0
-#define VC_CAT_PROCESS 1
-#define VC_CAT_MEMORY 2
-#define VC_CAT_NETWORK 3
+
+#define VC_CAT_RLIMIT 60
-#define VC_CAT_LIMITS 8
-#define VC_CAT_QUOTA 9
-
-#define VC_CAT_OTHER 62
+#define VC_CAT_SYSTEST 61
#define VC_CAT_COMPAT 63
-
+
/* interface version */
- //#define VC_VERSION 0x00010000
+#define VCI_VERSION 0x00010001
/* query version */
-#define VCMD_get_version VC_CMD(VERSION, 0, 0)
+#define VCMD_get_version VC_CMD(VERSION, 0, 0)
/* compatibiliy vserver commands */
-#define VCMD_new_s_context VC_CMD(COMPAT, 1, 1)
+#define VCMD_new_s_context VC_CMD(COMPAT, 1, 1)
#define VCMD_set_ipv4root VC_CMD(COMPAT, 2, 3)
/* compatibiliy vserver arguments */
struct vcmd_new_s_context_v1 {
- uint32_t remove_cap;
+ uint32_t remove_cap;
uint32_t flags;
};
#define NB_IPV4ROOT 16
struct vcmd_set_ipv4root_v3 {
- /* number of pairs in id */
- uint32_t broadcast;
+ /* number of pairs in id */
+ uint32_t broadcast;
struct {
uint32_t ip;
uint32_t mask;
};
+/* rlimit vserver commands */
+
+#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
+#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
+#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
+
+struct vcmd_ctx_rlimit_v0 {
+ uint32_t id;
+ uint64_t minimum;
+ uint64_t softlimit;
+ uint64_t maximum;
+};
+
+struct vcmd_ctx_rlimit_mask_v0 {
+ uint32_t minimum;
+ uint32_t softlimit;
+ uint32_t maximum;
+};
+
+#define CRLIM_INFINITY (~0ULL)
+#define CRLIM_KEEP (~1ULL)
+
+
#endif /* _LINUX_VIRTUAL_H */
# define CALL_VC_LEGACY(F,...) CALL_VC_NOOP
#endif
+#ifdef VC_ENABLE_API_V11
+# define CALL_VC_V11(F,...) CALL_VC_GENERAL(0x00010000, v11, F, __VA_ARGS__)
+#else
+# define CALL_VC_V11(F,...) CALL_VC_NOOP
+#endif
+
+
+#if 1
+# define CTX_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NOCTX : \
+ ((X)==(uint32_t)(-2)) ? VC_SAMECTX : \
+ (ctx_t)(X))
+
+# define CTX_USER2KERNEL(X) (((X)==VC_RANDCTX) ? (uint32_t)(-1) : \
+ ((X)==VC_SAMECTX) ? (uint32_t)(-2) : \
+ (uint32_t)(X))
+#else
+# define CTX_USER2KERNEL(X) (X)
+# define CTX_KERNEL2USER(X) (X)
+#endif
+
+
#ifndef HAVE_SYS_VIRTUAL_CONTEXT
static UNUSED
_syscall3(int, sys_virtual_context,
-// $Id$
-
-// 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.
+/* $Id$
+
+* 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.
+*/
#ifndef H_VSERVER_SYSCALL_H
#define H_VSERVER_SYSCALL_H
#include <stdlib.h>
#include <sys/types.h>
-#ifndef VC_NOCTX
-# define VC_NOCTX ((ctx_t)(-1))
-#endif
+/** the value which is returned in error-case (no ctx found) */
+#define VC_NOCTX ((ctx_t)(-1))
+/** the value which means a random (the next free) ctx */
+#define VC_RANDCTX ((ctx_t)(-1))
+/** the value which means the current ctx */
+#define VC_SAMECTX ((ctx_t)(-2))
+
+#define VC_LIM_INFINITY (~0ULL)
+#define VC_LIM_KEEP (~1ULL)
+
#ifndef S_CTX_INFO_LOCK
# define S_CTX_INFO_LOCK 1
#endif
int vc_chrootsafe(char const *dir);
+ /* rlimit related functions */
+ typedef uint64_t vc_limit_t;
+
+
+ struct vc_rlimit {
+ vc_limit_t min;
+ vc_limit_t soft;
+ vc_limit_t hard;
+ };
+
+ struct vc_rlimit_mask {
+ uint32_t min;
+ uint32_t soft;
+ uint32_t hard;
+ };
+
+ int vc_get_rlimit(ctx_t ctx, int resource, struct vc_rlimit *lim);
+ int vc_set_rlimit(ctx_t ctx, int resource, struct vc_rlimit const *lim);
+ int vc_get_rlimit_mask(ctx_t ctx, struct vc_rlimit_mask *lim);
+
/** Returns the context of the given process. pid==0 means the current process. */
ctx_t vc_X_getctx(pid_t pid);
char const * vc_cap2text(int);
- // The management part
+ /* The management part */
#define VC_LIMIT_VSERVER_NAME_LEN 1024
vcCfgStyle vc_getVserverCfgStyle(char const *id);
- // Resolves the name of the vserver. The result will be allocated and must
- // be freed by the caller
+ /** Resolves the name of the vserver. The result will be allocated and must
+ be freed by the caller. */
char * vc_getVserverName(char const *id, vcCfgStyle style);
char * vc_getVserverVdir(char const *id, vcCfgStyle style);
USR_SBIN=$SBINDIR
USR_LIB_VSERVER=$PKGLIBDIR
-
VSERVERKILLALL_CMD=$USR_LIB_VSERVER/vserverkillall
DEFAULTPATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
+
vserver_mknod(){
mknod $1 $2 $3 $4
chmod $5 $1
rm -f `find var/run -type f`
touch var/run/utmp
+ chgrp ${UTMP_GROUP:-utmp} var/run/utmp
+ chmod 0664 var/run/utmp
rm -f var/lock/subsys/*
mountproc $DEFAULT_VSERVERDIR/$1
CTXOPT=
STARTCMD="/etc/rc.d/rc $INITDEFAULT"
if [ -x $DEFAULT_VSERVERDIR/$1/etc/init.d/rc ] ; then
STARTCMD="/etc/init.d/rc $INITDEFAULT"
- fi
+ elif [ -x $DEFAULT_VSERVERDIR/$1/usr/bin/emerge ] ; then
+ STARTCMD="/sbin/rc default"
+ fi
DISCONNECT=
FAKEINIT=
STOPCMD="/etc/rc.d/rc 6"
if [ -x $DEFAULT_VSERVERDIR/$1/etc/init.d/rc ] ; then
STOPCMD="/etc/init.d/rc 6"
- fi
+ elif [ -x $DEFAULT_VSERVERDIR/$1/usr/bin/emerge ] ; then
+ STOPCMD="/sbin/rc shutdown"
+ fi
+
for f in $S_FLAGS dummy
do
case $f in
vcheck
vdu
vfiles
+vlimit
vreboot
vserver-stat
vunify
src/chcontext \
src/rebootmgr \
src/reducecap \
+ src/vlimit \
src/vdu \
src/vfiles \
src/vserver-stat
src/fakerunlevel \
src/pipe-sync \
src/exec-ulimit \
+ src/vlimit \
src/ctx-kill
src_HDRS = src/vutil.h src/vutil.p src/util.h \
src/wrappers.h src/wrappers-vserver.h \
+ src/ext2fs.h \
src/compat-pivot_root.h \
src/stack-start.h \
src/vserver.hh
src/reducecap \
src/vdu \
src/new-namespace \
+ src/vlimit \
src/vserver-stat \
$(src_sbin_CXX_PROGS)
src_reducecap_SOURCES = src/reducecap.c
src_reducecap_LDADD = lib/libvserver.a
+src_vlimit_SOURCES = src/vlimit.c
+src_vlimit_LDADD = lib/libvserver.a
+
src_save_ctxinfo_SOURCES = src/save_ctxinfo.c
src_save_ctxinfo_LDADD = lib/libvserver.a
--- /dev/null
+// $Id$ --*- c -*--
+
+// 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.
+
+
+#ifndef H_UTIL_VSERVER_SRC_EXT2FS_H
+#define H_UTIL_VSERVER_SRC_EXT2FS_H
+
+#ifdef HAVE_EXT2FS_EXT2FS_H
+# include <ext2fs/ext2fs.h>
+#elif defined(HAVE_LINUX_EXT2_FS_H)
+# include <linux/ext2_fs.h>
+#else
+# error Do not know how to include <ext2_fs.h>
+#endif
+
+#endif // H_UTIL_VSERVER_SRC_EXT2FS_H
+++ /dev/null
-// $Id$
-
-// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
-// based on setctxlimit.cc by Jacques Gelinas
-//
-// 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.
-
-/*
- Set the global per context limit of a resource (memory, file handle).
- This utility can do it either for the current context or a selected
- one.
-
- It uses the same options as ulimit, when possible
-*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "compat.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/resource.h>
-
-#include "vserver.h"
-
-static void set_ctxlim (int res, long lim, const char *msg)
-{
- if (call_set_ctxlimit(res,lim)==-1){
- fprintf (stderr,"Error setting limit \"%s\": %s\n"
- ,msg,strerror(errno));
- exit (-1);
- }
-}
-
-static void usage()
-{
- fprintf (stderr,"setctxlimit version %s\n",VERSION);
- fprintf (stderr
- ,"setctxlimit [ --ctx context ] limits\n"
- "\n"
- "-n nax opened files\n");
-}
-
-int main (int argc, char *argv[])
-{
- int ret = -1;
- if (argc < 2){
- usage();
- }else{
- int i;
- ret = 0;
- for (i=1; i<argc; i++){
- const char *arg = argv[i];
- const char *narg = argv[i+1];
- int val;
-
- if (narg == NULL) narg = "";
- val = atoi(narg);
- if (strcmp(arg,"--help")==0){
- usage();
- }else if (strcmp(arg,"--ctx")==0){
- int tb[1];
-
- tb[0] = val;
- if (call_new_s_context (1,tb,0,0)==-1){
- fprintf (stderr,"Can't select context %d (%s)\n"
- ,val,strerror(errno));
- exit (-1);
- }
- }else if (strcmp (arg,"-n")==0){
- set_ctxlim (RLIMIT_NOFILE,val,"Number of opened files");
- }
- }
- }
- return ret;
-}
-
// 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 "compat.h"
+
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <linux/ext2_fs.h>
+
+#include "ext2fs.h"
+
// Patch to help compile this utility on unpatched kernel source
#ifndef EXT2_IMMUTABLE_FILE_FL
--- /dev/null
+// $Id$
+
+// 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.
+
+/*
+ Set the global per context limit of a resource (memory, file handle).
+ This utility can do it either for the current context or a selected
+ one.
+
+ It uses the same options as ulimit, when possible
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include "vserver.h"
+#include "internal.h"
+
+#include <getopt.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define VERSION_COPYRIGHT_DISCLAIMER
+
+inline static void UNUSED
+writeStr(int fd, char const *cmd)
+{
+ (void)write(fd, cmd, strlen(cmd));
+}
+
+#define WRITE_MSG(FD,X) (void)(write(FD,X,sizeof(X)-1))
+#define WRITE_STR(FD,X) writeStr(FD,X)
+
+#define NUMLIM(X) \
+{ #X, required_argument, 0, 2048|X }
+
+static struct option const
+CMDLINE_OPTIONS[] = {
+ { "help", no_argument, 0, 'h' },
+ { "version", no_argument, 0, 'v' },
+ { "all", no_argument, 0, 'a' },
+ NUMLIM( 0), NUMLIM( 1), NUMLIM( 2), NUMLIM( 3),
+ NUMLIM( 4), NUMLIM( 5), NUMLIM( 6), NUMLIM( 7),
+ NUMLIM( 8), NUMLIM( 9), NUMLIM(10), NUMLIM(11),
+ NUMLIM(12), NUMLIM(13), NUMLIM(14), NUMLIM(15),
+ NUMLIM(16), NUMLIM(17), NUMLIM(18), NUMLIM(19),
+ NUMLIM(20), NUMLIM(21), NUMLIM(22), NUMLIM(23),
+ NUMLIM(24), NUMLIM(25), NUMLIM(26), NUMLIM(27),
+ NUMLIM(28), NUMLIM(29), NUMLIM(30), NUMLIM(31),
+ { 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,
+ " [-c|--ctx <ctx>] [-a|--all] [-MSH --<nr> <value>]*\n"
+ "Please report bugs to " PACKAGE_BUGREPORT "\n");
+ exit(res);
+}
+
+static void
+showVersion()
+{
+ WRITE_MSG(1,
+ "vlimit " VERSION " -- limits context-resources\n"
+ "This program is part of " PACKAGE_STRING "\n\n"
+ "Copyright (C) 2003 Enrico Scholz\n"
+ VERSION_COPYRIGHT_DISCLAIMER);
+ exit(0);
+}
+
+static void *
+appendLimit(char *ptr, bool do_it, vc_limit_t lim)
+{
+ memcpy(ptr, " ", 2);
+ ptr += 2;
+ if (do_it) {
+ if (lim==VC_LIM_INFINITY) {
+ strcpy(ptr, "INF");
+ ptr += 3;
+ }
+ else {
+ memcpy(ptr, "0x", 2);
+ ptr += 2;
+
+ ptr += utilvserver_uint2str(ptr, 20, (lim>>32), 16);
+ ptr += utilvserver_uint2str(ptr, 20, lim&0xffffffff, 16);
+ *ptr = ' ';
+ }
+ }
+ else {
+ memcpy(ptr, "N/A", 3);
+ ptr += 3;
+ }
+
+ return ptr;
+}
+
+static void
+showAll(int ctx)
+{
+ struct vc_rlimit_mask mask;
+ size_t i;
+
+ if (vc_get_rlimit_mask(-2, &mask)==-1) {
+ perror("vc_get_rlimit_mask()");
+ //exit(1);
+ }
+
+ for (i=0; i<32; ++i) {
+ uint32_t bitmask = (1<<i);
+ struct vc_rlimit limit;
+ char buf[100], *ptr=buf;
+
+ if (vc_get_rlimit(ctx, i, &limit)==-1) {
+ perror("vc_get_rlimit()");
+ //continue;
+ }
+
+ memset(buf, ' ', sizeof buf);
+ ptr += utilvserver_uint2str(ptr, 100, i, 10);
+ *ptr = ' ';
+
+ ptr = appendLimit(buf+10, mask.min &bitmask, limit.min);
+ ptr = appendLimit(buf+30, mask.soft&bitmask, limit.soft);
+ ptr = appendLimit(buf+50, mask.hard&bitmask, limit.hard);
+
+ *ptr++ = '\n';
+ write(1, buf, ptr-buf);
+ }
+}
+
+static void
+setLimits(int ctx, struct vc_rlimit const limits[], uint32_t mask)
+{
+ size_t i;
+ for (i=0; i<32; ++i) {
+ if ((mask & (1<<i))==0) continue;
+ if (vc_set_rlimit(ctx, i, limits+i)) {
+ perror("vc_set_rlimit()");
+ }
+ }
+}
+
+int main (int argc, char *argv[])
+{
+ // overall used limits
+ uint32_t lim_mask = 0;
+ int set_mask = 0;
+ struct vc_rlimit limits[32];
+ bool show_all = false;
+ ctx_t ctx = VC_SAMECTX;
+
+ {
+ size_t i;
+ for (i=0; i<32; ++i) {
+ limits[i].min = VC_LIM_KEEP;
+ limits[i].soft = VC_LIM_KEEP;
+ limits[i].hard = VC_LIM_KEEP;
+ }
+ }
+
+ while (1) {
+ int c = getopt_long(argc, argv, "MSHhvac:", CMDLINE_OPTIONS, 0);
+ if (c==-1) break;
+
+ if (2048<=c && c<2048+32) {
+ int id = c-2048;
+ vc_limit_t val;
+
+ if (strcmp(optarg, "inf")==0) val = VC_LIM_INFINITY;
+ else val = atoll(optarg);
+
+ if (set_mask & 1) limits[id].min = val;
+ if (set_mask & 2) limits[id].soft = val;
+ if (set_mask & 4) limits[id].soft = val;
+
+ lim_mask |= (1<<id);
+ set_mask = 0;
+ }
+ else switch (c) {
+ case 'h' : showHelp(1, argv[0], 0);
+ case 'v' : showVersion();
+ case 'c' : ctx = atoi(optarg); break;
+ case 'a' : show_all = true; break;
+ case 'M' :
+ case 'S' :
+ case 'H' :
+ switch (c) {
+ case 'M' : set_mask |= 1; break;
+ case 'S' : set_mask |= 2; break;
+ case 'H' : set_mask |= 4; break;
+ default : assert(false);
+ }
+ break;
+
+ default :
+ WRITE_MSG(2, "Try '");
+ WRITE_STR(2, argv[0]);
+ WRITE_MSG(2, " --help\" for more information.\n");
+ return EXIT_FAILURE;
+ break;
+ }
+ }
+
+ setLimits(ctx, limits, lim_mask);
+ if (show_all) showAll(ctx);
+
+ return EXIT_SUCCESS;
+}
#include <utime.h>
#include "vutil.h"
#include <sys/ioctl.h>
-#include <linux/ext2_fs.h>
+#include "ext2fs.h"
#include <pathconfig.h>
Obsoletes: vserver < %epoch:%version
BuildRequires: mount vconfig gawk iproute
BuildRequires: gcc-c++
-%{!?_without_dietlibc:BuildRequires: dietlibc}
+BuildRequires: e2fsprogs-devel
+%{!?_without_dietlibc:BuildRequires: dietlibc >= 0:0.22}
%package core
Summary: The core-utilities for util-vserver