aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/exechelp-posix.c24
-rw-r--r--common/exechelp.h8
2 files changed, 20 insertions, 12 deletions
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c
index 8f21cbf75..a3237020e 100644
--- a/common/exechelp-posix.c
+++ b/common/exechelp-posix.c
@@ -993,31 +993,33 @@ my_exec (const char *pgmname, const char *argv[],
int (*spawn_cb) (void *), void *spawn_cb_arg)
{
int i;
- int fds[3];
int ask_inherit = 0;
+ struct spawn_cb_arg sca;
- fds[0] = fd_in;
- fds[1] = fd_out;
- fds[2] = fd_err;
+
+ sca.fds[0] = fd_in;
+ sca.fds[1] = fd_out;
+ sca.fds[2] = fd_err;
+ sca.arg = spawn_cb_arg;
/* Assign /dev/null to unused FDs. */
for (i = 0; i <= 2; i++)
if (fds[i] == -1)
- fds[i] = posix_open_null (i);
+ sca.fds[i] = posix_open_null (i);
+
+ if (spawn_cb)
+ ask_inherit = (*spawn_cb) (&sca);
/* Connect the standard files. */
for (i = 0; i <= 2; i++)
- if (fds[i] != i)
+ if (sca.fds[i] != i)
{
- if (dup2 (fds[i], i) == -1)
+ if (dup2 (sca.fds[i], i) == -1)
log_fatal ("dup2 std%s failed: %s\n",
i==0?"in":i==1?"out":"err", strerror (errno));
- close (fds[i]);
+ close (sca.fds[i]);
}
- if (spawn_cb)
- ask_inherit = (*spawn_cb) (spawn_cb_arg);
-
/* Close all other files. */
if (!ask_inherit)
close_all_fds (3, NULL);
diff --git a/common/exechelp.h b/common/exechelp.h
index fa835a033..dfca18f1e 100644
--- a/common/exechelp.h
+++ b/common/exechelp.h
@@ -211,6 +211,7 @@ gpg_error_t gnupg_spawn_process_detached (const char *pgmname,
/* The opaque type for a subprocess. */
typedef struct gnupg_process *gnupg_process_t;
#ifdef HAVE_W32_SYSTEM
+struct spawn_cb_arg;
#ifdef NEED_STRUCT_SPAWN_CB_ARG
struct spawn_cb_arg {
void *plpAttributeList;
@@ -218,6 +219,11 @@ struct spawn_cb_arg {
void *arg;
};
#endif
+#else
+struct spawn_cb_arg {
+ int fds[3];
+ void *arg;
+};
#endif
/* Internal flag to ihnerit file descriptor/handle */
@@ -245,7 +251,7 @@ struct spawn_cb_arg {
/* Spawn PGMNAME. */
gpg_err_code_t gnupg_process_spawn (const char *pgmname, const char *argv[],
unsigned int flags,
- int (*spawn_cb) (void *),
+ int (*spawn_cb) (struct spawn_cb_arg *),
void *spawn_cb_arg,
gnupg_process_t *r_process);