[git] GnuPG - branch, master, updated. gnupg-2.1.15-245-g8dce5ee

by Justus Winter cvs at cvs.gnupg.org
Tue Oct 18 18:55:27 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  8dce5ee55a0268d196023224dcf3020306922490 (commit)
       via  05a1e412332dd980353a4e3e59bc75ba40bae7fc (commit)
       via  f2d39a6d051413289c717b9cd2dc387a270b8e7c (commit)
       via  727ca74bb942464217e678012cccbfc347ae08a5 (commit)
      from  34439da2d62b964a914ace66bae7e38f619582a4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8dce5ee55a0268d196023224dcf3020306922490
Author: Justus Winter <justus at g10code.com>
Date:   Tue Oct 18 17:57:19 2016 +0200

    common: Fix copying data to estreams.
    
    * common/exectool.c (copy_buffer_do_copy): Correctly account for
    partially written data in the event of errors.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/common/exectool.c b/common/exectool.c
index e46071c..cf54efe 100644
--- a/common/exectool.c
+++ b/common/exectool.c
@@ -248,7 +248,14 @@ copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink)
     return 0;	/* Done copying.  */
 
 
+  nwritten = 0;
   err = sink? es_write (sink, c->writep, c->nread, &nwritten) : 0;
+
+  assert (nwritten <= c->nread);
+  c->writep += nwritten;
+  c->nread -= nwritten;
+  assert (c->writep - c->buffer <= sizeof c->buffer);
+
   if (err)
     {
       if (errno == EAGAIN)
@@ -257,11 +264,6 @@ copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink)
       return my_error_from_syserror ();
     }
 
-  assert (nwritten <= c->nread);
-  c->writep += nwritten;
-  c->nread -= nwritten;
-  assert (c->writep - c->buffer <= sizeof c->buffer);
-
   if (sink && es_fflush (sink) && errno != EAGAIN)
     err = my_error_from_syserror ();
 

commit 05a1e412332dd980353a4e3e59bc75ba40bae7fc
Author: Justus Winter <justus at g10code.com>
Date:   Tue Oct 18 14:04:54 2016 +0200

    common,w32: Communicate with child in non-blocking mode.
    
    * common/exechelp-w32.c (gnupg_spawn_process): Open streams in
    non-blocking mode if requested.
    
    Fixes-commit: 83811e3f1f0c615b2b63bafdb49a35a0fc198088
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c
index c5d6b08..19e4d9e 100644
--- a/common/exechelp-w32.c
+++ b/common/exechelp-w32.c
@@ -418,6 +418,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
   int i;
   es_syshd_t syshd;
   gpg_err_source_t errsource = default_errsource;
+  int nonblock = !!(flags & GNUPG_SPAWN_NONBLOCK);
 
   (void)except; /* Not yet used.  */
 
@@ -440,7 +441,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
 
       syshd.type = ES_SYSHD_HANDLE;
       syshd.u.handle = inpipe[1];
-      infp = es_sysopen (&syshd, "w");
+      infp = es_sysopen (&syshd, nonblock? "w,nonblock" : "w");
       if (!infp)
         {
           err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
@@ -464,7 +465,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
 
       syshd.type = ES_SYSHD_HANDLE;
       syshd.u.handle = outpipe[0];
-      outfp = es_sysopen (&syshd, "r");
+      outfp = es_sysopen (&syshd, nonblock? "r,nonblock" : "r");
       if (!outfp)
         {
           err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
@@ -494,7 +495,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
 
       syshd.type = ES_SYSHD_HANDLE;
       syshd.u.handle = errpipe[0];
-      errfp = es_sysopen (&syshd, "r");
+      errfp = es_sysopen (&syshd, nonblock? "r,nonblock" : "r");
       if (!errfp)
         {
           err = gpg_err_make (errsource, gpg_err_code_from_syserror ());

commit f2d39a6d051413289c717b9cd2dc387a270b8e7c
Author: Justus Winter <justus at g10code.com>
Date:   Tue Oct 18 13:55:12 2016 +0200

    common,w32: Extend gnupg_create_inbound_pipe et al.
    
    * common/exechelp-w32.c (do_create_pipe): Rename, add arguments, and
    create a stream if reqested.
    (gnupg_create_inbound_pipe): Use the extended function to open the
    stream if requested.
    (gnupg_create_outbound_pipe): Likewise.
    (gnupg_create_pipe): Update call site.
    
    Fixes-commit: 5d991e333a1885adc40abd9d00c01fec4bd5d9d7
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c
index 418eb9b..c5d6b08 100644
--- a/common/exechelp-w32.c
+++ b/common/exechelp-w32.c
@@ -301,7 +301,8 @@ w32_open_null (int for_write)
 
 
 static gpg_error_t
-do_create_pipe (int filedes[2], int flags)
+create_pipe_and_estream (int filedes[2], int flags,
+                         estream_t *r_fp, int outbound, int nonblock)
 {
   gpg_error_t err = 0;
   HANDLE fds[2];
@@ -330,6 +331,25 @@ do_create_pipe (int filedes[2], int flags)
             err = 0;
         }
     }
+
+  if (! err && r_fp)
+    {
+      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 = my_error_from_syserror ();
+          log_error (_("error creating a stream for a pipe: %s\n"),
+                     gpg_strerror (err));
+          close (filedes[0]);
+          close (filedes[1]);
+          filedes[0] = filedes[1] = -1;
+          return err;
+        }
+    }
+
   return err;
 }
 
