shell_common.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Adapted from ash applet code
  4. *
  5. * This code is derived from software contributed to Berkeley by
  6. * Kenneth Almquist.
  7. *
  8. * Copyright (c) 1989, 1991, 1993, 1994
  9. * The Regents of the University of California. All rights reserved.
  10. *
  11. * Copyright (c) 1997-2005 Herbert Xu <herbert@gondor.apana.org.au>
  12. * was re-ported from NetBSD and debianized.
  13. *
  14. * Copyright (c) 2010 Denys Vlasenko
  15. * Split from ash.c
  16. *
  17. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  18. */
  19. #include "libbb.h"
  20. #include "shell_common.h"
  21. const char defifsvar[] ALIGN1 = "IFS= \t\n";
  22. const char defoptindvar[] ALIGN1 = "OPTIND=1";
  23. /* read builtin */
  24. /* Needs to be interruptible: shell must handle traps and shell-special signals
  25. * while inside read. To implement this, be sure to not loop on EINTR
  26. * and return errno == EINTR reliably.
  27. */
  28. //TODO: use more efficient setvar() which takes a pointer to malloced "VAR=VAL"
  29. //string. hush naturally has it, and ash has setvareq().
  30. //Here we can simply store "VAR=" at buffer start and store read data directly
  31. //after "=", then pass buffer to setvar() to consume.
  32. const char* FAST_FUNC
  33. shell_builtin_read(struct builtin_read_params *params)
  34. {
  35. struct pollfd pfd[1];
  36. #define fd (pfd[0].fd) /* -u FD */
  37. unsigned err;
  38. unsigned end_ms; /* -t TIMEOUT */
  39. int nchars; /* -n NUM */
  40. char **pp;
  41. char *buffer;
  42. char delim;
  43. struct termios tty, old_tty;
  44. const char *retval;
  45. int bufpos; /* need to be able to hold -1 */
  46. int startword;
  47. smallint backslash;
  48. char **argv;
  49. const char *ifs;
  50. int read_flags;
  51. errno = err = 0;
  52. argv = params->argv;
  53. pp = argv;
  54. while (*pp) {
  55. if (endofname(*pp)[0] != '\0') {
  56. /* Mimic bash message */
  57. bb_error_msg("read: '%s': not a valid identifier", *pp);
  58. return (const char *)(uintptr_t)1;
  59. }
  60. pp++;
  61. }
  62. nchars = 0; /* if != 0, -n is in effect */
  63. if (params->opt_n) {
  64. nchars = bb_strtou(params->opt_n, NULL, 10);
  65. if (nchars < 0 || errno)
  66. return "invalid count";
  67. /* note: "-n 0": off (bash 3.2 does this too) */
  68. }
  69. end_ms = 0;
  70. if (params->opt_t && !ENABLE_FEATURE_SH_READ_FRAC) {
  71. end_ms = bb_strtou(params->opt_t, NULL, 10);
  72. if (errno)
  73. return "invalid timeout";
  74. if (end_ms > UINT_MAX / 2048) /* be safely away from overflow */
  75. end_ms = UINT_MAX / 2048;
  76. end_ms *= 1000;
  77. }
  78. if (params->opt_t && ENABLE_FEATURE_SH_READ_FRAC) {
  79. /* bash 4.3 (maybe earlier) supports -t N.NNNNNN */
  80. char *p;
  81. /* Eat up to three fractional digits */
  82. int frac_digits = 3 + 1;
  83. end_ms = bb_strtou(params->opt_t, &p, 10);
  84. if (end_ms > UINT_MAX / 2048) /* be safely away from overflow */
  85. end_ms = UINT_MAX / 2048;
  86. if (errno) {
  87. /* EINVAL = number is ok, but not NUL terminated */
  88. if (errno != EINVAL || *p != '.')
  89. return "invalid timeout";
  90. /* Do not check the rest: bash allows "0.123456xyz" */
  91. while (*++p && --frac_digits) {
  92. end_ms *= 10;
  93. end_ms += (*p - '0');
  94. if ((unsigned char)(*p - '0') > 9)
  95. return "invalid timeout";
  96. }
  97. }
  98. while (--frac_digits > 0) {
  99. end_ms *= 10;
  100. }
  101. }
  102. fd = STDIN_FILENO;
  103. if (params->opt_u) {
  104. fd = bb_strtou(params->opt_u, NULL, 10);
  105. if (fd < 0 || errno)
  106. return "invalid file descriptor";
  107. }
  108. if (params->opt_t && end_ms == 0) {
  109. /* "If timeout is 0, read returns immediately, without trying
  110. * to read any data. The exit status is 0 if input is available
  111. * on the specified file descriptor, non-zero otherwise."
  112. * bash seems to ignore -p PROMPT for this use case.
  113. */
  114. int r;
  115. pfd[0].events = POLLIN;
  116. r = poll(pfd, 1, /*timeout:*/ 0);
  117. /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */
  118. return (const char *)(uintptr_t)(r <= 0);
  119. }
  120. if (params->opt_p && isatty(fd)) {
  121. fputs(params->opt_p, stderr);
  122. fflush_all();
  123. }
  124. ifs = params->ifs;
  125. if (ifs == NULL)
  126. ifs = defifs;
  127. read_flags = params->read_flags;
  128. if (nchars || (read_flags & BUILTIN_READ_SILENT)) {
  129. tcgetattr(fd, &tty);
  130. old_tty = tty;
  131. if (nchars) {
  132. tty.c_lflag &= ~ICANON;
  133. // Setting it to more than 1 breaks poll():
  134. // it blocks even if there's data. !??
  135. //tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
  136. /* reads will block only if < 1 char is available */
  137. tty.c_cc[VMIN] = 1;
  138. /* no timeout (reads block forever) */
  139. tty.c_cc[VTIME] = 0;
  140. }
  141. if (read_flags & BUILTIN_READ_SILENT) {
  142. tty.c_lflag &= ~(ECHO | ECHOK | ECHONL);
  143. }
  144. /* This forces execution of "restoring" tcgetattr later */
  145. read_flags |= BUILTIN_READ_SILENT;
  146. /* if tcgetattr failed, tcsetattr will fail too.
  147. * Ignoring, it's harmless. */
  148. tcsetattr(fd, TCSANOW, &tty);
  149. }
  150. retval = (const char *)(uintptr_t)0;
  151. startword = 1;
  152. backslash = 0;
  153. if (params->opt_t)
  154. end_ms += (unsigned)monotonic_ms();
  155. buffer = NULL;
  156. bufpos = 0;
  157. delim = params->opt_d ? params->opt_d[0] : '\n';
  158. do {
  159. char c;
  160. int timeout;
  161. if ((bufpos & 0xff) == 0)
  162. buffer = xrealloc(buffer, bufpos + 0x101);
  163. timeout = -1;
  164. if (params->opt_t) {
  165. timeout = end_ms - (unsigned)monotonic_ms();
  166. /* ^^^^^^^^^^^^^ all values are unsigned,
  167. * wrapping math is used here, good even if
  168. * 32-bit unix time wrapped (year 2038+).
  169. */
  170. if (timeout <= 0) { /* already late? */
  171. retval = (const char *)(uintptr_t)1;
  172. goto ret;
  173. }
  174. }
  175. /* We must poll even if timeout is -1:
  176. * we want to be interrupted if signal arrives,
  177. * regardless of SA_RESTART-ness of that signal!
  178. */
  179. errno = 0;
  180. pfd[0].events = POLLIN;
  181. if (poll(pfd, 1, timeout) <= 0) {
  182. /* timed out, or EINTR */
  183. err = errno;
  184. retval = (const char *)(uintptr_t)1;
  185. goto ret;
  186. }
  187. if (read(fd, &buffer[bufpos], 1) != 1) {
  188. err = errno;
  189. retval = (const char *)(uintptr_t)1;
  190. break;
  191. }
  192. c = buffer[bufpos];
  193. if (c == '\0')
  194. continue;
  195. if (!(read_flags & BUILTIN_READ_RAW)) {
  196. if (backslash) {
  197. backslash = 0;
  198. if (c != '\n')
  199. goto put;
  200. continue;
  201. }
  202. if (c == '\\') {
  203. backslash = 1;
  204. continue;
  205. }
  206. }
  207. if (c == delim) /* '\n' or -d CHAR */
  208. break;
  209. /* $IFS splitting. NOT done if we run "read"
  210. * without variable names (bash compat).
  211. * Thus, "read" and "read REPLY" are not the same.
  212. */
  213. if (!params->opt_d && argv[0]) {
  214. /* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 */
  215. const char *is_ifs = strchr(ifs, c);
  216. if (startword && is_ifs) {
  217. if (isspace(c))
  218. continue;
  219. /* it is a non-space ifs char */
  220. startword--;
  221. if (startword == 1) /* first one? */
  222. continue; /* yes, it is not next word yet */
  223. }
  224. startword = 0;
  225. if (argv[1] != NULL && is_ifs) {
  226. buffer[bufpos] = '\0';
  227. bufpos = 0;
  228. params->setvar(*argv, buffer);
  229. argv++;
  230. /* can we skip one non-space ifs char? (2: yes) */
  231. startword = isspace(c) ? 2 : 1;
  232. continue;
  233. }
  234. }
  235. put:
  236. bufpos++;
  237. } while (--nchars);
  238. if (argv[0]) {
  239. /* Remove trailing space $IFS chars */
  240. while (--bufpos >= 0
  241. && isspace(buffer[bufpos])
  242. && strchr(ifs, buffer[bufpos]) != NULL
  243. ) {
  244. continue;
  245. }
  246. buffer[bufpos + 1] = '\0';
  247. /* Last variable takes the entire remainder with delimiters
  248. * (sans trailing whitespace $IFS),
  249. * but ***only "if there are fewer vars than fields"(c)***!
  250. * The "X:Y:" case below: there are two fields,
  251. * and therefore last delimiter (:) is eaten:
  252. * IFS=": "
  253. * echo "X:Y:Z:" | (read x y; echo "|$x|$y|") # |X|Y:Z:|
  254. * echo "X:Y:Z" | (read x y; echo "|$x|$y|") # |X|Y:Z|
  255. * echo "X:Y:" | (read x y; echo "|$x|$y|") # |X|Y|, not |X|Y:|
  256. * echo "X:Y : " | (read x y; echo "|$x|$y|") # |X|Y|
  257. */
  258. if (bufpos >= 0
  259. && strchr(ifs, buffer[bufpos]) != NULL
  260. ) {
  261. /* There _is_ a non-whitespace IFS char */
  262. /* Skip whitespace IFS char before it */
  263. while (--bufpos >= 0
  264. && isspace(buffer[bufpos])
  265. && strchr(ifs, buffer[bufpos]) != NULL
  266. ) {
  267. continue;
  268. }
  269. /* Are there $IFS chars? */
  270. if (strcspn(buffer, ifs) >= ++bufpos) {
  271. /* No: last var takes one field, not more */
  272. /* So, drop trailing IFS delims */
  273. buffer[bufpos] = '\0';
  274. }
  275. }
  276. /* Use the remainder as a value for the next variable */
  277. params->setvar(*argv, buffer);
  278. /* Set the rest to "" */
  279. while (*++argv)
  280. params->setvar(*argv, "");
  281. } else {
  282. /* Note: no $IFS removal */
  283. buffer[bufpos] = '\0';
  284. params->setvar("REPLY", buffer);
  285. }
  286. ret:
  287. free(buffer);
  288. if (read_flags & BUILTIN_READ_SILENT)
  289. tcsetattr(fd, TCSANOW, &old_tty);
  290. errno = err;
  291. return retval;
  292. #undef fd
  293. }
  294. /* ulimit builtin */
  295. struct limits {
  296. uint8_t cmd; /* RLIMIT_xxx fit into it */
  297. uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */
  298. const char *name;
  299. };
  300. static const struct limits limits_tbl[] = {
  301. { RLIMIT_CORE, 9, "core file size (blocks)" }, // -c
  302. { RLIMIT_DATA, 10, "data seg size (kb)" }, // -d
  303. { RLIMIT_NICE, 0, "scheduling priority" }, // -e
  304. { RLIMIT_FSIZE, 9, "file size (blocks)" }, // -f
  305. #define LIMIT_F_IDX 3
  306. #ifdef RLIMIT_SIGPENDING
  307. { RLIMIT_SIGPENDING, 0, "pending signals" }, // -i
  308. #endif
  309. #ifdef RLIMIT_MEMLOCK
  310. { RLIMIT_MEMLOCK, 10, "max locked memory (kb)" }, // -l
  311. #endif
  312. #ifdef RLIMIT_RSS
  313. { RLIMIT_RSS, 10, "max memory size (kb)" }, // -m
  314. #endif
  315. #ifdef RLIMIT_NOFILE
  316. { RLIMIT_NOFILE, 0, "open files" }, // -n
  317. #endif
  318. #ifdef RLIMIT_MSGQUEUE
  319. { RLIMIT_MSGQUEUE, 0, "POSIX message queues (bytes)" }, // -q
  320. #endif
  321. #ifdef RLIMIT_RTPRIO
  322. { RLIMIT_RTPRIO, 0, "real-time priority" }, // -r
  323. #endif
  324. #ifdef RLIMIT_STACK
  325. { RLIMIT_STACK, 10, "stack size (kb)" }, // -s
  326. #endif
  327. #ifdef RLIMIT_CPU
  328. { RLIMIT_CPU, 0, "cpu time (seconds)" }, // -t
  329. #endif
  330. #ifdef RLIMIT_NPROC
  331. { RLIMIT_NPROC, 0, "max user processes" }, // -u
  332. #endif
  333. #ifdef RLIMIT_AS
  334. { RLIMIT_AS, 10, "virtual memory (kb)" }, // -v
  335. #endif
  336. #ifdef RLIMIT_LOCKS
  337. { RLIMIT_LOCKS, 0, "file locks" }, // -x
  338. #endif
  339. };
  340. // bash also shows:
  341. //pipe size (512 bytes, -p) 8
  342. static const char limit_chars[] ALIGN1 =
  343. "c"
  344. "d"
  345. "e"
  346. "f"
  347. #ifdef RLIMIT_SIGPENDING
  348. "i"
  349. #endif
  350. #ifdef RLIMIT_MEMLOCK
  351. "l"
  352. #endif
  353. #ifdef RLIMIT_RSS
  354. "m"
  355. #endif
  356. #ifdef RLIMIT_NOFILE
  357. "n"
  358. #endif
  359. #ifdef RLIMIT_MSGQUEUE
  360. "q"
  361. #endif
  362. #ifdef RLIMIT_RTPRIO
  363. "r"
  364. #endif
  365. #ifdef RLIMIT_STACK
  366. "s"
  367. #endif
  368. #ifdef RLIMIT_CPU
  369. "t"
  370. #endif
  371. #ifdef RLIMIT_NPROC
  372. "u"
  373. #endif
  374. #ifdef RLIMIT_AS
  375. "v"
  376. #endif
  377. #ifdef RLIMIT_LOCKS
  378. "x"
  379. #endif
  380. ;
  381. /* "-": treat args as parameters of option with ASCII code 1 */
  382. static const char ulimit_opt_string[] ALIGN1 = "-HSa"
  383. "c::"
  384. "d::"
  385. "e::"
  386. "f::"
  387. #ifdef RLIMIT_SIGPENDING
  388. "i::"
  389. #endif
  390. #ifdef RLIMIT_MEMLOCK
  391. "l::"
  392. #endif
  393. #ifdef RLIMIT_RSS
  394. "m::"
  395. #endif
  396. #ifdef RLIMIT_NOFILE
  397. "n::"
  398. #endif
  399. #ifdef RLIMIT_MSGQUEUE
  400. "q::"
  401. #endif
  402. #ifdef RLIMIT_RTPRIO
  403. "r::"
  404. #endif
  405. #ifdef RLIMIT_STACK
  406. "s::"
  407. #endif
  408. #ifdef RLIMIT_CPU
  409. "t::"
  410. #endif
  411. #ifdef RLIMIT_NPROC
  412. "u::"
  413. #endif
  414. #ifdef RLIMIT_AS
  415. "v::"
  416. #endif
  417. #ifdef RLIMIT_LOCKS
  418. "x::"
  419. #endif
  420. ;
  421. enum {
  422. OPT_hard = (1 << 0),
  423. OPT_soft = (1 << 1),
  424. OPT_all = (1 << 2),
  425. };
  426. static void printlim(unsigned opts, const struct rlimit *limit,
  427. const struct limits *l)
  428. {
  429. rlim_t val;
  430. val = limit->rlim_max;
  431. if (opts & OPT_soft)
  432. val = limit->rlim_cur;
  433. if (val == RLIM_INFINITY)
  434. puts("unlimited");
  435. else {
  436. val >>= l->factor_shift;
  437. printf("%llu\n", (long long) val);
  438. }
  439. }
  440. int FAST_FUNC
  441. shell_builtin_ulimit(char **argv)
  442. {
  443. struct rlimit limit;
  444. unsigned opt_cnt;
  445. unsigned opts;
  446. unsigned argc;
  447. unsigned i;
  448. /* We can't use getopt32: need to handle commands like
  449. * ulimit 123 -c2 -l 456
  450. */
  451. /* In case getopt() was already called:
  452. * reset libc getopt() internal state.
  453. */
  454. GETOPT_RESET();
  455. // bash 4.4.23:
  456. //
  457. // -H and/or -S change meaning even of options *before* them: ulimit -f 2000 -H
  458. // sets hard limit, ulimit -a -H prints hard limits.
  459. //
  460. // -a is equivalent for requesting all limits to be shown.
  461. //
  462. // If -a is specified, attempts to set limits are ignored:
  463. // ulimit -m 1000; ulimit -m 2000 -a
  464. // shows 1000, not 2000. HOWEVER, *implicit* -f form "ulimit 2000 -a"
  465. // DOES set -f limit [we don't implement this quirk], "ulimit -a 2000" does not.
  466. // Options are still parsed: ulimit -az complains about unknown -z opt.
  467. //
  468. // -a is not cumulative: "ulimit -a -a" = "ulimit -a -f -m" = "ulimit -a"
  469. //
  470. // -HSa can be combined in one argument and with one other option (example: -Sm),
  471. // but other options can't: limit value is an optional argument,
  472. // thus "-mf" means "-m f", f is the parameter of -m.
  473. //
  474. // Limit can be set and then printed: ulimit -m 2000 -m
  475. // If set more than once, they are set and printed in order:
  476. // try ulimit -m -m 1000 -m -m 2000 -m -m 3000 -m
  477. //
  478. // Limits are shown in the order of options given:
  479. // ulimit -m -f is not the same as ulimit -f -m.
  480. //
  481. // If both -S and -H are given, show soft limit.
  482. //
  483. // Short printout (limit value only) is printed only if just one option
  484. // is given: ulimit -m. ulimit -f -m prints verbose lines.
  485. // ulimit -f -f prints same verbose line twice.
  486. // ulimit -m 10000 -f prints verbose line for -f.
  487. argc = string_array_len(argv);
  488. /* First pass over options: detect -H/-S/-a status,
  489. * and "bare ulimit" and "only one option" cases
  490. * by counting other opts.
  491. */
  492. opt_cnt = 0;
  493. opts = 0;
  494. while (1) {
  495. int opt_char = getopt(argc, argv, ulimit_opt_string);
  496. if (opt_char == -1)
  497. break;
  498. if (opt_char == 'H') {
  499. opts |= OPT_hard;
  500. continue;
  501. }
  502. if (opt_char == 'S') {
  503. opts |= OPT_soft;
  504. continue;
  505. }
  506. if (opt_char == 'a') {
  507. opts |= OPT_all;
  508. continue;
  509. }
  510. if (opt_char == '?') {
  511. /* bad option. getopt already complained. */
  512. return EXIT_FAILURE;
  513. }
  514. opt_cnt++;
  515. } /* while (there are options) */
  516. if (!(opts & (OPT_hard | OPT_soft)))
  517. opts |= (OPT_hard | OPT_soft);
  518. if (opts & OPT_all) {
  519. for (i = 0; i < ARRAY_SIZE(limits_tbl); i++) {
  520. getrlimit(limits_tbl[i].cmd, &limit);
  521. printf("%-32s(-%c) ", limits_tbl[i].name, limit_chars[i]);
  522. printlim(opts, &limit, &limits_tbl[i]);
  523. }
  524. return EXIT_SUCCESS;
  525. }
  526. /* Second pass: set or print limits, in order */
  527. GETOPT_RESET();
  528. while (1) {
  529. char *val_str;
  530. int opt_char = getopt(argc, argv, ulimit_opt_string);
  531. if (opt_char == -1)
  532. break;
  533. if (opt_char == 'H')
  534. continue;
  535. if (opt_char == 'S')
  536. continue;
  537. //if (opt_char == 'a') - impossible
  538. if (opt_char == 1) /* if "ulimit NNN", -f is assumed */
  539. opt_char = 'f';
  540. i = strchrnul(limit_chars, opt_char) - limit_chars;
  541. //if (i >= ARRAY_SIZE(limits_tbl)) - bad option, impossible
  542. val_str = optarg;
  543. if (!val_str && argv[optind] && argv[optind][0] != '-')
  544. val_str = argv[optind++]; /* ++ skips NN in "-c NN" case */
  545. getrlimit(limits_tbl[i].cmd, &limit);
  546. if (!val_str) {
  547. if (opt_cnt > 1)
  548. printf("%-32s(-%c) ", limits_tbl[i].name, limit_chars[i]);
  549. printlim(opts, &limit, &limits_tbl[i]);
  550. } else {
  551. rlim_t val = RLIM_INFINITY;
  552. if (strcmp(val_str, "unlimited") != 0) {
  553. if (sizeof(val) == sizeof(int))
  554. val = bb_strtou(val_str, NULL, 10);
  555. else if (sizeof(val) == sizeof(long))
  556. val = bb_strtoul(val_str, NULL, 10);
  557. else
  558. val = bb_strtoull(val_str, NULL, 10);
  559. if (errno) {
  560. bb_error_msg("invalid number '%s'", val_str);
  561. return EXIT_FAILURE;
  562. }
  563. val <<= limits_tbl[i].factor_shift;
  564. }
  565. //bb_error_msg("opt %c val_str:'%s' val:%lld", opt_char, val_str, (long long)val);
  566. /* from man bash: "If neither -H nor -S
  567. * is specified, both the soft and hard
  568. * limits are set. */
  569. if (opts & OPT_hard)
  570. limit.rlim_max = val;
  571. if (opts & OPT_soft)
  572. limit.rlim_cur = val;
  573. //bb_error_msg("setrlimit(%d, %lld, %lld)", limits_tbl[i].cmd, (long long)limit.rlim_cur, (long long)limit.rlim_max);
  574. if (setrlimit(limits_tbl[i].cmd, &limit) < 0) {
  575. bb_perror_msg("error setting limit");
  576. return EXIT_FAILURE;
  577. }
  578. }
  579. } /* while (there are options) */
  580. if (opt_cnt == 0) {
  581. /* "bare ulimit": treat it as if it was -f */
  582. getrlimit(limits_tbl[LIMIT_F_IDX].cmd, &limit);
  583. printlim(opts, &limit, &limits_tbl[LIMIT_F_IDX]);
  584. }
  585. return EXIT_SUCCESS;
  586. }