[git] GnuPG - branch, master, updated. gnupg-2.1.16-79-g4a04277

by Werner Koch cvs at cvs.gnupg.org
Thu Dec 8 17:58:57 CET 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  4a04277ad112e0966296133795f93cf6a3daa48e (commit)
      from  e7429b1ced0c69fa7901f888f8dc25f00fc346a4 (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 4a04277ad112e0966296133795f93cf6a3daa48e
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Dec 8 17:55:36 2016 +0100

    wks: New option --status-fd for gpg-wks-client.
    
    * tools/wks-util.c: Include status.h.
    (statusfp): New global var.
    (wks_set_status_fd): New func.
    (wks_write_status): New func.
    * tools/gpg-wks-client.c: Include status.h.
    (oStatusFD): New constant.
    (opts): New option --status-fd.
    (parse_arguments): Handle that option.
    (main): Return STATUS_SUCCESS or STATUS_FAILURE.
    --
    
    This option is useful in case gpg-wks-client is spawed using a double
    fork approach which does not allow to return the exit code.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index 1a53f39..0f90424 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include "util.h"
+#include "status.h"
 #include "i18n.h"
 #include "sysutils.h"
 #include "init.h"
@@ -58,6 +59,7 @@ enum cmd_and_opt_values
     oGpgProgram,
     oSend,
     oFakeSubmissionAddr,
+    oStatusFD,
 
     oDummy
   };
@@ -86,6 +88,7 @@ static ARGPARSE_OPTS opts[] = {
   ARGPARSE_s_s (oGpgProgram, "gpg", "@"),
   ARGPARSE_s_n (oSend, "send", "send the mail using sendmail"),
   ARGPARSE_s_s (oOutput, "output", "|FILE|write the mail to FILE"),
+  ARGPARSE_s_i (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
 
   ARGPARSE_s_s (oFakeSubmissionAddr, "fake-submission-addr", "@"),
 
@@ -197,6 +200,9 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
         case oFakeSubmissionAddr:
           fake_submission_addr = pargs->r.ret_str;
           break;
+        case oStatusFD:
+          wks_set_status_fd (translate_sys2libc_fd_int (pargs->r.ret_int, 1));
+          break;
 
 	case aSupported:
 	case aCreate:
@@ -298,14 +304,21 @@ main (int argc, char **argv)
     case aCheck:
       if (argc != 1)
         wrong_args ("--check USER-ID");
-      command_check (argv[0]);
+      err = command_check (argv[0]);
       break;
 
     default:
       usage (1);
+      err = 0;
       break;
     }
 
+  if (err)
+    wks_write_status (STATUS_FAILURE, "- %u", err);
+  else if (log_get_errorcount (0))
+    wks_write_status (STATUS_FAILURE, "- %u", GPG_ERR_GENERAL);
+  else
+    wks_write_status (STATUS_SUCCESS, NULL);
   return log_get_errorcount (0)? 1:0;
 }
 
diff --git a/tools/gpg-wks.h b/tools/gpg-wks.h
index 7f347eb..62ceb34 100644
--- a/tools/gpg-wks.h
+++ b/tools/gpg-wks.h
@@ -65,6 +65,8 @@ typedef struct policy_flags_s *policy_flags_t;
 
 
 /*-- wks-util.c --*/
+void wks_set_status_fd (int fd);
+void wks_write_status (int no, const char *format, ...) GPGRT_ATTR_PRINTF(2,3);
 gpg_error_t wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes);
 gpg_error_t wks_send_mime (mime_maker_t mime);
 gpg_error_t wks_parse_policy (policy_flags_t flags, estream_t stream,
diff --git a/tools/wks-util.c b/tools/wks-util.c
index f4f44f6..e6f6b7a 100644
--- a/tools/wks-util.c
+++ b/tools/wks-util.c
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include "util.h"
+#include "status.h"
 #include "ccparray.h"
 #include "exectool.h"
 #include "mbox-util.h"
@@ -30,6 +31,65 @@
 #include "send-mail.h"
 #include "gpg-wks.h"
 
+/* The stream to output the status information.  Output is disabled if
+   this is NULL.  */
+static estream_t statusfp;
+
+
+

+/* Set the status FD.  */
+void
+wks_set_status_fd (int fd)
+{
+  static int last_fd = -1;
+
+  if (fd != -1 && last_fd == fd)
+    return;
+
+  if (statusfp && statusfp != es_stdout && statusfp != es_stderr)
+    es_fclose (statusfp);
+  statusfp = NULL;
+  if (fd == -1)
+    return;
+
+  if (fd == 1)
+    statusfp = es_stdout;
+  else if (fd == 2)
+    statusfp = es_stderr;
+  else
+    statusfp = es_fdopen (fd, "w");
+  if (!statusfp)
+    {
+      log_fatal ("can't open fd %d for status output: %s\n",
+                 fd, gpg_strerror (gpg_error_from_syserror ()));
+    }
+  last_fd = fd;
+}
+
+
+/* Write a status line with code NO followed by the outout of the
+ * printf style FORMAT.  The caller needs to make sure that LFs and
+ * CRs are not printed.  */
+void
+wks_write_status (int no, const char *format, ...)
+{
+  va_list arg_ptr;
+
+  if (!statusfp)
+    return;  /* Not enabled.  */
+
+  es_fputs ("[GNUPG:] ", statusfp);
+  es_fputs (get_status_string (no), statusfp);
+  if (format)
+    {
+      es_putc (' ', statusfp);
+      va_start (arg_ptr, format);
+      es_vfprintf (statusfp, format, arg_ptr);
+      va_end (arg_ptr);
+    }
+  es_putc ('\n', statusfp);
+}
+
 
 

 /* Helper for wks_list_key.  */

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

Summary of changes:
 tools/gpg-wks-client.c | 15 ++++++++++++-
 tools/gpg-wks.h        |  2 ++
 tools/wks-util.c       | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletion(-)


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




More information about the Gnupg-commits mailing list