On Thu, 06 Jun 2002 12:16:07 +0200, Simon Josefsson said:
Try calling emptyfile using execle() in C, it fails. Calling it
from
shells succeeds though. It seems like call-process-* somehow invokes
the shell and then the command (since it returns 0 when invoking an
empty file).
This is an artifact of how #! came to be, and how it works. A long time
ago, in a Unix version far away, there was only /bin/sh and exec*(). So if
you gave a command name, the shell would try to fork()/exec() it, and if it failed,
it would fork() and then try to read the file as a shell script. Then when
multiple shells came into existence, it got changed to "if it failed, it
would fork(), then run either ourselves or $SHELL to read it as input".
Then #! got added for flexibility and efficiency, as you could have it run
under a shell other than $SHELL and save a trip or two into the kernel
(which was REALLY important back on the 750/780 class systems).
And in fact, if $SHELL is set to something that signals an error on an
unexpected end-of-file, it might *NOT* return zero when invoking an
empty file....
(call-process "/tmp/emptyfile") should not return 0 IMHO.
Unfortunately, this has just too many subtle side effects - I've
seen systems where /bin/true and /bin/false rely on this sort of thing.
Yes, that's brain dead - /bin/true and /bin/false should be 'main()
{return(0)}'
type things (why they are 9144 bytes in size on RedHat 7.3 is code bloat
at its finest...)
--
Valdis Kletnieks
Computer Systems Senior Engineer
Virginia Tech