[bug #57242] Non-recursive command passes invalid jobserver file descriptors

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #57242] Non-recursive command passes invalid jobserver file descriptors

Martin Dorey-4
URL:
  <https://savannah.gnu.org/bugs/?57242>

                 Summary: Non-recursive command passes invalid jobserver file
descriptors
                 Project: make
            Submitted by: stefanbruens
            Submitted on: Fri 15 Nov 2019 07:41:39 PM UTC
                Severity: 3 - Normal
              Item Group: Bug
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
       Component Version: 4.2.1
        Operating System: POSIX-Based
           Fixed Release: None
           Triage Status: None

    _______________________________________________________

Details:

The problem can be reproduced using the following trivial
Makefile:
---
all:
    env | grep FLAGS
---

Using strace to get some diagnostics:
$> env -i strace -epipe,dup2,execve,fcntl -v -f -o nonrecursive.txt
/usr/bin/make -j2 -f  Makefile

Obivously, the jobserver file descriptors (3,4) are closed on exec by
fcntl({3,4}, F_SETFD, FD_CLOEXEC), but are still exported via
MFLAGS/MAKEFLAGS=--jobserver-auth=3,4.

When the "env | grep FLAGS" command is invoked via shell, the shell creates a
new pipe, reusing the no longer used file descriptors 3 and 4.

I.e. "env" (which serves as a placeholder here for some command implementing
the jobserver protocol) receives some file descriptors which are no jobserver
fds.

This does not happen when the command is marked as a recursive one (using the
'+' marker), but this is non-trivial to achieve in practice:

1. the Makefile may come from some generator
2. the command itself may be some script invoking "gmake" again.





    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57242>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57242] Non-recursive command passes invalid jobserver file descriptors

Martin Dorey-4
Follow-up Comment #1, bug #57242 (project make):

Stefan, the behavior you described is intended.
make closes the pipe unless the command has + or (MAKE) or {MAKE}.
This is necessary, because a command can mess up job server operation or a
command may expect a specific fd to be available.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57242>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57242] Non-recursive command passes invalid jobserver file descriptors

Martin Dorey-4
Follow-up Comment #2, bug #57242 (project make):

[comment #1 comment #1:]
> Stefan, the behavior you described is intended.
> make closes the pipe unless the command has + or (MAKE) or {MAKE}.
> This is necessary, because a command can mess up job server operation or a
command may expect a specific fd to be available.

Then at least the information should be consistent and the MAKEFLAGS should
not mention jobserver FDs.

As is, it already messes up make itself - a make process invocated indirectly
may get valid filedescriptors *not* belonging to the jobserver, and start busy
looping on the "read(rfd, 1)" call (when the other end is closed and read
returns 0).

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57242>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57242] Non-recursive command passes invalid jobserver file descriptors

Martin Dorey-4
Follow-up Comment #3, bug #57242 (project make):

I fully agree with Stafan that MAKEFLAGS should be aligned with jobserver
FDs.
My impression is that a much better approach would be the usage of named pipes
instead of file descriptors. I would consider the process relying on fixed
file descriptor numbers as a bad practice.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57242>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/