unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Josselin Poiret <dev@jpoiret.xyz>
Cc: 63024@debbugs.gnu.org, 62334@debbugs.gnu.org,
	Greg Hogan <code@greghogan.com>,
	Simon Tournier <zimon.toutoune@gmail.com>
Subject: bug#62334: bug#63024: Crash during `guix import pypi -r'
Date: Wed, 03 May 2023 11:04:14 +0200	[thread overview]
Message-ID: <87mt2l4whd.fsf@gnu.org> (raw)
In-Reply-To: <87fs8e5rrp.fsf@gnu.org> ("Ludovic Courtès"'s message of "Tue, 02 May 2023 23:48:26 +0200")

[-- Attachment #1: Type: text/plain, Size: 215 bytes --]

Hey,

Ludovic Courtès <ludo@gnu.org> skribis:

> Looks like we shoudn’t dup(4, 1) in the child process, because 4 is the
> other end of our sleep pipe.  :-)

How about this patch, Josselin?

Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2418 bytes --]

diff --git a/libguile/posix.c b/libguile/posix.c
index 3adc743c4..2d55d985c 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1388,11 +1388,27 @@ do_spawn (char *exec_file, char **exec_argv, char **exec_env,
     }
 
   /* Move the fds out of the way, so that duplicate fds or fds equal
-     to 0, 1, 2 don't trample each other */
+     to 0, 1, 2 don't trample each other.  Since 'system*' might give
+     us -1 for IN, OUT, or ERR, open /dev/null when that's the case.  */
+
+  if (in < 0)
+    posix_spawn_file_actions_addopen (&actions, fd_slot[0],
+                                      "/dev/null", O_RDONLY | O_CLOEXEC, 0);
+  else
+    posix_spawn_file_actions_adddup2 (&actions, in, fd_slot[0]);
+
+  if (out < 0)
+    posix_spawn_file_actions_addopen (&actions, fd_slot[1],
+                                      "/dev/null", O_WRONLY | O_CLOEXEC, 0);
+  else
+    posix_spawn_file_actions_adddup2 (&actions, out, fd_slot[1]);
+
+  if (err < 0)
+    posix_spawn_file_actions_addopen (&actions, fd_slot[2],
+                                      "/dev/null", O_WRONLY | O_CLOEXEC, 0);
+  else
+    posix_spawn_file_actions_adddup2 (&actions, err, fd_slot[2]);
 
-  posix_spawn_file_actions_adddup2 (&actions, in, fd_slot[0]);
-  posix_spawn_file_actions_adddup2 (&actions, out, fd_slot[1]);
-  posix_spawn_file_actions_adddup2 (&actions, err, fd_slot[2]);
   posix_spawn_file_actions_adddup2 (&actions, fd_slot[0], 0);
   posix_spawn_file_actions_adddup2 (&actions, fd_slot[1], 1);
   posix_spawn_file_actions_adddup2 (&actions, fd_slot[2], 2);
diff --git a/test-suite/tests/posix.test b/test-suite/tests/posix.test
index d5cf47cda..18dad8902 100644
--- a/test-suite/tests/posix.test
+++ b/test-suite/tests/posix.test
@@ -374,7 +374,17 @@
                     (system* "sh" "-c" "echo bong >&2"))))))))
 
       (and (zero? (status:exit-val status))
-           (call-with-input-file file get-string-all)))))
+           (call-with-input-file file get-string-all))))
+
+  (pass-if-equal "https://bugs.gnu.org/63024"
+      0
+    (if (file-exists? "/proc/self/fd/0")          ;on GNU/Linux?
+        (parameterize ((current-output-port (%make-void-port "w0")))
+          (system* "guile" "-c"
+                   (object->string
+                    '(exit (string=? "/dev/null"
+                                     (readlink "/proc/self/fd/1"))))))
+        (throw 'unresolved))))
 
 ;;
 ;; spawn

  reply	other threads:[~2023-05-03  9:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21 14:17 bug#62334: Network is unreachable only for recursive pypi import Greg Hogan
2023-03-21 21:45 ` Josselin Poiret via Bug reports for GNU Guix
2023-03-24 12:19   ` Maxim Cournoyer
2023-04-24  8:42     ` zimoun
2023-03-28 20:37 ` bug#62334: Network Travis Zimmerman
2023-04-25 12:23 ` bug#62334: Network is unreachable only for recursive pypi import Simon Tournier
2023-04-27 13:32   ` Simon Tournier
2023-05-02 21:47 ` bug#62334: bug#63024: Crash during `guix import pypi -r' Ludovic Courtès
2023-05-02 21:48 ` Ludovic Courtès
2023-05-03  9:04   ` Ludovic Courtès [this message]
2023-05-03 10:08     ` bug#63024: bug#62334: " Simon Tournier
2023-05-04 11:10       ` Ludovic Courtès
2023-05-05 13:39     ` bug#62334: [PATCH 1/3] Add error handling for spawn's posix_spawn_file_actions_adddup2 Josselin Poiret via Bug reports for GNU Guix
2023-05-08 14:08       ` bug#63024: Guile's "sleep pipe" can leak into processes created by 'spawn' Ludovic Courtès
2023-05-05 13:39     ` bug#63024: [PATCH 2/3] Use /dev/null in piped-process if port is not backed by a fdes Josselin Poiret via Bug reports for GNU Guix
2023-05-05 13:39     ` bug#62334: [PATCH 3/3] tests: Test that system* works if stdin/out/err isn't backed by fdes Josselin Poiret via Bug reports for GNU Guix
2023-05-04 11:13   ` bug#63024: Crash during `guix import pypi -r' Ludovic Courtès
2023-05-05  8:54     ` bug#57391: " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mt2l4whd.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=62334@debbugs.gnu.org \
    --cc=63024@debbugs.gnu.org \
    --cc=code@greghogan.com \
    --cc=dev@jpoiret.xyz \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).