From: Enrico Scholz Date: Fri, 7 Nov 2003 22:02:17 +0000 (+0000) Subject: added ctxlimit X-Git-Tag: version_0_24_90~11 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bf97b30c75c12d7f935c861f52e035c39f1e53e;p=util-vserver.git added ctxlimit git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/branches/SYSCALL_SWITCH@387 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/src/.cvsignore b/util-vserver/src/.cvsignore index 63d3635..a8c8ebb 100644 --- a/util-vserver/src/.cvsignore +++ b/util-vserver/src/.cvsignore @@ -3,6 +3,7 @@ capchroot chbind chcontext +ctxlimit fakerunlevel filetime ifspec diff --git a/util-vserver/src/Makefile-files b/util-vserver/src/Makefile-files index 4633f71..c1ffe53 100644 --- a/util-vserver/src/Makefile-files +++ b/util-vserver/src/Makefile-files @@ -38,6 +38,7 @@ src_sbin_PRGS = src/chbind \ src/chcontext \ src/rebootmgr \ src/reducecap \ + src/ctxlimit \ src/vdu \ src/vfiles \ src/vserver-stat @@ -64,6 +65,9 @@ src_rebootmgr_CPPFLAGS = $(AM_CPPFLAGS) -DSBINDIR=\"$(sbindir)\" -DVROOTDIR=\" src_reducecap_SOURCES = src/reducecap.c src_reducecap_LDADD = lib/libvserver.a +src_ctxlimit_SOURCES = src/ctxlimit.c +src_ctxlimit_LDADD = lib/libvserver.a + src_showattr_SOURCES = src/showattr.c src_showperm_SOURCES = src/showperm.c src_vbuild_SOURCES = src/vbuild.cc src/vutil.cc diff --git a/util-vserver/src/ctxlimit.c b/util-vserver/src/ctxlimit.c new file mode 100644 index 0000000..e5efe86 --- /dev/null +++ b/util-vserver/src/ctxlimit.c @@ -0,0 +1,232 @@ +// $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 "vserver.h" +#include "vserver-internal.h" + +#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, + "ctxlimit " 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<