mirror of
git://git.gnupg.org/gnupg.git
synced 2025-06-14 18:31:03 +02: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
|
static void
|
||||||
my_exec (const char *pgmname, const char *argv[],
|
my_exec (const char *pgmname, const char *argv[],
|
||||||
int fd_in, int fd_out, int fd_err,
|
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 i;
|
||||||
int ask_inherit = 0;
|
|
||||||
struct spawn_cb_arg sca;
|
struct spawn_cb_arg sca;
|
||||||
|
|
||||||
|
|
||||||
sca.fds[0] = fd_in;
|
sca.fds[0] = fd_in;
|
||||||
sca.fds[1] = fd_out;
|
sca.fds[1] = fd_out;
|
||||||
sca.fds[2] = fd_err;
|
sca.fds[2] = fd_err;
|
||||||
sca.except_fds = NULL;
|
sca.except_fds = NULL;
|
||||||
sca.arg = spawn_cb_arg;
|
sca.arg = spawn_cb_arg;
|
||||||
|
if (spawn_cb)
|
||||||
|
(*spawn_cb) (&sca);
|
||||||
|
|
||||||
/* Assign /dev/null to unused FDs. */
|
/* Assign /dev/null to unused FDs. */
|
||||||
for (i = 0; i <= 2; i++)
|
for (i = 0; i <= 2; i++)
|
||||||
if (sca.fds[i] == -1)
|
if (sca.fds[i] == -1)
|
||||||
sca.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. */
|
/* Connect the standard files. */
|
||||||
for (i = 0; i <= 2; i++)
|
for (i = 0; i <= 2; i++)
|
||||||
if (sca.fds[i] != i)
|
if (sca.fds[i] != i)
|
||||||
@ -1018,12 +1015,15 @@ my_exec (const char *pgmname, const char *argv[],
|
|||||||
if (dup2 (sca.fds[i], i) == -1)
|
if (dup2 (sca.fds[i], i) == -1)
|
||||||
log_fatal ("dup2 std%s failed: %s\n",
|
log_fatal ("dup2 std%s failed: %s\n",
|
||||||
i==0?"in":i==1?"out":"err", strerror (errno));
|
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. */
|
/* Close all other files. */
|
||||||
if (!ask_inherit)
|
close_all_fds (3, sca.except_fds);
|
||||||
close_all_fds (3, sca.except_fds);
|
|
||||||
|
|
||||||
execv (pgmname, (char *const *)argv);
|
execv (pgmname, (char *const *)argv);
|
||||||
/* No way to print anything, as we have may have closed all streams. */
|
/* No way to print anything, as we have may have closed all streams. */
|
||||||
@ -1033,7 +1033,7 @@ my_exec (const char *pgmname, const char *argv[],
|
|||||||
static gpg_err_code_t
|
static gpg_err_code_t
|
||||||
spawn_detached (gnupg_process_t process,
|
spawn_detached (gnupg_process_t process,
|
||||||
const char *pgmname, const char *argv[],
|
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;
|
gpg_err_code_t ec;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -1107,7 +1107,7 @@ spawn_detached (gnupg_process_t process,
|
|||||||
gpg_err_code_t
|
gpg_err_code_t
|
||||||
gnupg_process_spawn (const char *pgmname, const char *argv1[],
|
gnupg_process_spawn (const char *pgmname, const char *argv1[],
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
int (*spawn_cb) (struct spawn_cb_arg *),
|
void (*spawn_cb) (struct spawn_cb_arg *),
|
||||||
void *spawn_cb_arg,
|
void *spawn_cb_arg,
|
||||||
gnupg_process_t *r_process)
|
gnupg_process_t *r_process)
|
||||||
{
|
{
|
||||||
|
@ -214,6 +214,7 @@ typedef struct gnupg_process *gnupg_process_t;
|
|||||||
struct spawn_cb_arg;
|
struct spawn_cb_arg;
|
||||||
#ifdef NEED_STRUCT_SPAWN_CB_ARG
|
#ifdef NEED_STRUCT_SPAWN_CB_ARG
|
||||||
struct spawn_cb_arg {
|
struct spawn_cb_arg {
|
||||||
|
int ask_inherit;
|
||||||
void *plpAttributeList;
|
void *plpAttributeList;
|
||||||
HANDLE hd[16];
|
HANDLE hd[16];
|
||||||
void *arg;
|
void *arg;
|
||||||
@ -252,7 +253,7 @@ struct spawn_cb_arg {
|
|||||||
/* Spawn PGMNAME. */
|
/* Spawn PGMNAME. */
|
||||||
gpg_err_code_t gnupg_process_spawn (const char *pgmname, const char *argv[],
|
gpg_err_code_t gnupg_process_spawn (const char *pgmname, const char *argv[],
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
int (*spawn_cb) (struct spawn_cb_arg *),
|
void (*spawn_cb) (struct spawn_cb_arg *),
|
||||||
void *spawn_cb_arg,
|
void *spawn_cb_arg,
|
||||||
gnupg_process_t *r_process);
|
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)
|
setup_close_all (struct spawn_cb_arg *sca)
|
||||||
{
|
{
|
||||||
int *user_except = sca->arg;
|
int *user_except = sca->arg;
|
||||||
|
|
||||||
sca->except_fds = user_except;
|
sca->except_fds = user_except;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run the program PGMNAME with the command line arguments given in
|
/* Run the program PGMNAME with the command line arguments given in
|
||||||
|
Loading…
x
Reference in New Issue
Block a user