mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
posix: Fix for spawn_cb.
-- Fixes: 7571fd4cd02571ddd0ba84700c0a52704f0a9b5c Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
7571fd4cd0
commit
60b6cfe71f
@ -1000,11 +1000,12 @@ my_exec (const char *pgmname, const char *argv[],
|
||||
sca.fds[0] = fd_in;
|
||||
sca.fds[1] = fd_out;
|
||||
sca.fds[2] = fd_err;
|
||||
sca.except_fds = NULL;
|
||||
sca.arg = spawn_cb_arg;
|
||||
|
||||
/* Assign /dev/null to unused FDs. */
|
||||
for (i = 0; i <= 2; i++)
|
||||
if (fds[i] == -1)
|
||||
if (sca.fds[i] == -1)
|
||||
sca.fds[i] = posix_open_null (i);
|
||||
|
||||
if (spawn_cb)
|
||||
@ -1022,7 +1023,7 @@ my_exec (const char *pgmname, const char *argv[],
|
||||
|
||||
/* Close all other files. */
|
||||
if (!ask_inherit)
|
||||
close_all_fds (3, NULL);
|
||||
close_all_fds (3, sca.except_fds);
|
||||
|
||||
execv (pgmname, (char *const *)argv);
|
||||
/* No way to print anything, as we have may have closed all streams. */
|
||||
@ -1106,7 +1107,8 @@ spawn_detached (gnupg_process_t process,
|
||||
gpg_err_code_t
|
||||
gnupg_process_spawn (const char *pgmname, const char *argv1[],
|
||||
unsigned int flags,
|
||||
int (*spawn_cb) (void *), void *spawn_cb_arg,
|
||||
int (*spawn_cb) (struct spawn_cb_arg *),
|
||||
void *spawn_cb_arg,
|
||||
gnupg_process_t *r_process)
|
||||
{
|
||||
gpg_err_code_t ec;
|
||||
|
@ -222,6 +222,7 @@ struct spawn_cb_arg {
|
||||
#else
|
||||
struct spawn_cb_arg {
|
||||
int fds[3];
|
||||
int *except_fds;
|
||||
void *arg;
|
||||
};
|
||||
#endif
|
||||
|
@ -302,12 +302,12 @@ copy_buffer_flush (struct copy_buffer *c, estream_t sink)
|
||||
|
||||
|
||||
static int
|
||||
close_all_except (void *arg)
|
||||
setup_close_all (struct spawn_cb_arg *sca)
|
||||
{
|
||||
int *exceptclose = arg;
|
||||
int *user_except = sca->arg;
|
||||
|
||||
close_all_fds (3, exceptclose);
|
||||
return 1;
|
||||
sca->except_fds = user_except;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Run the program PGMNAME with the command line arguments given in
|
||||
@ -424,7 +424,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
|
||||
: GNUPG_PROCESS_STDIN_NULL)
|
||||
| GNUPG_PROCESS_STDOUT_PIPE
|
||||
| GNUPG_PROCESS_STDERR_PIPE),
|
||||
close_all_except, exceptclose, &proc);
|
||||
setup_close_all, exceptclose, &proc);
|
||||
gnupg_process_get_streams (proc, GNUPG_PROCESS_STREAM_NONBLOCK,
|
||||
input? &infp : NULL, &outfp, &errfp);
|
||||
if (extrapipe[0] != -1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user