X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fvlimit.c;h=b2d128e6738bd673bd45341efa58f01b7aa995c4;hb=95e2774070e989fe9cf9f48dae5fa054e55e2a3e;hp=18a28b258fe595e452665af3a2c8578e08bb37b1;hpb=06e1018272502e1d15d6d8f32b80fa96420785b8;p=util-vserver.git diff --git a/src/vlimit.c b/src/vlimit.c index 18a28b2..b2d128e 100644 --- a/src/vlimit.c +++ b/src/vlimit.c @@ -1,4 +1,4 @@ -// $Id: vlimit.c,v 1.1.2.2 2003/12/30 13:47:08 ensc Exp $ +// $Id: vlimit.c 2403 2006-11-24 23:06:08Z dhozac $ // Copyright (C) 2003 Enrico Scholz // @@ -29,7 +29,8 @@ #include "compat.h" #include "vserver.h" -#include "vserver-internal.h" +#include "internal.h" +#include "util.h" #include #include @@ -37,26 +38,46 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include -#define VERSION_COPYRIGHT_DISCLAIMER +#define ENSC_WRAPPERS_PREFIX "vlimit: " +#define ENSC_WRAPPERS_UNISTD 1 +#define ENSC_WRAPPERS_VSERVER 1 +#include -inline static void UNUSED -writeStr(int fd, char const *cmd) -{ - (void)write(fd, cmd, strlen(cmd)); -} +#define CMD_HELP 0x1000 +#define CMD_VERSION 0x1001 +#define CMD_XID 0x4000 +#define CMD_DIR 0x8000 +#define CMD_MISSINGOK 0x8001 -#define WRITE_MSG(FD,X) (void)(write(FD,X,sizeof(X)-1)) -#define WRITE_STR(FD,X) writeStr(FD,X) +int wrapper_exit_code = 255; + +#ifndef RLIMIT_MSGQUEUE +# define RLIMIT_MSGQUEUE 12 +#endif #define NUMLIM(X) \ { #X, required_argument, 0, 2048|X } +#define OPT_RESLIM(RES,V) \ + { #RES, required_argument, 0, 2048|RLIMIT_##V } +#define OPT_VLIMIT(RES,V) \ + { #RES, required_argument, 0, 2048|VC_VLIMIT_##V } static struct option const CMDLINE_OPTIONS[] = { - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'v' }, - { "all", no_argument, 0, 'a' }, + { "help", no_argument, 0, CMD_HELP }, + { "version", no_argument, 0, CMD_VERSION }, + { "all", no_argument, 0, 'a' }, + { "xid", required_argument, 0, CMD_XID }, + { "dir", required_argument, 0, CMD_DIR }, + { "missingok", no_argument, 0, CMD_MISSINGOK }, NUMLIM( 0), NUMLIM( 1), NUMLIM( 2), NUMLIM( 3), NUMLIM( 4), NUMLIM( 5), NUMLIM( 6), NUMLIM( 7), NUMLIM( 8), NUMLIM( 9), NUMLIM(10), NUMLIM(11), @@ -65,16 +86,69 @@ CMDLINE_OPTIONS[] = { NUMLIM(20), NUMLIM(21), NUMLIM(22), NUMLIM(23), NUMLIM(24), NUMLIM(25), NUMLIM(26), NUMLIM(27), NUMLIM(28), NUMLIM(29), NUMLIM(30), NUMLIM(31), + OPT_RESLIM(cpu, CPU), + OPT_RESLIM(fsize, FSIZE), + OPT_RESLIM(data, DATA), + OPT_RESLIM(stack, STACK), + OPT_RESLIM(core, CORE), + OPT_RESLIM(rss, RSS), + OPT_RESLIM(nproc, NPROC), + OPT_RESLIM(nofile, NOFILE), + OPT_RESLIM(memlock, MEMLOCK), + OPT_RESLIM(as, AS), + OPT_RESLIM(locks, LOCKS), + OPT_RESLIM(msgqueue, MSGQUEUE), + OPT_VLIMIT(nsock, NSOCK), + OPT_VLIMIT(openfd, OPENFD), + OPT_VLIMIT(anon, ANON), + OPT_VLIMIT(shmem, SHMEM), + OPT_VLIMIT(semary, SEMARY), + OPT_VLIMIT(nsems, NSEMS), + OPT_VLIMIT(dentry, DENTRY), { 0,0,0,0 } }; +#define REV_RESLIM(X) [RLIMIT_##X] = #X +#define REV_VLIMIT(X) [VC_VLIMIT_##X] = #X +static char const * const LIMIT_STR[] = { + REV_RESLIM(CPU), REV_RESLIM(FSIZE), REV_RESLIM(DATA), REV_RESLIM(STACK), + REV_RESLIM(CORE), REV_RESLIM(RSS), REV_RESLIM(NPROC), REV_RESLIM(NOFILE), + REV_RESLIM(MEMLOCK), REV_RESLIM(AS), REV_RESLIM(LOCKS), REV_RESLIM(MSGQUEUE), + REV_VLIMIT(NSOCK), REV_VLIMIT(OPENFD), REV_VLIMIT(ANON), REV_VLIMIT(SHMEM), + REV_VLIMIT(SEMARY), REV_VLIMIT(NSEMS), REV_VLIMIT(DENTRY), +}; + static void showHelp(int fd, char const *cmd, int res) { + VSERVER_DECLARE_CMD(cmd); + WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [-c|--ctx ] [-a|--all] [-MSH -- ]*\n" + " [--xid|-c ] [-nd] [-a|--all] [[-MSH] --(|) ]*\n" + " [--dir [--missingok]] [--] [ *]\n\n" + "Options:\n" + " -c|--xid \n" + " ... operate on context \n" + " -a|--all ... show all available limits\n" + " -n ... do not resolve limit-names\n" + " -d ... show limits in decimal\n" + " -M ... set Minimum limit\n" + " -S ... set Soft limit\n" + " -H ... set Hard limit (assumed by default, when neither\n" + " M nor S was requested)\n" + " --dir \n" + " ... read limits from /; allowed filenames are\n" + " and .{min,soft,hard}. When a limit\n" + " was set by the CLI already, the corresponding file\n" + " will be ignored\n" + " --missingok ... do not fail when does not exist\n" + " --| \n" + " ... set specified (MSH) limit for to \n\n" + "Valid values for resource are cpu, fsize, data, stack, core, rss, nproc,\n" + "nofile, memlock, as, locks, msgqueue, nsock, openfd, anon, shmem, semary,\n" + "nsems, and dentry.\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -90,6 +164,16 @@ showVersion() exit(0); } +static size_t +fmtHex(char *ptr, vc_limit_t lim) +{ + memcpy(ptr, "0x", 2); + return utilvserver_fmt_xuint64(ptr+2, lim) + 2; +} + +static bool do_resolve = true; +static size_t (*fmt_func)(char *, vc_limit_t) = fmtHex; + static void * appendLimit(char *ptr, bool do_it, vc_limit_t lim) { @@ -97,15 +181,11 @@ appendLimit(char *ptr, bool do_it, vc_limit_t lim) ptr += 2; if (do_it) { if (lim==VC_LIM_INFINITY) { - strcpy(ptr, "INF"); + memcpy(ptr, "inf", 3); 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 += (*fmt_func)(ptr, lim); *ptr = ' '; } } @@ -123,54 +203,151 @@ showAll(int ctx) struct vc_rlimit_mask mask; size_t i; - if (vc_get_rlimit_mask(-2, &mask)==-1) { + if (vc_get_rlimit_mask(ctx, &mask)==-1) { perror("vc_get_rlimit_mask()"); - //exit(1); + exit(wrapper_exit_code); } for (i=0; i<32; ++i) { uint32_t bitmask = (1<0 && pathname[l_pathname-1]!='/') + buf[l_pathname++] = '/'; + + for (i=0; i