merged/added from 0.25
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 18 Nov 2003 23:46:42 +0000 (23:46 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 18 Nov 2003 23:46:42 +0000 (23:46 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@410 94cd875c-1c1d-0410-91d2-eb244daf1a30

19 files changed:
util-vserver/Makefile.am
util-vserver/THANKS
util-vserver/configure.ac
util-vserver/lib/Makefile-files
util-vserver/lib/syscall-compat.hc
util-vserver/lib/syscall_rlimit-v11.hc [new file with mode: 0644]
util-vserver/lib/syscall_rlimit.c [new file with mode: 0644]
util-vserver/lib/virtual.h
util-vserver/lib/vserver-internal.h
util-vserver/lib/vserver.h
util-vserver/scripts/vserver-legacy
util-vserver/src/.cvsignore
util-vserver/src/Makefile-files
util-vserver/src/ext2fs.h [new file with mode: 0644]
util-vserver/src/setctxlimit.c [deleted file]
util-vserver/src/showattr.c
util-vserver/src/vlimit.c [new file with mode: 0644]
util-vserver/src/vutil.cc
util-vserver/util-vserver.spec.in

index 2f85191..7915f45 100644 (file)
@@ -82,7 +82,7 @@ endif
 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 $@
index 65b51e9..707403f 100644 (file)
@@ -4,4 +4,8 @@ Jacques Gelinas <jack@solucorp.qc.ca>,
     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
index 8936592..e407a9a 100644 (file)
@@ -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 <linux/fs.h>])
 AC_CHECK_TYPES(ctx_t,,,[#include <sys/types.h>])
index b8343a6..aad5979 100644 (file)
@@ -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 \
index 630265b..a3cdcba 100644 (file)
@@ -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 (file)
index 0000000..8148ba5
--- /dev/null
@@ -0,0 +1,75 @@
+// $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
diff --git a/util-vserver/lib/syscall_rlimit.c b/util-vserver/lib/syscall_rlimit.c
new file mode 100644 (file)
index 0000000..58766c0
--- /dev/null
@@ -0,0 +1,54 @@
+// $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
index f05fb40..ac6a3d7 100644 (file)
@@ -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 */
index de944d0..da7d062 100644 (file)
 #  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,
index 283897a..4a3ba90 100644 (file)
@@ -1,20 +1,21 @@
-// $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
@@ -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);
index d0435bf..f4d3405 100755 (executable)
@@ -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
index 21b0120..2283871 100644 (file)
@@ -28,6 +28,7 @@ vbuild
 vcheck
 vdu
 vfiles
+vlimit
 vreboot
 vserver-stat
 vunify
index 58ac7f2..dfd0256 100644 (file)
@@ -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 (file)
index 0000000..6213185
--- /dev/null
@@ -0,0 +1,30 @@
+// $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
diff --git a/util-vserver/src/setctxlimit.c b/util-vserver/src/setctxlimit.c
deleted file mode 100644 (file)
index e281401..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-// $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;     
-}
-
index 7e63289..daaf7a6 100644 (file)
 // 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
diff --git a/util-vserver/src/vlimit.c b/util-vserver/src/vlimit.c
new file mode 100644 (file)
index 0000000..df73ccb
--- /dev/null
@@ -0,0 +1,232 @@
+// $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;
+}
index 5ca9a40..4f66ff5 100644 (file)
@@ -32,7 +32,7 @@
 #include <utime.h>
 #include "vutil.h"
 #include <sys/ioctl.h>
-#include <linux/ext2_fs.h>
+#include "ext2fs.h"
 
 #include <pathconfig.h>
 
index 353c229..d16f113 100644 (file)
@@ -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