diff options
author | Werner Koch <[email protected]> | 2016-12-08 16:55:36 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-12-08 16:56:12 +0000 |
commit | 4a04277ad112e0966296133795f93cf6a3daa48e (patch) | |
tree | 1c96d085431b97ec0bf0733c41ab665a73092dd2 /tools/wks-util.c | |
parent | gpgscm: Better error reporting. (diff) | |
download | gnupg-4a04277ad112e0966296133795f93cf6a3daa48e.tar.gz gnupg-4a04277ad112e0966296133795f93cf6a3daa48e.zip |
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 <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | tools/wks-util.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tools/wks-util.c b/tools/wks-util.c index f4f44f6b2..e6f6b7acd 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. */ |