bugmake - Bugs: bug #62840, make --version in pipe return...

 
 

bug #62840: make --version in pipe return SIGPIPE

Submitter:  Tzvetelin Katchov <katchov>
Submitted:  Sat 30 Jul 2022 04:24:33 PM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Fixed Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.3 Operating System:  POSIX-Based
Fixed Release:  4.4 Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 31 Aug 2022 01:21:32 AM UTC, comment #5: 

Thanks for that patch.  After looking at it I added some more cleanup.

I saw one weird thing: we allow the --version option to be accepted from the environment:


$ MAKEFLAGS=--version make
GNU Make 4.3
  ...


and doesn't try to build any targets.  I don't think this is a good idea.  Anyone have a good reason to keep this behavior?

Paul D. Smith <psmith>
Group administrator
Tue 30 Aug 2022 01:56:01 AM UTC, comment #4: 

Patch sv62840_fix.diff sets stdout to line buffering after --version and --help are processed, but before make reads makefiles.

Dmitry Goncharov <dgoncharov>
Sun 31 Jul 2022 01:16:40 PM UTC, comment #3: 

The reason GNU make behaves differently here is that for a normal program when you pipe its output the system automatically sets the stdout stream to block buffered mode (the default is line buffered mode).

This means that the entire version string is buffered in the stream, then it will be written as a single block when you flush (or exit, or the block fills up: but blocks are usually 1K or more so that won't happen for version info output).  Because it goes as a single block, the entire thing will be written to the pipe before the reader closes the pipe.

However, due to GNU make's output sync feature, make will force stdout to be in line buffered mode (where each line is flushed as its written) at all times.  This means that GNU make is writing its output in multiple separate system calls, which means it might get a write failure if the reader closes the pipe early.

Unfortunately I'm not sure there's a simple way to avoid this.  I'll have to think about it.

Paul D. Smith <psmith>
Group administrator
Sat 30 Jul 2022 05:26:46 PM UTC, comment #2: 

Just for completeness or academic interest, then, this makes it happen reliably for me:


set -o pipefail; { ruby -we '$stdout.write("x" * 4096)'; make --version; } | head -n1; echo $?


That behaved the same all the way back to make-3.81.  This was the first command I found that behaved like make --version:


set -o pipefail; { ruby -we '$stdout.write("x" * 4096)'; tar --help; } | head -n1; echo $?


Martin Dorey <mdorey>
Sat 30 Jul 2022 05:06:08 PM UTC, comment #1: 

I'm not convinced that this is a bug.  First, it's highly timing-dependent: when I tried it it didn't fail:


$ make --version | head -n1
GNU Make 4.3

$ echo $?
0


Second, you can get similar behavior from other commands; you just have to be sure that the writer is still trying to write when the reader (head) has exited.  For example:


$ (/bin/echo one; sleep 1; /bin/echo hi) | head -n1
one
/bin/echo: write error: Broken pipe

$ echo $?
1


Here /bin/echo exits with 1 not 141 but it's the same thing with a different exit code.

Paul D. Smith <psmith>
Group administrator
Sat 30 Jul 2022 04:24:33 PM UTC, original submission:  

$ set -o pipefail
$ make --version | head -n1
GNU Make 4.3
$ echo $?
141

Tzvetelin Katchov <katchov>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #53634:  sv62840_fix.diff added by dgoncharov (3KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dgoncharov (Updated the item)
  • -email is unavailable- added by mdorey (Posted a comment)
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by katchov (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-08-31 psmith StatusNone Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 4.4
    2022-08-30 dgoncharov Attached File- Added sv62840_fix.diff, #53634

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code