GNU bug report logs - #52835
[PATCH 0/2] Fix spawning a child not setting standard fds properly

Previous Next

Package: guile;

Reported by: Josselin Poiret <dev <at> jpoiret.xyz>

Date: Mon, 27 Dec 2021 21:27:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Josselin Poiret <dev <at> jpoiret.xyz>
To: Josselin Poiret <dev <at> jpoiret.xyz>, Timothy Sample <samplet <at> ngyro.com>
Cc: 52835 <at> debbugs.gnu.org
Subject: bug#52835: [PATCH v4 0/4] Improve safety of start_child and piped-process.
Date: Sat, 28 May 2022 14:46:30 +0200
retitle 52835 Improve safety of start_child and piped-process.
thanks

Hello everyone,

This time, it's another Guix bug [1] that prompted me to have a closer
look at piped-process and start_child, which don't seem to be very
multi-thread safe.  I've ended up with a couple of improvements that
IMO would make all procedures relying on them more robust.  Here's
roughly what I did:

* Fix the fd closing code that was bogus for unusual values for in,
  out, err for start_child.
* Check for double closes and avoid them, so that we don't
  accidentally close an fd that another thread could have opened.
* Remove some closing code in the child, since we're already
  generically closing all fds.
* Add a pipe from the child to the parent that the former uses to
  report its errno to the latter.  This avoids the use of strerror and
  printf in the child after forking, since they are not async-signal
  safe.  As a side effect, this lets piped-error raise the proper
  system exception for the child errno, instead of returning the PID
  of a process that hasn't exec'd successfully.

[1] https://issues.guix.gnu.org/55441

Best,
Josselin Poiret (4):
  Fix child spawning closing standard fds prematurely.
  Avoid double closes in piped-process.
  Remove useless closing code in start_child.
  Make start_child propagate the child errno to the parent.

 configure.ac     |   3 +-
 libguile/posix.c | 187 ++++++++++++++++++++++++++++++++++-------------
 2 files changed, 138 insertions(+), 52 deletions(-)

-- 
2.36.0





This bug report was last modified 2 years and 128 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.