X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Fvlimit.c;h=cf1b536f4bc6b797515606a077d7151430ca4d28;hb=a64dcc3f8cc535c437f7b35cef4747576aca629d;hp=690b6725b236ef074f7f4e980cbde523e3177433;hpb=7f097def11a0b0302a3746dc5f570c5a346a729d;p=util-vserver.git diff --git a/util-vserver/src/vlimit.c b/util-vserver/src/vlimit.c index 690b672..cf1b536 100644 --- a/util-vserver/src/vlimit.c +++ b/util-vserver/src/vlimit.c @@ -30,6 +30,7 @@ #include "vserver.h" #include "internal.h" +#include "util.h" #include #include @@ -38,20 +39,13 @@ #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) +#include +#include #define NUMLIM(X) \ { #X, required_argument, 0, 2048|X } +#define RESLIM(RES,V) \ + { #RES, required_argument, 0, 2048|RLIMIT_##V } static struct option const CMDLINE_OPTIONS[] = { @@ -66,16 +60,49 @@ 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), + RESLIM(cpu, CPU), + RESLIM(fsize, FSIZE), + RESLIM(data, DATA), + RESLIM(stack, STACK), + RESLIM(core, CORE), + RESLIM(rss, RSS), + RESLIM(nproc, NPROC), + RESLIM(nofile, NOFILE), + RESLIM(memlock, MEMLOCK), + RESLIM(as, AS), + RESLIM(locks, LOCKS), { 0,0,0,0 } }; +#define REV_RESLIM(X) [RLIMIT_##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) +}; + 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 ] [-a|--all] [-MSH -- ]*\n" + " -c [-nd] [-a|--all] [[-MSH] --(|) ]*\n\n" + "Options:\n" + " -c ... 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" + " --| \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 and locks.\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -91,6 +118,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) { @@ -102,9 +139,7 @@ appendLimit(char *ptr, bool do_it, vc_limit_t lim) ptr += 3; } else { - memcpy(ptr, "0x", 2); ptr += 2; - - ptr += utilvserver_fmt_xuint64(ptr, lim); + ptr += (*fmt_func)(ptr, lim); *ptr = ' '; } } @@ -122,7 +157,7 @@ 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); } @@ -130,16 +165,24 @@ showAll(int ctx) for (i=0; i<32; ++i) { uint32_t bitmask = (1<