unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: Josselin Poiret via Bug reports for GNU Guix <bug-guix@gnu.org>
To: "Ludovic Courtès" <ludo@gnu.org>, "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: [PATCH 1/3] Add error handling for spawn's posix_spawn_file_actions_adddup2
Date: Fri,  5 May 2023 15:39:22 +0200	[thread overview]
Message-ID: <f7db538ea324545f2e297b6a6cdcd937f889ef63.1683293896.git.dev@jpoiret.xyz> (raw)
In-Reply-To: <87mt2l4whd.fsf@gnu.org>

From: Josselin Poiret <dev@jpoiret.xyz>

* libguile/posix.c (do_spawn): Add error handling if
posix_spawn_file_actions_adddup2 fails.
---
Hi Ludo,

Sorry for not noticing this thread sooner!  Here's my take on it, a minor
variation but that's what I'd prefer tbh.

LMKWYT,
Josselin

 libguile/posix.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libguile/posix.c b/libguile/posix.c
index 3adc743c4..2969f1f24 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1390,12 +1390,15 @@ 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 */
 
-  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);
+  int dup2_action_from[] = {in, out, err,
+                            fd_slot[0], fd_slot[1], fd_slot[2]};
+  int dup2_action_to  [] = {fd_slot[0], fd_slot[1], fd_slot[2],
+                            0, 1, 2};
+
+  errno = 0;
+  for (int i = 0;i < sizeof (dup2_action_from) / sizeof (int);i++)
+    if ((errno = posix_spawn_file_actions_adddup2 (&actions, dup2_action_from[i], dup2_action_to[i])))
+        return -1;
 
 #ifdef HAVE_ADDCLOSEFROM
   /* This function appears in glibc 2.34.  It's both free from race

base-commit: fe6cc6d04ab094ea802907bdc4f728416c0e97ba
-- 
2.39.2





  parent reply	other threads:[~2023-05-05 13:40 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   ` bug#62334: " Ludovic Courtès
2023-05-03 10:08     ` bug#63024: " Simon Tournier
2023-05-04 11:10       ` Ludovic Courtès
2023-05-05 13:39     ` Josselin Poiret via Bug reports for GNU Guix [this message]
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=f7db538ea324545f2e297b6a6cdcd937f889ef63.1683293896.git.dev@jpoiret.xyz \
    --to=bug-guix@gnu.org \
    --cc=62334@debbugs.gnu.org \
    --cc=63024@debbugs.gnu.org \
    --cc=code@greghogan.com \
    --cc=dev@jpoiret.xyz \
    --cc=ludo@gnu.org \
    --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).