@@ -339,10 +359,8 @@ do_create_pipe (int filedes[2], int flags)
 gpg_error_t
 gnupg_create_inbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
 {
-  if (r_fp)
-    return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
-  else
-    return do_create_pipe (filedes, INHERIT_WRITE);
+  return create_pipe_and_estream (filedes, INHERIT_WRITE,
+                                  r_fp, 0, nonblock);
 }
 
 
@@ -352,10 +370,8 @@ gnupg_create_inbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
 gpg_error_t
 gnupg_create_outbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
 {
-  if (r_fp)
-    return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
-  else
-    return do_create_pipe (filedes, INHERIT_READ);
+  return create_pipe_and_estream (filedes, INHERIT_READ,
+                                  r_fp, 1, nonblock);
 }
 
 
@@ -364,7 +380,8 @@ gnupg_create_outbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
 gpg_error_t
 gnupg_create_pipe (int filedes[2])
 {
-  return do_create_pipe (filedes, INHERIT_BOTH);
+  return create_pipe_and_estream (filedes, INHERIT_BOTH,
+                                  NULL, 0, 0);
 }
 
 

commit 727ca74bb942464217e678012cccbfc347ae08a5
Author: Justus Winter <justus at g10code.com>
Date:   Tue Oct 18 14:01:53 2016 +0200

    common,w32: 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.
    
    Fixes-commit: 96c7901ec1c79be732570811223d3ea54875abfe
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c
index b2d2457..418eb9b 100644
--- a/common/exechelp-w32.c
+++ b/common/exechelp-w32.c
@@ -84,6 +84,20 @@
 # define handle_to_pid(a) ((int)(a))
 
 
+/* 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.  */
@@ -219,7 +233,7 @@ build_w32_commandline (const char *pgmname, const char * const *argv,
 
   buf = p = xtrymalloc (n);
   if (!buf)
-    return gpg_error_from_syserror ();
+    return my_error_from_syserror ();
 
   p = build_w32_commandline_copy (p, pgmname);
   for (i=0; argv[i]; i++)
@@ -293,7 +307,7 @@ do_create_pipe (int filedes[2], int flags)
   HANDLE fds[2];
 
   filedes[0] = filedes[1] = -1;
-  err = gpg_error (GPG_ERR_GENERAL);
+  err = my_error (GPG_ERR_GENERAL);
   if (!create_inheritable_pipe (fds, flags))
     {
       filedes[0] = _open_osfhandle (handle_to_fd (fds[0]), O_RDONLY);
@@ -662,7 +676,7 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
                       ))
     {
       log_error ("CreateProcess failed: %s\n", w32_strerror (-1));
-      err = gpg_error (GPG_ERR_GENERAL);
+      err = my_error (GPG_ERR_GENERAL);
     }
   else
     err = 0;
@@ -707,7 +721,7 @@ gnupg_wait_processes (const char **pgmnames, pid_t *pids, size_t count,
 
   procs = xtrycalloc (count, sizeof *procs);
   if (procs == NULL)
-    return gpg_error_from_syserror ();
+    return my_error_from_syserror ();
 
   for (i = 0; i < count; i++)
     {
@@ -715,7 +729,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);
 
       procs[i] = fd_to_handle (pids[i]);
     }
@@ -818,7 +832,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
   (void)envp;
 
   if (access (pgmname, X_OK))
-    return gpg_error_from_syserror ();
+    return my_error_from_syserror ();
 
   /* Prepare security attributes.  */
   memset (&sec_attr, 0, sizeof sec_attr );
@@ -856,7 +870,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
     {
       log_error ("CreateProcess(detached) failed: %s\n", w32_strerror (-1));
       xfree (cmdline);
-      return gpg_error (GPG_ERR_GENERAL);
+      return my_error (GPG_ERR_GENERAL);
     }
   xfree (cmdline);
   cmdline = NULL;

-----------------------------------------------------------------------

Summary of changes:
 common/exechelp-w32.c | 72 +++++++++++++++++++++++++++++++++++++--------------
 common/exectool.c     | 12 +++++----
 2 files changed, 59 insertions(+), 25 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list