Re: [PATCH] Catch errors properly, if whoami or who don't exist

Stefan <[email protected]> Thu, 12 Sep 2024 18:41:10 +0200
Newsgroups gmane.comp.sysutils.dejagnu.general
Message-ID <[email protected]>
Hi!

>>>> As of commit 7be57b729931bbdfa0770eabe4e7586170b28b1f the problem should be fixed; please confirm that it is.  (I took the opportunity to clean up the code while in there.) 

Yes, confirmed.

>>>> There is a technical reason for this assumption about /bin/sh:  the #! 
>>>> mechanism does not search $PATH and requires an absolute filename.

I know about this restriction, but this does not necessarily need to be extended to the script content itself.

>>> 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.

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.

>> 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");”


Bye

Stefan


¹ <https://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html>