[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/02: Add error handling for spawn's posix_spawn_file_a
From: |
Ludovic Courtès |
Subject: |
[Guile-commits] 01/02: Add error handling for spawn's posix_spawn_file_actions_adddup2. |
Date: |
Mon, 8 May 2023 10:07:27 -0400 (EDT) |
civodul pushed a commit to branch main
in repository guile.
commit ccd7400fdbebca73fc4340ad4ca0248655009f04
Author: Josselin Poiret <dev@jpoiret.xyz>
AuthorDate: Fri May 5 15:39:22 2023 +0200
Add error handling for spawn's posix_spawn_file_actions_adddup2.
* libguile/posix.c (do_spawn): Add error handling if
posix_spawn_file_actions_adddup2 fails.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
---
libguile/posix.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/libguile/posix.c b/libguile/posix.c
index 3adc743c4..6776a7744 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1390,12 +1390,19 @@ 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++)
+ {
+ errno = posix_spawn_file_actions_adddup2 (&actions, dup2_action_from[i],
+ dup2_action_to[i]);
+ if (errno != 0)
+ return -1;
+ }
#ifdef HAVE_ADDCLOSEFROM
/* This function appears in glibc 2.34. It's both free from race