This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Use a default path in exec*p*() if PATH is unset?


On 4/11/2017 7:10 AM, Christian Franke wrote:
> Thomas Wolff wrote:
>> Am 10.04.2017 um 22:29 schrieb Christian Franke:
>>> A few years after https://cygwin.com/ml/cygwin/2014-09/msg00204.html
>>> I found another use case of an unset PATH variable:
>>>
>>> The configure script from mandoc (http://mdocml.bsd.lv/) uses this
>>> interesting approach to query default CC command from make:
>>>
>>> CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -`
>> Why does it `env -i` at all?
> 
> I guess because make result should not depend on environment. I agree
> that 'env -i' is probably to much, 'env -u CC' would be enough.
> 

  -i, --ignore-environment  start with an empty environment

A relative use of the executable will not be found if the environment is
empty.

> 
>> (And why does it prepend a \ to the output?)
> 
> It doesn't. The extra \\ is required because `...` is used instead of
> $(...):
> 
> $ printf "all:\\n\\t@echo \\\$(CC)\\n"
> all:
>         @echo \$(CC)
> 
> $ CC=$(printf "all:\\n\\t@echo \\\$(CC)\\n" > /dev/tty)
> all:
>         @echo \$(CC)
> 
> $ CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" > /dev/tty`
> all:
>         @echo $(CC)
> 
> 
>> It seems this scriptlet has an issue, rather than adapting core
>> behaviour for it.
> 
> Of course Cygwin shouldn't be adapted solely for this single case.
> But it possibly Cygwin should be adapted to the existing practice of
> various other open source *ix systems.
> 

No, the other open source systems should adapt practices to defined
POSIX representation and not impose such "defaults" to their methods.
Using default behavior should never condoned as a default behavior,
unless defined explicitly can always be different elsewhere or even
change on the same system.

> Interestingly the approach in newlib/libc/posix/execvp.c differs from
> Cygwin and others:
> execvp() with PATH unset calls execv(). This has the same effect as
> execvp() with PATH set to current directory only.
> 

Why do you assume that this is an issue with execvp?  The user should
not expect that an undefined behavior behaves the same way on other
systems.  You might be able to get away with "env -i `which make` -sf -"
but this is broken based on POSIX.

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]