mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
Tweak the spawn API, again for POSIX.
-- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
60b6cfe71f
commit
b35c3980c1
@ -990,27 +990,24 @@ posix_open_null (int for_write)
|
||||
static void
|
||||
my_exec (const char *pgmname, const char *argv[],
|
||||
int fd_in, int fd_out, int fd_err,
|
||||
int (*spawn_cb) (void *), void *spawn_cb_arg)
|
||||
void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg)
|
||||
{
|
||||
int i;
|
||||
int ask_inherit = 0;
|
||||
struct spawn_cb_arg sca;
|
||||
|
||||
|
||||
sca.fds[0] = fd_in;
|
||||
sca.fds[1] = fd_out;
|
||||
sca.fds[2] = fd_err;
|
||||
sca.except_fds = NULL;
|
||||
sca.arg = spawn_cb_arg;
|
||||
if (spawn_cb)
|
||||
(*spawn_cb) (&sca);
|
||||
|
||||
/* Assign /dev/null to unused FDs. */
|
||||
for (i = 0; i <= 2; i++)
|
||||
if (sca.fds[i] == -1)
|
||||
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 (sca.fds[i] != i)
|
||||
@ -1018,11 +1015,14 @@ my_exec (const char *pgmname, const char *argv[],
|
||||
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 (sca.fds[i]);
|
||||
/*
|
||||
* We don't close sca.fds[i] here, but close them by
|
||||
* close_all_fds. Note that there may be same one in three of
|
||||
* sca.fds[i].
|
||||
*/
|
||||
}
|
||||
|
||||
/* Close all other files. */
|
||||
if (!ask_inherit)
|
||||
close_all_fds (3, sca.except_fds);
|
||||
|
||||
execv (pgmname, (char *const *)argv);
|
||||
@ -1033,7 +1033,7 @@ my_exec (const char *pgmname, const char *argv[],
|
||||
static gpg_err_code_t
|
||||
spawn_detached (gnupg_process_t process,
|
||||
const char *pgmname, const char *argv[],
|
||||
int (*spawn_cb) (void *), void *spawn_cb_arg)
|
||||
void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg)
|
||||
{
|
||||
gpg_err_code_t ec;
|
||||
pid_t pid;
|
||||
@ -1107,7 +1107,7 @@ 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) (struct spawn_cb_arg *),
|
||||
void (*spawn_cb) (struct spawn_cb_arg *),
|
||||
void *spawn_cb_arg,
|
||||
gnupg_process_t *r_process)
|
||||
{
|
||||
|
@ -214,6 +214,7 @@ typedef struct gnupg_process *gnupg_process_t;
|
||||
struct spawn_cb_arg;
|
||||
#ifdef NEED_STRUCT_SPAWN_CB_ARG
|
||||
struct spawn_cb_arg {
|
||||
int ask_inherit;
|
||||
void *plpAttributeList;
|
||||
HANDLE hd[16];
|
||||
void *arg;
|
||||
@ -252,7 +253,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) (struct spawn_cb_arg *),
|
||||
void (*spawn_cb) (struct spawn_cb_arg *),
|
||||
void *spawn_cb_arg,
|
||||
gnupg_process_t *r_process);
|
||||
|
||||
|
@ -301,13 +301,12 @@ copy_buffer_flush (struct copy_buffer *c, estream_t sink)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
static void
|
||||
setup_close_all (struct spawn_cb_arg *sca)
|
||||
{
|
||||
int *user_except = sca->arg;
|
||||
|
||||
sca->except_fds = user_except;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Run the program PGMNAME with the command line arguments given in
|
||||
|
Loading…
x
Reference in New Issue
Block a user