ash,hush: bash compat for ulimit: reorder to match

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2019-04-28 11:20:09 +02:00
parent a92a9601f8
commit 57e1b0ad5e

View File

@ -339,44 +339,38 @@ struct limits {
}; };
static const struct limits limits_tbl[] = { static const struct limits limits_tbl[] = {
/* No RLIMIT_FSIZE define guard since -f is the default limit and this must exist */
{ RLIMIT_FSIZE, 9, "file size (blocks)" }, // -f
#ifdef RLIMIT_CPU
{ RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t
#endif
#ifdef RLIMIT_DATA
{ RLIMIT_DATA, 10, "data seg size (kb)" }, // -d
#endif
#ifdef RLIMIT_STACK
{ RLIMIT_STACK, 10, "stack size (kb)" }, // -s
#endif
#ifdef RLIMIT_CORE
{ RLIMIT_CORE, 9, "core file size (blocks)" }, // -c { RLIMIT_CORE, 9, "core file size (blocks)" }, // -c
{ RLIMIT_DATA, 10, "data seg size (kb)" }, // -d
{ RLIMIT_NICE, 0, "scheduling priority" }, // -e
{ RLIMIT_FSIZE, 9, "file size (blocks)" }, // -f
#define LIMIT_F_IDX 3
#ifdef RLIMIT_MEMLOCK
{ RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l
#endif #endif
#ifdef RLIMIT_RSS #ifdef RLIMIT_RSS
{ RLIMIT_RSS, 10, "max memory size (kb)" }, // -m { RLIMIT_RSS, 10, "max memory size (kb)" }, // -m
#endif #endif
#ifdef RLIMIT_MEMLOCK #ifdef RLIMIT_NOFILE
{ RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l { RLIMIT_NOFILE, 0, "open files" }, // -n
#endif
#ifdef RLIMIT_RTPRIO
{ RLIMIT_RTPRIO, 0, "real-time priority" }, // -r
#endif
#ifdef RLIMIT_STACK
{ RLIMIT_STACK, 10, "stack size (kb)" }, // -s
#endif
#ifdef RLIMIT_CPU
{ RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t
#endif #endif
#ifdef RLIMIT_NPROC #ifdef RLIMIT_NPROC
{ RLIMIT_NPROC, 0, "max user processes" }, // -u { RLIMIT_NPROC, 0, "max user processes" }, // -u
#endif #endif
#ifdef RLIMIT_NOFILE
{ RLIMIT_NOFILE, 0, "open files" }, // -n
#endif
#ifdef RLIMIT_AS #ifdef RLIMIT_AS
{ RLIMIT_AS, 10, "virtual memory (kb)" }, // -v { RLIMIT_AS, 10, "virtual memory (kb)" }, // -v
#endif #endif
#ifdef RLIMIT_LOCKS #ifdef RLIMIT_LOCKS
{ RLIMIT_LOCKS, 0, "file locks" }, // -x { RLIMIT_LOCKS, 0, "file locks" }, // -x
#endif #endif
#ifdef RLIMIT_NICE
{ RLIMIT_NICE, 0, "scheduling priority" }, // -e
#endif
#ifdef RLIMIT_RTPRIO
{ RLIMIT_RTPRIO, 0, "real-time priority" }, // -r
#endif
}; };
// bash also has these: // bash also has these:
//pending signals (-i) 61858 //RLIMIT_SIGPENDING //pending signals (-i) 61858 //RLIMIT_SIGPENDING
@ -384,85 +378,73 @@ static const struct limits limits_tbl[] = {
//POSIX message queues (bytes, -q) 819200 //RLIMIT_MSGQUEUE //POSIX message queues (bytes, -q) 819200 //RLIMIT_MSGQUEUE
static const char limit_chars[] ALIGN1 = static const char limit_chars[] ALIGN1 =
"f"
#ifdef RLIMIT_CPU
"t"
#endif
#ifdef RLIMIT_DATA
"d"
#endif
#ifdef RLIMIT_STACK
"s"
#endif
#ifdef RLIMIT_CORE
"c" "c"
"d"
"e"
"f"
#ifdef RLIMIT_MEMLOCK
"l"
#endif #endif
#ifdef RLIMIT_RSS #ifdef RLIMIT_RSS
"m" "m"
#endif #endif
#ifdef RLIMIT_MEMLOCK #ifdef RLIMIT_NOFILE
"l" "n"
#endif
#ifdef RLIMIT_RTPRIO
"r"
#endif
#ifdef RLIMIT_STACK
"s"
#endif
#ifdef RLIMIT_CPU
"t"
#endif #endif
#ifdef RLIMIT_NPROC #ifdef RLIMIT_NPROC
"u" "u"
#endif #endif
#ifdef RLIMIT_NOFILE
"n"
#endif
#ifdef RLIMIT_AS #ifdef RLIMIT_AS
"v" "v"
#endif #endif
#ifdef RLIMIT_LOCKS #ifdef RLIMIT_LOCKS
"x" "x"
#endif #endif
#ifdef RLIMIT_NICE
"e"
#endif
#ifdef RLIMIT_RTPRIO
"r"
#endif
; ;
/* "-": treat args as parameters of option with ASCII code 1 */ /* "-": treat args as parameters of option with ASCII code 1 */
static const char ulimit_opt_string[] ALIGN1 = "-HSa" static const char ulimit_opt_string[] ALIGN1 = "-HSa"
"f::"
#ifdef RLIMIT_CPU
"t::"
#endif
#ifdef RLIMIT_DATA
"d::"
#endif
#ifdef RLIMIT_STACK
"s::"
#endif
#ifdef RLIMIT_CORE
"c::" "c::"
"d::"
"e::"
"f::"
#ifdef RLIMIT_MEMLOCK
"l::"
#endif #endif
#ifdef RLIMIT_RSS #ifdef RLIMIT_RSS
"m::" "m::"
#endif #endif
#ifdef RLIMIT_MEMLOCK #ifdef RLIMIT_NOFILE
"l::" "n::"
#endif
#ifdef RLIMIT_RTPRIO
"r::"
#endif
#ifdef RLIMIT_STACK
"s::"
#endif
#ifdef RLIMIT_CPU
"t::"
#endif #endif
#ifdef RLIMIT_NPROC #ifdef RLIMIT_NPROC
"u::" "u::"
#endif #endif
#ifdef RLIMIT_NOFILE
"n::"
#endif
#ifdef RLIMIT_AS #ifdef RLIMIT_AS
"v::" "v::"
#endif #endif
#ifdef RLIMIT_LOCKS #ifdef RLIMIT_LOCKS
"x::" "x::"
#endif #endif
#ifdef RLIMIT_NICE ;
"e::"
#endif
#ifdef RLIMIT_RTPRIO
"r::"
#endif
;
enum { enum {
OPT_hard = (1 << 0), OPT_hard = (1 << 0),
@ -595,11 +577,10 @@ shell_builtin_ulimit(char **argv)
continue; continue;
//if (opt_char == 'a') - impossible //if (opt_char == 'a') - impossible
i = 0; /* if "ulimit NNN", -f is assumed */ if (opt_char == 1) /* if "ulimit NNN", -f is assumed */
if (opt_char != 1) { opt_char = 'f';
i = strchrnul(limit_chars, opt_char) - limit_chars; i = strchrnul(limit_chars, opt_char) - limit_chars;
//if (i >= ARRAY_SIZE(limits_tbl)) - bad option, impossible //if (i >= ARRAY_SIZE(limits_tbl)) - bad option, impossible
}
val_str = optarg; val_str = optarg;
if (!val_str && argv[optind] && argv[optind][0] != '-') if (!val_str && argv[optind] && argv[optind][0] != '-')
@ -643,8 +624,8 @@ shell_builtin_ulimit(char **argv)
if (opt_cnt == 0) { if (opt_cnt == 0) {
/* "bare ulimit": treat it as if it was -f */ /* "bare ulimit": treat it as if it was -f */
getrlimit(limits_tbl[0].cmd, &limit); getrlimit(limits_tbl[LIMIT_F_IDX].cmd, &limit);
printlim(opts, &limit, &limits_tbl[0]); printlim(opts, &limit, &limits_tbl[LIMIT_F_IDX]);
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;