diff options
author | Werner Koch <[email protected]> | 2016-05-27 13:25:03 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-05-27 13:34:22 +0000 |
commit | 96c7901ec1c79be732570811223d3ea54875abfe (patch) | |
tree | 4dd77c0d37a0f4047d703d115099e3619f8adf0a /common/exechelp-posix.c | |
parent | gpg: Keep current and total of PROGESS status lines small enough. (diff) | |
download | gnupg-96c7901ec1c79be732570811223d3ea54875abfe.tar.gz gnupg-96c7901ec1c79be732570811223d3ea54875abfe.zip |
common: Make use of default_errsource in exechelp.
* common/exechelp-posix.c (my_error_from_syserror, my_error): New.
Use them instead of gpg_error and gpg_error_from_syserror.
(create_pipe_and_estream): Remove arg ERRSOURCE and fix use of
OUTBOUND which has a wrong name. Adjust callers.
(gnupg_spawn_process): Remove arg ERRSOURCE and replace by use of
DEFAULT_ERRSOURCE.
* common/exechelp-w32.c (gnupg_spawn_process): Ditto.
* common/exechelp-w32ce.c (gnupg_spawn_process): Ditto.
* common/exectool.c (gnupg_exec_tool_stream): Do not pass
GPG_ERROR_FROM_SYSERROR.
* tools/gpgconf-comp.c (gc_component_check_options): Ditto.
(retrieve_options_from_program): Ditto.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/exechelp-posix.c')
-rw-r--r-- | common/exechelp-posix.c | 97 |
1 files changed, 54 insertions, 43 deletions
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c index 6614eb7d6..069b07a4b 100644 --- a/common/exechelp-posix.c +++ b/common/exechelp-posix.c @@ -73,6 +73,20 @@ #include "exechelp.h" +/* Helper */ +static inline gpg_error_t +my_error_from_syserror (void) +{ + return gpg_err_make (default_errsource, gpg_err_code_from_syserror ()); +} + +static inline gpg_error_t +my_error (int errcode) +{ + return gpg_err_make (default_errsource, errcode); +} + + /* Return the maximum number of currently allowed open file descriptors. Only useful on POSIX systems but returns a value on other systems too. */ @@ -285,64 +299,36 @@ do_create_pipe (int filedes[2]) if (pipe (filedes) == -1) { - err = gpg_error_from_syserror (); + err = my_error_from_syserror (); filedes[0] = filedes[1] = -1; } return err; } -/* Portable function to create a pipe. Under Windows the write end is - inheritable. */ -gpg_error_t -gnupg_create_inbound_pipe (int filedes[2]) -{ - return do_create_pipe (filedes); -} - - -/* Portable function to create a pipe. Under Windows the read end is - inheritable. */ -gpg_error_t -gnupg_create_outbound_pipe (int filedes[2]) -{ - return do_create_pipe (filedes); -} - - -/* Portable function to create a pipe. Under Windows both ends are - inheritable. */ -gpg_error_t -gnupg_create_pipe (int filedes[2]) -{ - return do_create_pipe (filedes); -} - - static gpg_error_t create_pipe_and_estream (int filedes[2], estream_t *r_fp, - int outbound, int nonblock, - gpg_err_source_t errsource) + int outbound, int nonblock) { gpg_error_t err; if (pipe (filedes) == -1) { - err = gpg_err_make (errsource, gpg_err_code_from_syserror ()); + err = my_error_from_syserror (); log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); filedes[0] = filedes[1] = -1; *r_fp = NULL; return err; } - if (outbound) + if (!outbound) *r_fp = es_fdopen (filedes[0], nonblock? "r,nonblock" : "r"); else *r_fp = es_fdopen (filedes[1], nonblock? "w,nonblock" : "w"); if (!*r_fp) { - err = gpg_err_make (errsource, gpg_err_code_from_syserror ()); + err = my_error_from_syserror (); log_error (_("error creating a stream for a pipe: %s\n"), gpg_strerror (err)); close (filedes[0]); @@ -354,11 +340,36 @@ create_pipe_and_estream (int filedes[2], estream_t *r_fp, } +/* Portable function to create a pipe. Under Windows the write end is + inheritable. */ +gpg_error_t +gnupg_create_inbound_pipe (int filedes[2]) +{ + return do_create_pipe (filedes); +} + + +/* Portable function to create a pipe. Under Windows the read end is + inheritable. */ +gpg_error_t +gnupg_create_outbound_pipe (int filedes[2]) +{ + return do_create_pipe (filedes); +} + + +/* Portable function to create a pipe. Under Windows both ends are + inheritable. */ +gpg_error_t +gnupg_create_pipe (int filedes[2]) +{ + return do_create_pipe (filedes); +} + /* Fork and exec the PGMNAME, see exechelp.h for details. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], - gpg_err_source_t errsource, void (*preexec)(void), unsigned int flags, estream_t *r_infp, estream_t *r_outfp, @@ -384,14 +395,14 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], if (r_infp) { - err = create_pipe_and_estream (inpipe, &infp, 0, nonblock, errsource); + err = create_pipe_and_estream (inpipe, &infp, 1, nonblock); if (err) return err; } if (r_outfp) { - err = create_pipe_and_estream (outpipe, &outfp, 1, nonblock, errsource); + err = create_pipe_and_estream (outpipe, &outfp, 0, nonblock); if (err) { if (infp) @@ -407,7 +418,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], if (r_errfp) { - err = create_pipe_and_estream (errpipe, &errfp, 1, nonblock, errsource); + err = create_pipe_and_estream (errpipe, &errfp, 0, nonblock); if (err) { if (infp) @@ -432,7 +443,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], *pid = fork (); if (*pid == (pid_t)(-1)) { - err = gpg_err_make (errsource, gpg_err_code_from_syserror ()); + err = my_error_from_syserror (); log_error (_("error forking process: %s\n"), gpg_strerror (err)); if (infp) @@ -505,7 +516,7 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[], *pid = fork (); if (*pid == (pid_t)(-1)) { - err = gpg_error_from_syserror (); + err = my_error_from_syserror (); log_error (_("error forking process: %s\n"), strerror (errno)); return err; } @@ -543,7 +554,7 @@ gnupg_wait_processes (const char **pgmnames, pid_t *pids, size_t count, r_exitcodes[i] = -1; if (pids[i] == (pid_t)(-1)) - return gpg_error (GPG_ERR_INV_VALUE); + return my_error (GPG_ERR_INV_VALUE); } left = count; @@ -638,16 +649,16 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[], int i; if (getuid() != geteuid()) - return gpg_error (GPG_ERR_BUG); + return my_error (GPG_ERR_BUG); if (access (pgmname, X_OK)) - return gpg_error_from_syserror (); + return my_error_from_syserror (); pid = fork (); if (pid == (pid_t)(-1)) { log_error (_("error forking process: %s\n"), strerror (errno)); - return gpg_error_from_syserror (); + return my_error_from_syserror (); } if (!pid) { |