Re: [PATCH] Catch errors properly, if whoami or who don't exist
Jacob Bachmeyer <[email protected]> Thu, 12 Sep 2024 21:33:23 -0500
| Newsgroups | gmane.comp.sysutils.dejagnu.general |
|---|---|
| Message-ID | <[email protected]> |
Stefan wrote:
> [...]
>
>>>> In fact, how are you even running the dejagnu(1) and runtest(1)
>>>> scripts if /bin/sh does not exist? Their #! lines refer to /bin/sh...
>
> In Guix there is an automatism to patch (only) all shebangs to the
> correct absolute paths.
So you patch every script instead of installing symlinks that allow
interpreters to be easily updated...
> If you search for “ sh ” usage across the DejaGnu source, then you
> will find plenty of places happily using sh without /bin/. But there
> is only this one usage of /bin/sh. So for consistency one might argue
> to change it.
A search of the source tree for " sh " finds exactly three code files in
DejaGnu containing that word: lib/remote.exp, lib/rsh.exp, and
lib/ssh.exp. Other files are either documentation or imported.
Notably, config.sub is actually matching the string "sh" in a case block
and configure only references " sh " while attempting to determine the
PATH_SEPARATOR (in a test that assumes that /bin exists, notably) and in
a list of names under which a POSIX shell might be found.
>>> POSIX says otherwise, you must not rely on the presence of /bin/sh;
>>> cf.
>>> <https://pubs.opengroup.org/onlinepubs/9799919799/utilities/sh.html#tag_20_110_16>.
>>> The path to the interpreter can be easily substituted e.g. with
>>> autoconf.
>
>> That is in an informative section; and it is indeed correct that
>> /bin/sh cannot be assumed to be a POSIX shell. The scripts that use
>> #!/bin/sh in DejaGnu avoid making such an assumption. That section
>> also says that you are supposed to be able to find a POSIX shell with
>> `command -v sh` but I suspect that Autoconf does considerably more
>> work than that to locate a suitable shell.
>
> There is also confstr()¹, which is able to deliver a PATH, which is
> guaranteed to find sh. And there is also a hint to “popen("command -p
> getconf variable", "r");”
Will `command -v sh` reliably locate a POSIX sh?
A quick test at cfarm111 finds that AIX7.1 command(1) does not allow the
combination of -p and -v, although `getconf PATH` works and is defined
to return the _CS_PATH string (see
<URL:https://pubs.opengroup.org/onlinepubs/9699919799/utilities/getconf.html#tag_20_53_05>)
available to C programs using confstr(). Remember that dejagnu(1) is a
shell script, so the XCU volume of the POSIX spec is relevant, not
(confusingly) XSH.
-- Jacob