From: Enrico Scholz Date: Tue, 18 Nov 2003 23:46:42 +0000 (+0000) Subject: merged/added from 0.25 X-Git-Tag: VERSION_0_10~1075 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bac3099d94faabc10f8916475bcfd38eb7acc49;p=util-vserver.git merged/added from 0.25 git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@410 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/Makefile.am b/util-vserver/Makefile.am index 2f85191..7915f45 100644 --- a/util-vserver/Makefile.am +++ b/util-vserver/Makefile.am @@ -82,7 +82,7 @@ endif linuxcaps.h: ${kernelincludedir}/linux/capability.h Makefile @rm -f $@ echo '#include ' >$@.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 $@ diff --git a/util-vserver/THANKS b/util-vserver/THANKS index 65b51e9..707403f 100644 --- a/util-vserver/THANKS +++ b/util-vserver/THANKS @@ -4,4 +4,8 @@ Jacques Gelinas , 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 diff --git a/util-vserver/configure.ac b/util-vserver/configure.ac index 8936592..e407a9a 100644 --- a/util-vserver/configure.ac +++ b/util-vserver/configure.ac @@ -24,7 +24,7 @@ dnl distribution terms that you use for the rest of that program. 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]) @@ -93,19 +93,24 @@ AC_ARG_ENABLE([apis], [], [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 ]) AC_CHECK_TYPES(ctx_t,,,[#include ]) diff --git a/util-vserver/lib/Makefile-files b/util-vserver/lib/Makefile-files index b8343a6..aad5979 100644 --- a/util-vserver/lib/Makefile-files +++ b/util-vserver/lib/Makefile-files @@ -21,6 +21,7 @@ lib_legacy_SRCS = lib/getprocentry-legacy.c lib_management_SRCS = lib/getvservername.c \ lib/getvservercfgstyle.c \ lib/getvservervdir.c +lib_v11_SRCS = lib/syscall_rlimit.c PKGCONFIG_FILES = lib/util-vserver @@ -33,12 +34,14 @@ lib_SRCS = lib/syscall.c \ 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 \ diff --git a/util-vserver/lib/syscall-compat.hc b/util-vserver/lib/syscall-compat.hc index 630265b..a3cdcba 100644 --- a/util-vserver/lib/syscall-compat.hc +++ b/util-vserver/lib/syscall-compat.hc @@ -35,7 +35,7 @@ vc_new_s_context_compat(ctx_t ctx, unsigned int remove_cap, unsigned int flags) 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 diff --git a/util-vserver/lib/syscall_rlimit-v11.hc b/util-vserver/lib/syscall_rlimit-v11.hc new file mode 100644 index 0000000..8148ba5 --- /dev/null +++ b/util-vserver/lib/syscall_rlimit-v11.hc @@ -0,0 +1,75 @@ +// $Id$ --*- c++ -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// 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 +#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 diff --git a/util-vserver/lib/syscall_rlimit.c b/util-vserver/lib/syscall_rlimit.c new file mode 100644 index 0000000..58766c0 --- /dev/null +++ b/util-vserver/lib/syscall_rlimit.c @@ -0,0 +1,54 @@ +// $Id$ --*- c++ -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// 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 +#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 diff --git a/util-vserver/lib/virtual.h b/util-vserver/lib/virtual.h index f05fb40..ac6a3d7 100644 --- a/util-vserver/lib/virtual.h +++ b/util-vserver/lib/virtual.h @@ -2,51 +2,82 @@ #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; @@ -54,4 +85,27 @@ struct vcmd_set_ipv4root_v3 { }; +/* 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 */ diff --git a/util-vserver/lib/vserver-internal.h b/util-vserver/lib/vserver-internal.h index de944d0..da7d062 100644 --- a/util-vserver/lib/vserver-internal.h +++ b/util-vserver/lib/vserver-internal.h @@ -62,6 +62,27 @@ # 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, diff --git a/util-vserver/lib/vserver.h b/util-vserver/lib/vserver.h index 283897a..4a3ba90 100644 --- a/util-vserver/lib/vserver.h +++ b/util-vserver/lib/vserver.h @@ -1,20 +1,21 @@ -// $Id$ - -// Copyright (C) 2003 Enrico Scholz -// -// 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 +* +* 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 @@ -23,10 +24,17 @@ #include #include -#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 @@ -113,6 +121,26 @@ extern "C" { 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); @@ -125,7 +153,7 @@ extern "C" { char const * vc_cap2text(int); - // The management part + /* The management part */ #define VC_LIMIT_VSERVER_NAME_LEN 1024 @@ -136,8 +164,8 @@ extern "C" { 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); diff --git a/util-vserver/scripts/vserver-legacy b/util-vserver/scripts/vserver-legacy index d0435bf..f4d3405 100755 --- a/util-vserver/scripts/vserver-legacy +++ b/util-vserver/scripts/vserver-legacy @@ -28,9 +28,9 @@ test -e "$UTIL_VSERVER_VARS" || { 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 @@ -452,6 +452,8 @@ elif [ "$2" = "start" ] ; then 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= @@ -464,7 +466,9 @@ elif [ "$2" = "start" ] ; then 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= @@ -577,7 +581,10 @@ elif [ "$2" = "stop" ] ; then 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 diff --git a/util-vserver/src/.cvsignore b/util-vserver/src/.cvsignore index 21b0120..2283871 100644 --- a/util-vserver/src/.cvsignore +++ b/util-vserver/src/.cvsignore @@ -28,6 +28,7 @@ vbuild vcheck vdu vfiles +vlimit vreboot vserver-stat vunify diff --git a/util-vserver/src/Makefile-files b/util-vserver/src/Makefile-files index 58ac7f2..dfd0256 100644 --- a/util-vserver/src/Makefile-files +++ b/util-vserver/src/Makefile-files @@ -41,6 +41,7 @@ src_OPTIONS_EXEMPT = src/parserpmdump \ src/chcontext \ src/rebootmgr \ src/reducecap \ + src/vlimit \ src/vdu \ src/vfiles \ src/vserver-stat @@ -57,10 +58,12 @@ src_DIETPROGS = src/new-namespace \ 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 @@ -94,6 +97,7 @@ src_sbin_PRGS = src/chbind \ src/reducecap \ src/vdu \ src/new-namespace \ + src/vlimit \ src/vserver-stat \ $(src_sbin_CXX_PROGS) @@ -121,6 +125,9 @@ src_exec_ulimit_SOURCES = src/exec-ulimit.c 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 diff --git a/util-vserver/src/ext2fs.h b/util-vserver/src/ext2fs.h new file mode 100644 index 0000000..6213185 --- /dev/null +++ b/util-vserver/src/ext2fs.h @@ -0,0 +1,30 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// 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 +#elif defined(HAVE_LINUX_EXT2_FS_H) +# include +#else +# error Do not know how to include +#endif + +#endif // H_UTIL_VSERVER_SRC_EXT2FS_H diff --git a/util-vserver/src/setctxlimit.c b/util-vserver/src/setctxlimit.c deleted file mode 100644 index e281401..0000000 --- a/util-vserver/src/setctxlimit.c +++ /dev/null @@ -1,91 +0,0 @@ -// $Id$ - -// Copyright (C) 2003 Enrico Scholz -// 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 -#endif -#include "compat.h" - -#include -#include -#include -#include -#include - -#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 +#endif +#include "compat.h" + #include #include #include #include #include #include -#include + +#include "ext2fs.h" + // Patch to help compile this utility on unpatched kernel source #ifndef EXT2_IMMUTABLE_FILE_FL diff --git a/util-vserver/src/vlimit.c b/util-vserver/src/vlimit.c new file mode 100644 index 0000000..df73ccb --- /dev/null +++ b/util-vserver/src/vlimit.c @@ -0,0 +1,232 @@ +// $Id$ + +// Copyright (C) 2003 Enrico Scholz +// +// 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 +#endif +#include "compat.h" + +#include "vserver.h" +#include "internal.h" + +#include +#include +#include +#include +#include +#include +#include + +#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 ] [-a|--all] [-MSH -- ]*\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< #include "vutil.h" #include -#include +#include "ext2fs.h" #include diff --git a/util-vserver/util-vserver.spec.in b/util-vserver/util-vserver.spec.in index 353c229..d16f113 100644 --- a/util-vserver/util-vserver.spec.in +++ b/util-vserver/util-vserver.spec.in @@ -19,7 +19,8 @@ Provides: vserver = %epoch:%version-%release 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