[Pkg-gnupg-commit] [gnupg2] 38/159: common: Use default_errsource for call-gpg and exectool.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Jan 27 13:23:51 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit 4ffe44c5874ed655d82adfa7a85439fab91cde03
Author: Werner Koch <wk at gnupg.org>
Date: Mon Dec 14 19:55:34 2015 +0100
common: Use default_errsource for call-gpg and exectool.
* common/call-gpg.c (my_error_from_syserror, my_error_from_errno): New.
Use these wrappers.
* common/exectool.c (my_error_from_syserror): New. Use these
wrappers.
--
Function in common should use the error source of the component which
links them. The global variable DEFAULT_ERRSOURCE is set early by
each component to make this possible.
Signed-off-by: Werner Koch <wk at gnupg.org>
---
common/call-gpg.c | 41 +++++++++++++++++++++++++++--------------
common/exectool.c | 23 +++++++++++++++--------
2 files changed, 42 insertions(+), 22 deletions(-)
diff --git a/common/call-gpg.c b/common/call-gpg.c
index cd865ef..f5a62ec 100644
--- a/common/call-gpg.c
+++ b/common/call-gpg.c
@@ -36,6 +36,19 @@
#include "strlist.h"
#include "util.h"
+
+static GPGRT_INLINE gpg_error_t
+my_error_from_syserror (void)
+{
+ return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
+}
+
+static GPGRT_INLINE gpg_error_t
+my_error_from_errno (int e)
+{
+ return gpg_err_make (default_errsource, gpg_err_code_from_errno (e));
+}
+
/* Fire up a new GPG. Handle the server's initial greeting. Returns
0 on success and stores the assuan context at R_CTX. */
@@ -74,7 +87,7 @@ start_gpg (ctrl_t ctrl, const char *gpg_program, strlist_t gpg_arguments,
if (fflush (NULL))
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
log_error ("error flushing pending output: %s\n", gpg_strerror (err));
return err;
}
@@ -82,7 +95,7 @@ start_gpg (ctrl_t ctrl, const char *gpg_program, strlist_t gpg_arguments,
argv = xtrycalloc (strlist_length (gpg_arguments) + 3, sizeof *argv);
if (argv == NULL)
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
return err;
}
i = 0;
@@ -196,7 +209,7 @@ writer_thread_main (void *arg)
{
if (errno == EINTR)
continue;
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
break; /* Write error. */
}
length -= nwritten;
@@ -250,7 +263,7 @@ start_writer (int fd, const void *data, size_t datalen, estream_t stream,
parm = xtrymalloc (sizeof *parm);
if (!parm)
- return gpg_error_from_syserror ();
+ return my_error_from_syserror ();
parm->fd = fd;
parm->data = data;
parm->datalen = datalen;
@@ -263,7 +276,7 @@ start_writer (int fd, const void *data, size_t datalen, estream_t stream,
ret = npth_create (&thread, &tattr, writer_thread_main, parm);
if (ret)
{
- err = gpg_error_from_errno (ret);
+ err = my_error_from_errno (ret);
log_error ("error spawning writer thread: %s\n", gpg_strerror (err));
}
else
@@ -304,7 +317,7 @@ reader_thread_main (void *arg)
{
if (errno == EINTR)
continue;
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
break; /* Read error. */
}
@@ -357,7 +370,7 @@ start_reader (int fd, membuf_t *mb, estream_t stream,
parm = xtrymalloc (sizeof *parm);
if (!parm)
- return gpg_error_from_syserror ();
+ return my_error_from_syserror ();
parm->fd = fd;
parm->mb = mb;
parm->stream = stream;
@@ -369,7 +382,7 @@ start_reader (int fd, membuf_t *mb, estream_t stream,
ret = npth_create (&thread, &tattr, reader_thread_main, parm);
if (ret)
{
- err = gpg_error_from_errno (ret);
+ err = my_error_from_errno (ret);
log_error ("error spawning reader thread: %s\n", gpg_strerror (err));
}
else
@@ -474,7 +487,7 @@ _gpg_encrypt (ctrl_t ctrl,
ret = npth_join (reader_thread, NULL);
if (ret)
{
- err = gpg_error_from_errno (ret);
+ err = my_error_from_errno (ret);
log_error ("waiting for reader thread failed: %s\n", gpg_strerror (err));
goto leave;
}
@@ -491,7 +504,7 @@ _gpg_encrypt (ctrl_t ctrl,
ret = npth_join (writer_thread, NULL);
if (ret)
{
- err = gpg_error_from_errno (ret);
+ err = my_error_from_errno (ret);
log_error ("waiting for writer thread failed: %s\n", gpg_strerror (err));
goto leave;
}
@@ -549,7 +562,7 @@ gpg_encrypt_blob (ctrl_t ctrl,
*r_ciph = get_membuf (&reader_mb, r_ciphlen);
if (!*r_ciph)
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
log_error ("error while storing the data in the reader thread: %s\n",
gpg_strerror (err));
}
@@ -646,7 +659,7 @@ _gpg_decrypt (ctrl_t ctrl,
ret = npth_join (reader_thread, NULL);
if (ret)
{
- err = gpg_error_from_errno (ret);
+ err = my_error_from_errno (ret);
log_error ("waiting for reader thread failed: %s\n", gpg_strerror (err));
goto leave;
}
@@ -662,7 +675,7 @@ _gpg_decrypt (ctrl_t ctrl,
ret = npth_join (writer_thread, NULL);
if (ret)
{
- err = gpg_error_from_errno (ret);
+ err = my_error_from_errno (ret);
log_error ("waiting for writer thread failed: %s\n", gpg_strerror (err));
goto leave;
}
@@ -717,7 +730,7 @@ gpg_decrypt_blob (ctrl_t ctrl,
*r_plain = get_membuf (&reader_mb, r_plainlen);
if (!*r_plain)
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
log_error ("error while storing the data in the reader thread: %s\n",
gpg_strerror (err));
}
diff --git a/common/exectool.c b/common/exectool.c
index a2828a6..766ee94 100644
--- a/common/exectool.c
+++ b/common/exectool.c
@@ -54,6 +54,13 @@ typedef struct
} read_and_log_buffer_t;
+static inline gpg_error_t
+my_error_from_syserror (void)
+{
+ return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
+}
+
+
static void
read_and_log_stderr (read_and_log_buffer_t *state, es_poll_t *fderr)
{
@@ -102,7 +109,7 @@ read_and_log_stderr (read_and_log_buffer_t *state, es_poll_t *fderr)
}
else if (es_ferror (fderr->stream))
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
log_error ("error reading stderr of '%s': %s\n",
state->pgmname, gpg_strerror (err));
fderr->ignore = 1; /* Disable. */
@@ -172,7 +179,7 @@ copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink)
if (errno == EAGAIN)
return 0; /* We will just retry next time. */
- return gpg_error_from_syserror ();
+ return my_error_from_syserror ();
}
assert (c->nread <= sizeof c->buffer);
@@ -187,7 +194,7 @@ copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink)
if (errno == EAGAIN)
return 0; /* We will just retry next time. */
- return gpg_error_from_syserror ();
+ return my_error_from_syserror ();
}
assert (nwritten <= c->nread);
@@ -196,7 +203,7 @@ copy_buffer_do_copy (struct copy_buffer *c, estream_t source, estream_t sink)
assert (c->writep - c->buffer <= sizeof c->buffer);
if (es_fflush (sink) && errno != EAGAIN)
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
return err;
}
@@ -272,7 +279,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
count = es_poll (fds, DIM(fds), -1);
if (count == -1)
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
log_error ("error polling '%s': %s\n", pgmname, gpg_strerror (err));
goto leave;
}
@@ -391,13 +398,13 @@ gnupg_exec_tool (const char *pgmname, const char *argv[],
input = es_mopen ((char *) input_string, len, len,
0 /* don't grow */, NULL, nop_free, "rb");
if (! input)
- return gpg_error_from_syserror ();
+ return my_error_from_syserror ();
}
output = es_fopenmem (0, "wb");
if (! output)
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
goto leave;
}
@@ -413,7 +420,7 @@ gnupg_exec_tool (const char *pgmname, const char *argv[],
*result = xtrymalloc (len);
if (*result == NULL)
{
- err = gpg_error_from_syserror ();
+ err = my_error_from_syserror ();
goto leave;
}
--
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