diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-21 16:47:09 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-21 16:47:09 +0200 |
commit | 3ef513e787781e26f5996fc19b3540287a57fb9f (patch) | |
tree | cd469ff3acac937476d3c78a6f9399e719ecfb85 /shell | |
parent | fb1103595f0562f98505882150fed384dea72f39 (diff) | |
download | busybox-w32-3ef513e787781e26f5996fc19b3540287a57fb9f.tar.gz busybox-w32-3ef513e787781e26f5996fc19b3540287a57fb9f.tar.bz2 busybox-w32-3ef513e787781e26f5996fc19b3540287a57fb9f.zip |
shell/ulimit: code shrink
text data bss dec hex filename
1001949 551 5612 1008112 f61f0 busybox_old
1001906 551 5612 1008069 f61c5 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/shell_common.c | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c index a93533903..12c4a073c 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c | |||
@@ -322,52 +322,91 @@ shell_builtin_read(struct builtin_read_params *params) | |||
322 | struct limits { | 322 | struct limits { |
323 | uint8_t cmd; /* RLIMIT_xxx fit into it */ | 323 | uint8_t cmd; /* RLIMIT_xxx fit into it */ |
324 | uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */ | 324 | uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */ |
325 | const char *name; | ||
326 | }; | 325 | }; |
327 | 326 | ||
328 | static const struct limits limits_tbl[] = { | 327 | static const struct limits limits_tbl[] = { |
329 | { RLIMIT_CORE, 9, "core file size (blocks)" }, // -c | 328 | { RLIMIT_CORE, 9, }, // -c |
330 | { RLIMIT_DATA, 10, "data seg size (kb)" }, // -d | 329 | { RLIMIT_DATA, 10, }, // -d |
331 | { RLIMIT_NICE, 0, "scheduling priority" }, // -e | 330 | { RLIMIT_NICE, 0, }, // -e |
332 | { RLIMIT_FSIZE, 9, "file size (blocks)" }, // -f | 331 | { RLIMIT_FSIZE, 9, }, // -f |
333 | #define LIMIT_F_IDX 3 | 332 | #define LIMIT_F_IDX 3 |
334 | #ifdef RLIMIT_SIGPENDING | 333 | #ifdef RLIMIT_SIGPENDING |
335 | { RLIMIT_SIGPENDING, 0, "pending signals" }, // -i | 334 | { RLIMIT_SIGPENDING, 0, }, // -i |
336 | #endif | 335 | #endif |
337 | #ifdef RLIMIT_MEMLOCK | 336 | #ifdef RLIMIT_MEMLOCK |
338 | { RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l | 337 | { RLIMIT_MEMLOCK, 10, }, // -l |
339 | #endif | 338 | #endif |
340 | #ifdef RLIMIT_RSS | 339 | #ifdef RLIMIT_RSS |
341 | { RLIMIT_RSS, 10, "max memory size (kb)" }, // -m | 340 | { RLIMIT_RSS, 10, }, // -m |
342 | #endif | 341 | #endif |
343 | #ifdef RLIMIT_NOFILE | 342 | #ifdef RLIMIT_NOFILE |
344 | { RLIMIT_NOFILE, 0, "open files" }, // -n | 343 | { RLIMIT_NOFILE, 0, }, // -n |
345 | #endif | 344 | #endif |
346 | #ifdef RLIMIT_MSGQUEUE | 345 | #ifdef RLIMIT_MSGQUEUE |
347 | { RLIMIT_MSGQUEUE, 0, "POSIX message queues (bytes)" }, // -q | 346 | { RLIMIT_MSGQUEUE, 0, }, // -q |
348 | #endif | 347 | #endif |
349 | #ifdef RLIMIT_RTPRIO | 348 | #ifdef RLIMIT_RTPRIO |
350 | { RLIMIT_RTPRIO, 0, "real-time priority" }, // -r | 349 | { RLIMIT_RTPRIO, 0, }, // -r |
351 | #endif | 350 | #endif |
352 | #ifdef RLIMIT_STACK | 351 | #ifdef RLIMIT_STACK |
353 | { RLIMIT_STACK, 10, "stack size (kb)" }, // -s | 352 | { RLIMIT_STACK, 10, }, // -s |
354 | #endif | 353 | #endif |
355 | #ifdef RLIMIT_CPU | 354 | #ifdef RLIMIT_CPU |
356 | { RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t | 355 | { RLIMIT_CPU, 0, }, // -t |
357 | #endif | 356 | #endif |
358 | #ifdef RLIMIT_NPROC | 357 | #ifdef RLIMIT_NPROC |
359 | { RLIMIT_NPROC, 0, "max user processes" }, // -u | 358 | { RLIMIT_NPROC, 0, }, // -u |
360 | #endif | 359 | #endif |
361 | #ifdef RLIMIT_AS | 360 | #ifdef RLIMIT_AS |
362 | { RLIMIT_AS, 10, "virtual memory (kb)" }, // -v | 361 | { RLIMIT_AS, 10, }, // -v |
363 | #endif | 362 | #endif |
364 | #ifdef RLIMIT_LOCKS | 363 | #ifdef RLIMIT_LOCKS |
365 | { RLIMIT_LOCKS, 0, "file locks" }, // -x | 364 | { RLIMIT_LOCKS, 0, }, // -x |
366 | #endif | 365 | #endif |
367 | }; | 366 | }; |
368 | // bash also shows: | 367 | // bash also shows: |
369 | //pipe size (512 bytes, -p) 8 | 368 | //pipe size (512 bytes, -p) 8 |
370 | 369 | ||
370 | static const char limits_help[] ALIGN1 = | ||
371 | "core file size (blocks)" // -c | ||
372 | "\0""data seg size (kb)" // -d | ||
373 | "\0""scheduling priority" // -e | ||
374 | "\0""file size (blocks)" // -f | ||
375 | #ifdef RLIMIT_SIGPENDING | ||
376 | "\0""pending signals" // -i | ||
377 | #endif | ||
378 | #ifdef RLIMIT_MEMLOCK | ||
379 | "\0""max locked memory (kb)" // -l | ||
380 | #endif | ||
381 | #ifdef RLIMIT_RSS | ||
382 | "\0""max memory size (kb)" // -m | ||
383 | #endif | ||
384 | #ifdef RLIMIT_NOFILE | ||
385 | "\0""open files" // -n | ||
386 | #endif | ||
387 | #ifdef RLIMIT_MSGQUEUE | ||
388 | "\0""POSIX message queues (bytes)" // -q | ||
389 | #endif | ||
390 | #ifdef RLIMIT_RTPRIO | ||
391 | "\0""real-time priority" // -r | ||
392 | #endif | ||
393 | #ifdef RLIMIT_STACK | ||
394 | "\0""stack size (kb)" // -s | ||
395 | #endif | ||
396 | #ifdef RLIMIT_CPU | ||
397 | "\0""cpu time (seconds)" // -t | ||
398 | #endif | ||
399 | #ifdef RLIMIT_NPROC | ||
400 | "\0""max user processes" // -u | ||
401 | #endif | ||
402 | #ifdef RLIMIT_AS | ||
403 | "\0""virtual memory (kb)" // -v | ||
404 | #endif | ||
405 | #ifdef RLIMIT_LOCKS | ||
406 | "\0""file locks" // -x | ||
407 | #endif | ||
408 | ; | ||
409 | |||
371 | static const char limit_chars[] ALIGN1 = | 410 | static const char limit_chars[] ALIGN1 = |
372 | "c" | 411 | "c" |
373 | "d" | 412 | "d" |
@@ -558,10 +597,12 @@ shell_builtin_ulimit(char **argv) | |||
558 | if (!(opts & (OPT_hard | OPT_soft))) | 597 | if (!(opts & (OPT_hard | OPT_soft))) |
559 | opts |= (OPT_hard | OPT_soft); | 598 | opts |= (OPT_hard | OPT_soft); |
560 | if (opts & OPT_all) { | 599 | if (opts & OPT_all) { |
600 | const char *help = limits_help; | ||
561 | for (i = 0; i < ARRAY_SIZE(limits_tbl); i++) { | 601 | for (i = 0; i < ARRAY_SIZE(limits_tbl); i++) { |
562 | getrlimit(limits_tbl[i].cmd, &limit); | 602 | getrlimit(limits_tbl[i].cmd, &limit); |
563 | printf("%-32s(-%c) ", limits_tbl[i].name, limit_chars[i]); | 603 | printf("%-32s(-%c) ", help, limit_chars[i]); |
564 | printlim(opts, &limit, &limits_tbl[i]); | 604 | printlim(opts, &limit, &limits_tbl[i]); |
605 | help += strlen(help) + 1; | ||
565 | } | 606 | } |
566 | return EXIT_SUCCESS; | 607 | return EXIT_SUCCESS; |
567 | } | 608 | } |
@@ -592,7 +633,7 @@ shell_builtin_ulimit(char **argv) | |||
592 | getrlimit(limits_tbl[i].cmd, &limit); | 633 | getrlimit(limits_tbl[i].cmd, &limit); |
593 | if (!val_str) { | 634 | if (!val_str) { |
594 | if (opt_cnt > 1) | 635 | if (opt_cnt > 1) |
595 | printf("%-32s(-%c) ", limits_tbl[i].name, limit_chars[i]); | 636 | printf("%-32s(-%c) ", nth_string(limits_help, i), limit_chars[i]); |
596 | printlim(opts, &limit, &limits_tbl[i]); | 637 | printlim(opts, &limit, &limits_tbl[i]); |
597 | } else { | 638 | } else { |
598 | rlim_t val = RLIM_INFINITY; | 639 | rlim_t val = RLIM_INFINITY; |