Skip to content

Commit

Permalink
getconf builtin: fix a bunch of missing and inaccurate values
Browse files Browse the repository at this point in the history
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
McDutchie committed Feb 9, 2024
1 parent 32950af commit 5948b42
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ This documents significant changes in the dev branch of ksh 93u+m.
For full details, see the git log at: https://github.com/ksh93/ksh
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.

2024-02-09:

- Fixed multiple inaccurate or missing values in the /opt/ast/bin/getconf
path-bound built-in command.

2024-02-08:

- Fixed an init-time crash that may occur if standard error is on a terminal,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.1.0-alpha" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2024-02-08" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2024-02-09" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2024 Contributors to ksh " SH_RELEASE_FORK

/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
Expand Down
21 changes: 3 additions & 18 deletions src/lib/libast/comp/conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# This software is part of the ast package #
# Copyright (c) 1985-2011 AT&T Intellectual Property #
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down Expand Up @@ -249,9 +249,6 @@ case $append$extra in
esac
;;
*) values=$values$sp$1
case $1 in
$sym) echo "$1" >> $tmp.v ;;
esac
;;
esac
done
Expand Down Expand Up @@ -799,8 +796,6 @@ do eval name=\"'$'CONF_name_$key\"
done > $tmp.q
sort -u < $tmp.q > $tmp.t
mv $tmp.t $tmp.q
sort -u < $tmp.v > $tmp.t
mv $tmp.t $tmp.v
case $debug in
-d4) exit ;;
esac
Expand Down Expand Up @@ -862,7 +857,6 @@ case $verbose in
1) echo "$command: check macros/enums as static initializers" >&2 ;;
esac
defined $tmp.q
defined $tmp.v
case $debug in
-d5) exit ;;
esac
Expand All @@ -873,10 +867,6 @@ exec < $tmp.q
while read line
do eval CONF_const_${line}=1
done
exec < $tmp.v
while read line
do eval CONF_const_${line}=1
done

# mark the string literal values

Expand Down Expand Up @@ -1061,13 +1051,8 @@ do eval name=\"'$'CONF_name_$key\"
conf_limit=0
case $flags in
*[Ll]*) d=
case ${conf_name} in
LONG_MAX|SSIZE_MAX)
x=
;;
*) eval x='$'CONF_const_${conf_name}
;;
esac
# always probe, even if a CONF_const_${conf_name} variable exists
x=
case $x in
'') for s in ${values}
do case $s in
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/comp/conf.tab
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ENH_I18N XOPEN SC 1 FSUW
EQUIV_CLASS_MAX C QQ 1 L
EXEC_INTERPRETER_LENGTH C QQ 1 L
EXPR_NEST_MAX POSIX SC 2 LMN 32
FCHR_MAX SVID SC 1 LMU LONG_MAX 2147483647
FCHR_MAX SVID SC 1 LMU SSIZE_MAX 2147483647
FILESIZEBITS POSIX PC 1 LMU (8*sizeof(off_t)) 32
FILE_LOCKING POSIX SC 1 FU
FORT_DEV POSIX SC 2 CFUW
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libcmd/getconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

static const char usage[] =
"[-?\n@(#)$Id: getconf (ksh 93u+m) 2021-04-20 $\n]"
"[-?\n@(#)$Id: getconf (ksh 93u+m) 2024-02-09 $\n]"
"[--catalog?" ERROR_CATALOG "]"
"[+NAME?getconf - get configuration values]"
"[+DESCRIPTION?\bgetconf\b displays the system configuration value for"
Expand Down

0 comments on commit 5948b42

Please sign in to comment.