Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getconf builtin: fix a bunch of missing and inaccurate values
Regression test failure on NetBSD: test return begins at 2024-02-09+07:26:55 getconf: INT_MAX: unknown variable return.sh[256]: FAIL: return fails to warn for INT_MAX+1 (expected status 128 and *': out of range', got status 1 and '') The problem is that the getconf builtin (bound to the path /opt/ast/bin/getconf) did not return a value for INT_MAX, though it is listed in src/lib/libast/comp/comf.tab. Turns out that this problem exists everywhere, not just on NetBSD. But, on most systems, the problem is masked by the fact that the getconf builtin will defer to the external standard getconf command, which usually does know it. But the NetBSD one doesn't. I found other missing values, e.g. SHRT_MAX (but not INT_MIN or SHRT_MIN!). And some wrong ones as well, like on macOS or FreeBSD: $ /opt/ast/bin/getconf SSIZE_MAX 2147483647 $ /usr/bin/getconf SSIZE_MAX 9223372036854775807 After hours of trying to debug conf.sh, which generates the information used by the getconf builtin, I found that the way that the $tmp.v temporary file is uses makes no sense. It contains words that looks like identifiers, scanned from default values of entries in conf.tab. Each such identifier then gets a corresponding CONF_const_${identifier} variable set, which then (on line 1068 and on) stops any probe from happening. As a result, no value is detected, which is incorrect. (This also explains why INT_MIN works whereas INT_MAX doesn't.) On line 1065, we find two variables exempted: case ${conf_name} in LONG_MAX|SSIZE_MAX) x= ;; Emptying the 'x' variable causes the probe to happen for these two. Sure enough, removing this special-casing introduces the same problem for LONG_MAX as well: not found by the built-in. After experimenting I am seeing no reason why this probe should not simply always happen. This appears to be another case where removing code fixes a bug. src/lib/libast/comp/conf.sh: - Remove $tmp.v code that scans values for words looking like IDs and sets CONF_const_${ID} variables based on them. This should only happen for the actual IDs in conf.tab (first column), not their default values. - Remove special-casing. Always probe, even if a CONF_const_${ID} variable exists. src/lib/libast/comp/conf.tab: - Update FCHR_MAX (max file size) default from LONG_MAX to SSIZE_MAX to avoid the value changing after the above change. On macOS, the following are now corrected (verified with 'ksh -r' as restricted mode currently stops fallback to /usr/bin/getconf): * getconf CHARCLASS_NAME_MAX: was absent, now 14 * getconf INT_MAX: was absent, now 2147483647 * getconf LONG_BIT: was absent, now 64 * getconf NL_ARGMAX: was absent, now 9 * getconf NL_LANGMAX: was absent, now 14 * getconf NL_MSGMAX: was absent, now 32767 * getconf NL_NMAX: was absent, now 1 * getconf NL_SETMAX: was absent, now 255 * getconf NL_TEXTMAX: was absent, now 2048 * getconf NZERO: was absent, now 20 * getconf PTHREAD_DESTRUCTOR_ITERATIONS: was absent, now 4 * getconf PTHREAD_KEYS_MAX: was absent, now 512 * getconf SHRT_MAX: was absent, now 32767 * getconf SIZE_MAX: was 4294967295, now 18446744073709551615 * getconf SSIZE_MAX: was 2147483647, now 9223372036854775807 * getconf UID_MAX: was 60002, now 2147483647 * getconf UINT_MAX: was absent, now 4294967295 * getconf WORD_BIT: was absent, now 32
- Loading branch information