On Sun, Jan 14 2018, Anton Lindqvist wrote:
> Hi,
> Stop constructing the optstring passed to ksh_getopt() for ulimit at
> runtime. While here remove ifdef RLIMIT_VMEM block since it's not
> defined.
>
> Comments? OK?
Regarding RLIMIT_VMEM, APUE says it is available on FreeBSD and Solaris
9, and that it is a synonym for RLIMIT_AS, which we don't provide
either. ok jca@ to remove it.
Regarding the opt string handling, that's a case of slightly more
complex code vs. mild information duplication. I don't care much either
way. Comment inline,
> Index: c_ulimit.c
> ===
> RCS file: /cvs/src/bin/ksh/c_ulimit.c,v
> retrieving revision 1.24
> diff -u -p -r1.24 c_ulimit.c
> --- c_ulimit.c14 Dec 2015 13:59:42 - 1.24
> +++ c_ulimit.c14 Jan 2018 16:12:33 -
> @@ -53,27 +53,14 @@ c_ulimit(char **wp)
> { "memory(kbytes)", RLIMIT_RSS, 1024, 'm' },
> { "nofiles(descriptors)", RLIMIT_NOFILE, 1, 'n' },
> { "processes", RLIMIT_NPROC, 1, 'p' },
> -#ifdef RLIMIT_VMEM
> - { "vmemory(kbytes)", RLIMIT_VMEM, 1024, 'v' },
> -#endif /* RLIMIT_VMEM */
> { NULL }
> };
> - static char options[4 + NELEM(limits) * 2];
> + static const char *options = "HSat#f#c#d#s#l#m#n#p#";
"static" would not be needed any more.
> int how = SOFT | HARD;
> const struct limits *l;
> int optc, all = 0;
>
> - if (!options[0]) {
> - /* build options string on first call - yuck */
> - char *p = options;
>
> - *p++ = 'H'; *p++ = 'S'; *p++ = 'a';
> - for (l = limits; l->name; l++) {
> - *p++ = l->option;
> - *p++ = '#';
> - }
> - *p = '\0';
> - }
> /* First check for -a, -H and -S. */
> while ((optc = ksh_getopt(wp, &builtin_opt, options)) != -1)
> switch (optc) {
>
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE