ulimit: precompute option string for getopt and usage; noticed by bsiegert@
This commit is contained in:
89
funcs.c
89
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.222 2012/06/25 16:34:58 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.223 2012/08/03 18:30:13 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -3414,21 +3414,83 @@ c_ulimit(const char **wp)
|
|||||||
#endif
|
#endif
|
||||||
{ NULL, 0, 0, 0 }
|
{ NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
static char opts[3 + NELEM(limits)];
|
static const char opts[] = "a"
|
||||||
|
#ifdef RLIMIT_SBSIZE
|
||||||
|
"B"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_TCACHE
|
||||||
|
"C"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_CORE
|
||||||
|
"c"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_DATA
|
||||||
|
"d"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_NICE
|
||||||
|
"e"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_FSIZE
|
||||||
|
"f"
|
||||||
|
#endif
|
||||||
|
"H"
|
||||||
|
#ifdef RLIMIT_SIGPENDING
|
||||||
|
"i"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_LOCKS
|
||||||
|
"L"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_MEMLOCK
|
||||||
|
"l"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_AIO_MEM
|
||||||
|
"M"
|
||||||
|
#endif
|
||||||
|
#if defined(ULIMIT_M_IS_RSS) || defined(ULIMIT_M_IS_VMEM)
|
||||||
|
"m"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_NOFILE
|
||||||
|
"n"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_AIO_OPS
|
||||||
|
"O"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_PTHREAD
|
||||||
|
"P"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_NPROC
|
||||||
|
"p"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_MSGQUEUE
|
||||||
|
"q"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_RTPRIO
|
||||||
|
"r"
|
||||||
|
#endif
|
||||||
|
"S"
|
||||||
|
#ifdef RLIMIT_STACK
|
||||||
|
"s"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_TIME
|
||||||
|
"T"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_CPU
|
||||||
|
"t"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_NOVMON
|
||||||
|
"V"
|
||||||
|
#endif
|
||||||
|
#if defined(ULIMIT_V_IS_VMEM) || defined(ULIMIT_V_IS_AS)
|
||||||
|
"v"
|
||||||
|
#endif
|
||||||
|
#ifdef RLIMIT_SWAP
|
||||||
|
"w"
|
||||||
|
#endif
|
||||||
|
;
|
||||||
int how = SOFT | HARD, optc, what = 'f';
|
int how = SOFT | HARD, optc, what = 'f';
|
||||||
bool all = false;
|
bool all = false;
|
||||||
const struct limits *l;
|
const struct limits *l;
|
||||||
|
|
||||||
if (!opts[0]) {
|
|
||||||
/* build options string on first call - yuck */
|
|
||||||
char *p = opts;
|
|
||||||
|
|
||||||
*p++ = 'H'; *p++ = 'S'; *p++ = 'a';
|
|
||||||
for (l = limits; l->name; l++)
|
|
||||||
*p++ = l->option;
|
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((optc = ksh_getopt(wp, &builtin_opt, opts)) != -1)
|
while ((optc = ksh_getopt(wp, &builtin_opt, opts)) != -1)
|
||||||
switch (optc) {
|
switch (optc) {
|
||||||
case 'H':
|
case 'H':
|
||||||
@ -3441,8 +3503,7 @@ c_ulimit(const char **wp)
|
|||||||
all = true;
|
all = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
bi_errorf("%s: %s", "usage",
|
bi_errorf("usage: ulimit [-%s] [value]", opts);
|
||||||
"ulimit [-acdfHLlmnpSsTtvw] [value]");
|
|
||||||
return (1);
|
return (1);
|
||||||
default:
|
default:
|
||||||
what = optc;
|
what = optc;
|
||||||
|
Reference in New Issue
Block a user