diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-28 11:20:09 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-28 11:20:09 +0200 |
commit | 57e1b0ad5ebd77705841fbcd01a79f2552fbab8e (patch) | |
tree | bebc5fbbabb9d6d92304bab0d0f850cafb3e4965 /shell/shell_common.c | |
parent | a92a9601f89d59597b268e29e7098597a8766778 (diff) | |
download | busybox-w32-57e1b0ad5ebd77705841fbcd01a79f2552fbab8e.tar.gz busybox-w32-57e1b0ad5ebd77705841fbcd01a79f2552fbab8e.tar.bz2 busybox-w32-57e1b0ad5ebd77705841fbcd01a79f2552fbab8e.zip |
ash,hush: bash compat for ulimit: reorder to match
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/shell_common.c')
-rw-r--r-- | shell/shell_common.c | 125 |
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 { | |||
339 | }; | 339 | }; |
340 | 340 | ||
341 | static const struct limits limits_tbl[] = { | 341 | static const struct limits limits_tbl[] = { |
342 | /* No RLIMIT_FSIZE define guard since -f is the default limit and this must exist */ | 342 | { RLIMIT_CORE, 9, "core file size (blocks)" }, // -c |
343 | { RLIMIT_DATA, 10, "data seg size (kb)" }, // -d | ||
344 | { RLIMIT_NICE, 0, "scheduling priority" }, // -e | ||
343 | { RLIMIT_FSIZE, 9, "file size (blocks)" }, // -f | 345 | { RLIMIT_FSIZE, 9, "file size (blocks)" }, // -f |
344 | #ifdef RLIMIT_CPU | 346 | #define LIMIT_F_IDX 3 |
345 | { RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t | 347 | #ifdef RLIMIT_MEMLOCK |
348 | { RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l | ||
346 | #endif | 349 | #endif |
347 | #ifdef RLIMIT_DATA | 350 | #ifdef RLIMIT_RSS |
348 | { RLIMIT_DATA, 10, "data seg size (kb)" }, // -d | 351 | { RLIMIT_RSS, 10, "max memory size (kb)" }, // -m |
349 | #endif | 352 | #endif |
350 | #ifdef RLIMIT_STACK | 353 | #ifdef RLIMIT_NOFILE |
351 | { RLIMIT_STACK, 10, "stack size (kb)" }, // -s | 354 | { RLIMIT_NOFILE, 0, "open files" }, // -n |
352 | #endif | 355 | #endif |
353 | #ifdef RLIMIT_CORE | 356 | #ifdef RLIMIT_RTPRIO |
354 | { RLIMIT_CORE, 9, "core file size (blocks)" }, // -c | 357 | { RLIMIT_RTPRIO, 0, "real-time priority" }, // -r |
355 | #endif | 358 | #endif |
356 | #ifdef RLIMIT_RSS | 359 | #ifdef RLIMIT_STACK |
357 | { RLIMIT_RSS, 10, "max memory size (kb)" }, // -m | 360 | { RLIMIT_STACK, 10, "stack size (kb)" }, // -s |
358 | #endif | 361 | #endif |
359 | #ifdef RLIMIT_MEMLOCK | 362 | #ifdef RLIMIT_CPU |
360 | { RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l | 363 | { RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t |
361 | #endif | 364 | #endif |
362 | #ifdef RLIMIT_NPROC | 365 | #ifdef RLIMIT_NPROC |
363 | { RLIMIT_NPROC, 0, "max user processes" }, // -u | 366 | { RLIMIT_NPROC, 0, "max user processes" }, // -u |
364 | #endif | 367 | #endif |
365 | #ifdef RLIMIT_NOFILE | ||
366 | { RLIMIT_NOFILE, 0, "open files" }, // -n | ||
367 | #endif | ||
368 | #ifdef RLIMIT_AS | 368 | #ifdef RLIMIT_AS |
369 | { RLIMIT_AS, 10, "virtual memory (kb)" }, // -v | 369 | { RLIMIT_AS, 10, "virtual memory (kb)" }, // -v |
370 | #endif | 370 | #endif |
371 | #ifdef RLIMIT_LOCKS | 371 | #ifdef RLIMIT_LOCKS |
372 | { RLIMIT_LOCKS, 0, "file locks" }, // -x | 372 | { RLIMIT_LOCKS, 0, "file locks" }, // -x |
373 | #endif | 373 | #endif |
374 | #ifdef RLIMIT_NICE | ||
375 | { RLIMIT_NICE, 0, "scheduling priority" }, // -e | ||
376 | #endif | ||
377 | #ifdef RLIMIT_RTPRIO | ||
378 | { RLIMIT_RTPRIO, 0, "real-time priority" }, // -r | ||
379 | #endif | ||
380 | }; | 374 | }; |
381 | // bash also has these: | 375 | // bash also has these: |
382 | //pending signals (-i) 61858 //RLIMIT_SIGPENDING | 376 | //pending signals (-i) 61858 //RLIMIT_SIGPENDING |
@@ -384,85 +378,73 @@ static const struct limits limits_tbl[] = { | |||
384 | //POSIX message queues (bytes, -q) 819200 //RLIMIT_MSGQUEUE | 378 | //POSIX message queues (bytes, -q) 819200 //RLIMIT_MSGQUEUE |
385 | 379 | ||
386 | static const char limit_chars[] ALIGN1 = | 380 | static const char limit_chars[] ALIGN1 = |
381 | "c" | ||
382 | "d" | ||
383 | "e" | ||
387 | "f" | 384 | "f" |
388 | #ifdef RLIMIT_CPU | 385 | #ifdef RLIMIT_MEMLOCK |
389 | "t" | 386 | "l" |
390 | #endif | 387 | #endif |
391 | #ifdef RLIMIT_DATA | 388 | #ifdef RLIMIT_RSS |
392 | "d" | 389 | "m" |
393 | #endif | 390 | #endif |
394 | #ifdef RLIMIT_STACK | 391 | #ifdef RLIMIT_NOFILE |
395 | "s" | 392 | "n" |
396 | #endif | 393 | #endif |
397 | #ifdef RLIMIT_CORE | 394 | #ifdef RLIMIT_RTPRIO |
398 | "c" | 395 | "r" |
399 | #endif | 396 | #endif |
400 | #ifdef RLIMIT_RSS | 397 | #ifdef RLIMIT_STACK |
401 | "m" | 398 | "s" |
402 | #endif | 399 | #endif |
403 | #ifdef RLIMIT_MEMLOCK | 400 | #ifdef RLIMIT_CPU |
404 | "l" | 401 | "t" |
405 | #endif | 402 | #endif |
406 | #ifdef RLIMIT_NPROC | 403 | #ifdef RLIMIT_NPROC |
407 | "u" | 404 | "u" |
408 | #endif | 405 | #endif |
409 | #ifdef RLIMIT_NOFILE | ||
410 | "n" | ||
411 | #endif | ||
412 | #ifdef RLIMIT_AS | 406 | #ifdef RLIMIT_AS |
413 | "v" | 407 | "v" |
414 | #endif | 408 | #endif |
415 | #ifdef RLIMIT_LOCKS | 409 | #ifdef RLIMIT_LOCKS |
416 | "x" | 410 | "x" |
417 | #endif | 411 | #endif |
418 | #ifdef RLIMIT_NICE | ||
419 | "e" | ||
420 | #endif | ||
421 | #ifdef RLIMIT_RTPRIO | ||
422 | "r" | ||
423 | #endif | ||
424 | ; | 412 | ; |
425 | 413 | ||
426 | /* "-": treat args as parameters of option with ASCII code 1 */ | 414 | /* "-": treat args as parameters of option with ASCII code 1 */ |
427 | static const char ulimit_opt_string[] ALIGN1 = "-HSa" | 415 | static const char ulimit_opt_string[] ALIGN1 = "-HSa" |
416 | "c::" | ||
417 | "d::" | ||
418 | "e::" | ||
428 | "f::" | 419 | "f::" |
429 | #ifdef RLIMIT_CPU | 420 | #ifdef RLIMIT_MEMLOCK |
430 | "t::" | 421 | "l::" |
431 | #endif | 422 | #endif |
432 | #ifdef RLIMIT_DATA | 423 | #ifdef RLIMIT_RSS |
433 | "d::" | 424 | "m::" |
434 | #endif | 425 | #endif |
435 | #ifdef RLIMIT_STACK | 426 | #ifdef RLIMIT_NOFILE |
436 | "s::" | 427 | "n::" |
437 | #endif | 428 | #endif |
438 | #ifdef RLIMIT_CORE | 429 | #ifdef RLIMIT_RTPRIO |
439 | "c::" | 430 | "r::" |
440 | #endif | 431 | #endif |
441 | #ifdef RLIMIT_RSS | 432 | #ifdef RLIMIT_STACK |
442 | "m::" | 433 | "s::" |
443 | #endif | 434 | #endif |
444 | #ifdef RLIMIT_MEMLOCK | 435 | #ifdef RLIMIT_CPU |
445 | "l::" | 436 | "t::" |
446 | #endif | 437 | #endif |
447 | #ifdef RLIMIT_NPROC | 438 | #ifdef RLIMIT_NPROC |
448 | "u::" | 439 | "u::" |
449 | #endif | 440 | #endif |
450 | #ifdef RLIMIT_NOFILE | ||
451 | "n::" | ||
452 | #endif | ||
453 | #ifdef RLIMIT_AS | 441 | #ifdef RLIMIT_AS |
454 | "v::" | 442 | "v::" |
455 | #endif | 443 | #endif |
456 | #ifdef RLIMIT_LOCKS | 444 | #ifdef RLIMIT_LOCKS |
457 | "x::" | 445 | "x::" |
458 | #endif | 446 | #endif |
459 | #ifdef RLIMIT_NICE | 447 | ; |
460 | "e::" | ||
461 | #endif | ||
462 | #ifdef RLIMIT_RTPRIO | ||
463 | "r::" | ||
464 | #endif | ||
465 | ; | ||
466 | 448 | ||
467 | enum { | 449 | enum { |
468 | OPT_hard = (1 << 0), | 450 | OPT_hard = (1 << 0), |
@@ -595,11 +577,10 @@ shell_builtin_ulimit(char **argv) | |||
595 | continue; | 577 | continue; |
596 | //if (opt_char == 'a') - impossible | 578 | //if (opt_char == 'a') - impossible |
597 | 579 | ||
598 | i = 0; /* if "ulimit NNN", -f is assumed */ | 580 | if (opt_char == 1) /* if "ulimit NNN", -f is assumed */ |
599 | if (opt_char != 1) { | 581 | opt_char = 'f'; |
600 | i = strchrnul(limit_chars, opt_char) - limit_chars; | 582 | i = strchrnul(limit_chars, opt_char) - limit_chars; |
601 | //if (i >= ARRAY_SIZE(limits_tbl)) - bad option, impossible | 583 | //if (i >= ARRAY_SIZE(limits_tbl)) - bad option, impossible |
602 | } | ||
603 | 584 | ||
604 | val_str = optarg; | 585 | val_str = optarg; |
605 | if (!val_str && argv[optind] && argv[optind][0] != '-') | 586 | if (!val_str && argv[optind] && argv[optind][0] != '-') |
@@ -643,8 +624,8 @@ shell_builtin_ulimit(char **argv) | |||
643 | 624 | ||
644 | if (opt_cnt == 0) { | 625 | if (opt_cnt == 0) { |
645 | /* "bare ulimit": treat it as if it was -f */ | 626 | /* "bare ulimit": treat it as if it was -f */ |
646 | getrlimit(limits_tbl[0].cmd, &limit); | 627 | getrlimit(limits_tbl[LIMIT_F_IDX].cmd, &limit); |
647 | printlim(opts, &limit, &limits_tbl[0]); | 628 | printlim(opts, &limit, &limits_tbl[LIMIT_F_IDX]); |
648 | } | 629 | } |
649 | 630 | ||
650 | return EXIT_SUCCESS; | 631 | return EXIT_SUCCESS; |