]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
posix: Do not use WNOHANG in waitpid call for Linux posix_spawn
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Sat, 21 Oct 2017 13:33:27 +0000 (11:33 -0200)
committerAurelien Jarno <aurelien@aurel32.net>
Sun, 26 Nov 2017 23:20:02 +0000 (00:20 +0100)
As shown in some buildbot issues on aarch64 and powerpc, calling
clone (VFORK) and waitpid (WNOHANG) does not guarantee the child
is ready to be collected.  This patch changes the call back to 0
as before fe05e1cb6d64 fix.

This change can lead to the scenario 4.3 described in the commit,
where the waitpid call can hang undefinitely on the call.  However
this is also a very unlikely and also undefinied situation where
both the caller is trying to terminate a pid before posix_spawn
returns and the race pid reuse is triggered.  I don't see how to
correct handle this specific situation within posix_spawn.

Checked on x86_64-linux-gnu, aarch64-linux-gnu and
powerpc64-linux-gnu.

* sysdeps/unix/sysv/linux/spawni.c (__spawnix): Use 0 instead of
WNOHANG in waitpid call.

(cherry picked from commit aa95a2414e4f664ca740ad5f4a72d9145abbd426)

ChangeLog
sysdeps/unix/sysv/linux/spawni.c

index 1da1c0f65a7dd7195e8b905882f4de1a395fd4fa..c1df219b612b5b76a340752e07895f20c48c6f36 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-10-23  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+       * sysdeps/unix/sysv/linux/spawni.c (__spawnix): Use 0 instead of
+       WNOHANG in waitpid call.
+
 2017-10-20  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        [BZ #22273]
index 93657c4cf0b67bf256ca10c873ced04f68374295..ee09fb762b2d108d6c9854bdd8d6280c34eb4175 100644 (file)
@@ -372,12 +372,12 @@ __spawnix (pid_t * pid, const char *file,
       ec = args.err;
       if (ec > 0)
        /* There still an unlikely case where the child is cancelled after
-          setting args.err, due to a positive error value.  Also due a
+          setting args.err, due to a positive error value.  Also there is
           possible pid reuse race (where the kernel allocated the same pid
-          to unrelated process) we need not to undefinitely hang expecting
-          an invalid pid.  In both cases an error is returned to the
-          caller.  */
-       __waitpid (new_pid, NULL, WNOHANG);
+          to an unrelated process).  Unfortunately due synchronization
+          issues where the kernel might not have the process collected
+          the waitpid below can not use WNOHANG.  */
+       __waitpid (new_pid, NULL, 0);
     }
   else
     ec = -new_pid;