aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-04-28 11:20:09 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-04-28 11:20:09 +0200
commit57e1b0ad5ebd77705841fbcd01a79f2552fbab8e (patch)
treebebc5fbbabb9d6d92304bab0d0f850cafb3e4965
parenta92a9601f89d59597b268e29e7098597a8766778 (diff)
downloadbusybox-57e1b0ad5ebd77705841fbcd01a79f2552fbab8e.tar.gz
ash,hush: bash compat for ulimit: reorder to match
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/shell_common.c125
1 files changed, 53 insertions, 72 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c
index a992682a8..cc518d54b 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -339,44 +339,38 @@ struct limits {
};
static const struct limits limits_tbl[] = {
-/* No RLIMIT_FSIZE define guard since -f is the default limit and this must exist */
+ { 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
-#ifdef RLIMIT_CPU
- { RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t
+#define LIMIT_F_IDX 3
+#ifdef RLIMIT_MEMLOCK
+ { RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l
#endif
-#ifdef RLIMIT_DATA
- { RLIMIT_DATA, 10, "data seg size (kb)" }, // -d
+#ifdef RLIMIT_RSS
+ { RLIMIT_RSS, 10, "max memory size (kb)" }, // -m
#endif
-#ifdef RLIMIT_STACK
- { RLIMIT_STACK, 10, "stack size (kb)" }, // -s
+#ifdef RLIMIT_NOFILE
+ { RLIMIT_NOFILE, 0, "open files" }, // -n
#endif
-#ifdef RLIMIT_CORE
- { RLIMIT_CORE, 9, "core file size (blocks)" }, // -c
+#ifdef RLIMIT_RTPRIO
+ { RLIMIT_RTPRIO, 0, "real-time priority" }, // -r
#endif
-#ifdef RLIMIT_RSS
- { RLIMIT_RSS, 10, "max memory size (kb)" }, // -m
+#ifdef RLIMIT_STACK
+ { RLIMIT_STACK, 10, "stack size (kb)" }, // -s
#endif
-#ifdef RLIMIT_MEMLOCK
- { RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l
+#ifdef RLIMIT_CPU
+ { RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t
#endif
#ifdef RLIMIT_NPROC
{ RLIMIT_NPROC, 0, "max user processes" }, // -u
#endif
-#ifdef RLIMIT_NOFILE
- { RLIMIT_NOFILE, 0, "open files" }, // -n
-#endif
#ifdef RLIMIT_AS
{ RLIMIT_AS, 10, "virtual memory (kb)" }, // -v
#endif
#ifdef RLIMIT_LOCKS
{ RLIMIT_LOCKS, 0, "file locks" }, // -x
#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:
//pending signals (-i) 61858 //RLIMIT_SIGPENDING
@@ -384,85 +378,73 @@ static const struct limits limits_tbl[] = {
//POSIX message queues (bytes, -q) 819200 //RLIMIT_MSGQUEUE
static const char limit_chars[] ALIGN1 =
+ "c"
+ "d"
+ "e"
"f"
-#ifdef RLIMIT_CPU
- "t"
+#ifdef RLIMIT_MEMLOCK
+ "l"
#endif
-#ifdef RLIMIT_DATA
- "d"
+#ifdef RLIMIT_RSS
+ "m"
#endif
-#ifdef RLIMIT_STACK
- "s"
+#ifdef RLIMIT_NOFILE
+ "n"
#endif
-#ifdef RLIMIT_CORE
- "c"
+#ifdef RLIMIT_RTPRIO
+ "r"
#endif
-#ifdef RLIMIT_RSS
- "m"
+#ifdef RLIMIT_STACK
+ "s"
#endif
-#ifdef RLIMIT_MEMLOCK
- "l"
+#ifdef RLIMIT_CPU
+ "t"
#endif
#ifdef RLIMIT_NPROC
"u"
#endif
-#ifdef RLIMIT_NOFILE
- "n"
-#endif
#ifdef RLIMIT_AS
"v"
#endif
#ifdef RLIMIT_LOCKS
"x"
#endif
-#ifdef RLIMIT_NICE
- "e"
-#endif
-#ifdef RLIMIT_RTPRIO
- "r"
-#endif
;
/* "-": treat args as parameters of option with ASCII code 1 */
static const char ulimit_opt_string[] ALIGN1 = "-HSa"
+ "c::"
+ "d::"
+ "e::"
"f::"
-#ifdef RLIMIT_CPU
- "t::"
+#ifdef RLIMIT_MEMLOCK
+ "l::"
#endif
-#ifdef RLIMIT_DATA
- "d::"
+#ifdef RLIMIT_RSS
+ "m::"
#endif
-#ifdef RLIMIT_STACK
- "s::"
+#ifdef RLIMIT_NOFILE
+ "n::"
#endif
-#ifdef RLIMIT_CORE
- "c::"
+#ifdef RLIMIT_RTPRIO
+ "r::"
#endif
-#ifdef RLIMIT_RSS
- "m::"
+#ifdef RLIMIT_STACK
+ "s::"
#endif
-#ifdef RLIMIT_MEMLOCK
- "l::"
+#ifdef RLIMIT_CPU
+ "t::"
#endif
#ifdef RLIMIT_NPROC
"u::"
#endif
-#ifdef RLIMIT_NOFILE
- "n::"
-#endif
#ifdef RLIMIT_AS
"v::"
#endif
#ifdef RLIMIT_LOCKS
"x::"
#endif
-#ifdef RLIMIT_NICE
- "e::"
-#endif
-#ifdef RLIMIT_RTPRIO
- "r::"
-#endif
- ;
+;
enum {
OPT_hard = (1 << 0),
@@ -595,11 +577,10 @@ shell_builtin_ulimit(char **argv)
continue;
//if (opt_char == 'a') - impossible
- i = 0; /* if "ulimit NNN", -f is assumed */
- if (opt_char != 1) {
- i = strchrnul(limit_chars, opt_char) - limit_chars;
- //if (i >= ARRAY_SIZE(limits_tbl)) - bad option, impossible
- }
+ if (opt_char == 1) /* if "ulimit NNN", -f is assumed */
+ opt_char = 'f';
+ i = strchrnul(limit_chars, opt_char) - limit_chars;
+ //if (i >= ARRAY_SIZE(limits_tbl)) - bad option, impossible
val_str = optarg;
if (!val_str && argv[optind] && argv[optind][0] != '-')
@@ -643,8 +624,8 @@ shell_builtin_ulimit(char **argv)
if (opt_cnt == 0) {
/* "bare ulimit": treat it as if it was -f */
- getrlimit(limits_tbl[0].cmd, &limit);
- printlim(opts, &limit, &limits_tbl[0]);
+ getrlimit(limits_tbl[LIMIT_F_IDX].cmd, &limit);
+ printlim(opts, &limit, &limits_tbl[LIMIT_F_IDX]);
}
return EXIT_SUCCESS;