1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Use dynamic maximum configuration values when necessary (#370)

This commit fixes an issue with how ksh was obtaining the value of
NGROUPS_MAX. On some systems this setting can be changed (e.g., on
illumos adding 'set ngroups_max=32' to /etc/system then rebooting
changes NGROUPS_MAX from 16 to 32). Ksh was using NGROUPS_MAX with
the assumption it's a static value, which could cause issues on
systems where it isn't static. This bugfix is inspired by the one
from <b1362c3a5>, although it
has been expanded a bit to account for OPEN_MAX as well.

src/cmd/ksh93/sh/init.c, src/lib/libcmd/fds.c:
- Rename the getconf() macro to astconf_long() and move it to ast.h
  to prevent redundancy. Other sections of the code have been
  modified to use this macro for astconf() to account for
  dynamic settings.
- An equivalent macro for unsigned long values (astconf_ulong) has
  been added.
- Prefer sysconf(3) where available. It has better performance as it
  returns a numeric value directly instead of via string
  conversion.
- The astconf_long and astconf_ulong macros have been documented in
  the ast(3) man page.
This commit is contained in:
Johnothan King 2021-12-12 22:51:59 -08:00 committed by Martijn Dekker
parent fc752b574a
commit c2ac69b2d5
15 changed files with 81 additions and 27 deletions

View file

@ -54,9 +54,6 @@ static const char usage[] =
#define major(x) (int)(((unsigned int)(x)>>8)&0xff)
#endif
#undef getconf
#define getconf(x) strtol(astconf(x,NiL,NiL),NiL,0)
#ifdef S_IFSOCK
typedef struct NV_s
@ -214,8 +211,14 @@ b_fds(int argc, char** argv, Shbltin_t* context)
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if ((open_max = getconf("OPEN_MAX")) <= 0)
if ((open_max = (int)astconf_long(CONF_OPEN_MAX)) <= 0)
{
#if defined(OPEN_MAX)
open_max = OPEN_MAX;
#else
open_max = FOPEN_MAX;
#endif
}
if (unit == 1)
sp = sfstdout;
else if (fstat(unit, &st) || !(sp = sfnew(NiL, NiL, SF_UNBOUND, unit, SF_WRITE)))

View file

@ -231,7 +231,7 @@ getids(Sfio_t* sp, const char* name, register int flags)
*/
if ((maxgroups = getgroups(0, groups)) <= 0)
maxgroups = NGROUPS_MAX;
maxgroups = (int)astconf_long(CONF_NGROUPS_MAX);
if (!(groups = newof(0, gid_t, maxgroups + 1, 0)))
{
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory [group array]");