bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in $(shell ...) I can't understand


From: Paul Smith
Subject: Re: Bug in $(shell ...) I can't understand
Date: Sun, 06 Feb 2022 15:21:39 -0500
User-agent: Evolution 3.42.3 (flatpak git)

On Sun, 2022-02-06 at 20:18 +0300, Dmitry V. Levin wrote:
> 4175643 write(2<pipe:[1062668627]>, "/bin/sh: bad-program: command no"..., 
> 40) = 40
> 4175640 <... read resumed>"/bin/sh: bad-program: command no"..., 200) = 40
> 4175640 read(5<pipe:[1062668627]>,  <unfinished ...>
> 4175643 +++ exited with 127 +++
> 4175640 <... read resumed>"", 160)      = 0
> 4175642 +++ exited with 127 +++
> 4175640 write(2</dev/null>, "/bin/sh: bad-program: command no"..., 40) = 40
> 4175640 write(1</dev/null>, "out = ", 6) = 6
> 4175640 write(1</dev/null>, "\n", 1)    = 1
> 4175640 read(4</tmp/Makefile>, "", 4096) = 0
> 4175640 write(2</dev/null>, "make: *** No targets.  Stop.\n", 29) = 29
> 4175640 +++ exited with 2 +++

Yes, I saw this as well.  But this doesn't help me understand WHY it's
happening.  There's something make is doing here that's causing this
but I don't understand what it is.  Make is reading the output of the
pipe, like we want, but somehow it's then rewriting the output to its
own stderr... why is that happening?

Oh.  I see the problem.  If the shell exits with an exit code of 127
then make's shell function assumes that it failed because the sub-
process was not found, and it actually writes its output to stderr!!

function.c:func_shell_base() contains:

    /* shell_completed() will set shell_function_completed to 1 when the
       child dies normally, or to -1 if it dies with status 127, which is
       most likely an exec fail.  */

    if (shell_function_completed == -1)
      {
        /* This likely means that the execvp failed, so we should just
           write the error message in the pipe from the child.  */
        fputs (buffer, stderr);
        fflush (stderr);
      }
    else
  ...

I'm not sure this is correct.  I will need to think about it.

> Try the following instead:
> 
> out := $(shell bad-program 2>&1 ||:)
> $(info out = $(out))
> 
> $ make
> out = /bin/sh: bad-program: command not found

Sure, there are definitely workarounds: I suggested a different one in
my message.  I was trying to understand why the behavior happened, not
how to work around it.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]