[Pkg-gnupg-commit] [gnupg2] 30/102: common: Make use of default_errsource in exechelp.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Fri Jun 17 00:14:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gnupg2.

commit 96c7901ec1c79be732570811223d3ea54875abfe
Author: Werner Koch <wk at gnupg.org>
Date:   Fri May 27 15:25:03 2016 +0200

    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 <wk at gnupg.org>
---
 common/exechelp-posix.c | 97 +++++++++++++++++++++++++++----------------------
 common/exechelp-w32.c   |  2 +-
 common/exechelp-w32ce.c |  2 +-
 common/exechelp.h       |  1 -
 common/exectool.c       |  2 +-
 tools/gpgconf-comp.c    |  4 +-
 6 files changed, 59 insertions(+), 49 deletions(-)

diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c
index 6614eb7..069b07a 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)
     {
diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c
index 3e407d2..0aa2020 100644
--- a/common/exechelp-w32.c
+++ b/common/exechelp-w32.c
@@ -349,7 +349,6 @@ gnupg_create_pipe (int filedes[2])
 /* 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,
@@ -379,6 +378,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
                       INVALID_HANDLE_VALUE};
   int i;
   es_syshd_t syshd;
+  gpg_err_source_t errsource = default_errsource;
 
   if (r_infp)
     *r_infp = NULL;
diff --git a/common/exechelp-w32ce.c b/common/exechelp-w32ce.c
index e208f6e..57ecaf3 100644
--- a/common/exechelp-w32ce.c
+++ b/common/exechelp-w32ce.c
@@ -509,7 +509,6 @@ create_process (const char *pgmname, const char *cmdline,
 /* 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,
@@ -534,6 +533,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
   } errpipe = {INVALID_HANDLE_VALUE, 0};
   estream_t outfp = NULL;
   estream_t errfp = NULL;
+  gpg_err_source_t errsource = default_errsource;
 
   (void)preexec;
   (void)flags;
diff --git a/common/exechelp.h b/common/exechelp.h
index 82224fd..3454cd6 100644
--- a/common/exechelp.h
+++ b/common/exechelp.h
@@ -112,7 +112,6 @@ gpg_error_t gnupg_create_pipe (int filedes[2]);
  */
 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,
diff --git a/common/exectool.c b/common/exectool.c
index 7b3a8f1..9ba336d 100644
--- a/common/exectool.c
+++ b/common/exectool.c
@@ -251,7 +251,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
   copy_buffer_init (&cpbuf[0]);
   copy_buffer_init (&cpbuf[1]);
 
-  err = gnupg_spawn_process (pgmname, argv, GPG_ERR_SOURCE_DEFAULT,
+  err = gnupg_spawn_process (pgmname, argv,
                              NULL, GNUPG_SPAWN_NONBLOCK,
                              input? &infp : NULL,
                              &outfp, &errfp, &pid);
diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index 4dd10a4..5d4a26a 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -1626,7 +1626,7 @@ gc_component_check_options (int component, estream_t out, const char *conf_file)
 
   result = 0;
   errlines = NULL;
-  err = gnupg_spawn_process (pgmname, argv, GPG_ERR_SOURCE_DEFAULT, NULL, 0,
+  err = gnupg_spawn_process (pgmname, argv, NULL, 0,
                              NULL, NULL, &errfp, &pid);
   if (err)
     result |= 1; /* Program could not be run.  */
@@ -1965,7 +1965,7 @@ retrieve_options_from_program (gc_component_t component, gc_backend_t backend)
   argv[0] = "--gpgconf-list";
   argv[1] = NULL;
 
-  err = gnupg_spawn_process (pgmname, argv, GPG_ERR_SOURCE_DEFAULT, NULL, 0,
+  err = gnupg_spawn_process (pgmname, argv, NULL, 0,
                              NULL, &outfp, NULL, &pid);
   if (err)
     {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list