mirror of
git://git.gnupg.org/gnupg.git
synced 2024-11-10 21:38:50 +01:00
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@gnupg.org>
This commit is contained in:
parent
345ec7323d
commit
4ffe44c587
@ -36,6 +36,19 @@
|
|||||||
#include "strlist.h"
|
#include "strlist.h"
|
||||||
#include "util.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
|
/* Fire up a new GPG. Handle the server's initial greeting. Returns
|
||||||
0 on success and stores the assuan context at R_CTX. */
|
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))
|
if (fflush (NULL))
|
||||||
{
|
{
|
||||||
err = gpg_error_from_syserror ();
|
err = my_error_from_syserror ();
|
||||||
log_error ("error flushing pending output: %s\n", gpg_strerror (err));
|
log_error ("error flushing pending output: %s\n", gpg_strerror (err));
|
||||||
return 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);
|
argv = xtrycalloc (strlist_length (gpg_arguments) + 3, sizeof *argv);
|
||||||
if (argv == NULL)
|
if (argv == NULL)
|
||||||
{
|
{
|
||||||
err = gpg_error_from_syserror ();
|
err = my_error_from_syserror ();
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -196,7 +209,7 @@ writer_thread_main (void *arg)
|
|||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
err = gpg_error_from_syserror ();
|
err = my_error_from_syserror ();
|
||||||
break; /* Write error. */
|
break; /* Write error. */
|
||||||
}
|
}
|
||||||
length -= nwritten;
|
length -= nwritten;
|
||||||
@ -250,7 +263,7 @@ start_writer (int fd, const void *data, size_t datalen, estream_t stream,
|
|||||||
|
|
||||||
parm = xtrymalloc (sizeof *parm);
|
parm = xtrymalloc (sizeof *parm);
|
||||||
if (!parm)
|
if (!parm)
|
||||||
return gpg_error_from_syserror ();
|
return my_error_from_syserror ();
|
||||||
parm->fd = fd;
|
parm->fd = fd;
|
||||||
parm->data = data;
|
parm->data = data;
|
||||||
parm->datalen = datalen;
|
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);
|
ret = npth_create (&thread, &tattr, writer_thread_main, parm);
|
||||||
if (ret)
|
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));
|
log_error ("error spawning writer thread: %s\n", gpg_strerror (err));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -304,7 +317,7 @@ reader_thread_main (void *arg)
|
|||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
err = gpg_error_from_syserror ();
|
err = my_error_from_syserror ();
|
||||||
break; /* Read error. */
|
break; /* Read error. */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +370,7 @@ start_reader (int fd, membuf_t *mb, estream_t stream,
|
|||||||
|
|
||||||
parm = xtrymalloc (sizeof *parm);
|
parm = xtrymalloc (sizeof *parm);
|
||||||
if (!parm)
|
if (!parm)
|
||||||
return gpg_error_from_syserror ();
|
return my_error_from_syserror ();
|
||||||
parm->fd = fd;
|
parm->fd = fd;
|
||||||
parm->mb = mb;
|
parm->mb = mb;
|
||||||
parm->stream = stream;
|
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);
|
ret = npth_create (&thread, &tattr, reader_thread_main, parm);
|
||||||
if (ret)
|
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));
|
log_error ("error spawning reader thread: %s\n", gpg_strerror (err));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -474,7 +487,7 @@ _gpg_encrypt (ctrl_t ctrl,
|
|||||||
ret = npth_join (reader_thread, NULL);
|
ret = npth_join (reader_thread, NULL);
|
||||||
if (ret)
|
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));
|
log_error ("waiting for reader thread failed: %s\n", gpg_strerror (err));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -491,7 +504,7 @@ _gpg_encrypt (ctrl_t ctrl,
|
|||||||
ret = npth_join (writer_thread, NULL);
|
ret = npth_join (writer_thread, NULL);
|
||||||
if (ret)
|
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));
|
log_error ("waiting for writer thread failed: %s\n", gpg_strerror (err));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -549,7 +562,7 @@ gpg_encrypt_blob (ctrl_t ctrl,
|
|||||||
*r_ciph = get_membuf (&reader_mb, r_ciphlen);
|
*r_ciph = get_membuf (&reader_mb, r_ciphlen);
|
||||||
if (!*r_ciph)
|
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",
|
log_error ("error while storing the data in the reader thread: %s\n",
|
||||||
gpg_strerror (err));
|
gpg_strerror (err));
|
||||||
}
|
}
|
||||||
@ -646,7 +659,7 @@ _gpg_decrypt (ctrl_t ctrl,
|
|||||||
ret = npth_join (reader_thread, NULL);
|
ret = npth_join (reader_thread, NULL);
|
||||||
if (ret)
|
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));
|
log_error ("waiting for reader thread failed: %s\n", gpg_strerror (err));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -662,7 +675,7 @@ _gpg_decrypt (ctrl_t ctrl,
|
|||||||
ret = npth_join (writer_thread, NULL);
|
ret = npth_join (writer_thread, NULL);
|
||||||
if (ret)
|
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));
|
log_error ("waiting for writer thread failed: %s\n", gpg_strerror (err));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -717,7 +730,7 @@ gpg_decrypt_blob (ctrl_t ctrl,
|
|||||||
*r_plain = get_membuf (&reader_mb, r_plainlen);
|
*r_plain = get_membuf (&reader_mb, r_plainlen);
|
||||||
if (!*r_plain)
|
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",
|
log_error ("error while storing the data in the reader thread: %s\n",
|
||||||
gpg_strerror (err));
|
gpg_strerror (err));
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,13 @@ typedef struct
|
|||||||
} read_and_log_buffer_t;
|
} 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
|
static void
|
||||||
read_and_log_stderr (read_and_log_buffer_t *state, es_poll_t *fderr)
|
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))
|
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",
|
log_error ("error reading stderr of '%s': %s\n",
|
||||||
state->pgmname, gpg_strerror (err));
|
state->pgmname, gpg_strerror (err));
|
||||||
fderr->ignore = 1; /* Disable. */
|
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)
|
if (errno == EAGAIN)
|
||||||
return 0; /* We will just retry next time. */
|
return 0; /* We will just retry next time. */
|
||||||
|
|
||||||
return gpg_error_from_syserror ();
|
return my_error_from_syserror ();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (c->nread <= sizeof c->buffer);
|
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)
|
if (errno == EAGAIN)
|
||||||
return 0; /* We will just retry next time. */
|
return 0; /* We will just retry next time. */
|
||||||
|
|
||||||
return gpg_error_from_syserror ();
|
return my_error_from_syserror ();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (nwritten <= c->nread);
|
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);
|
assert (c->writep - c->buffer <= sizeof c->buffer);
|
||||||
|
|
||||||
if (es_fflush (sink) && errno != EAGAIN)
|
if (es_fflush (sink) && errno != EAGAIN)
|
||||||
err = gpg_error_from_syserror ();
|
err = my_error_from_syserror ();
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -272,7 +279,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
|
|||||||
count = es_poll (fds, DIM(fds), -1);
|
count = es_poll (fds, DIM(fds), -1);
|
||||||
if (count == -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));
|
log_error ("error polling '%s': %s\n", pgmname, gpg_strerror (err));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -391,13 +398,13 @@ gnupg_exec_tool (const char *pgmname, const char *argv[],
|
|||||||
input = es_mopen ((char *) input_string, len, len,
|
input = es_mopen ((char *) input_string, len, len,
|
||||||
0 /* don't grow */, NULL, nop_free, "rb");
|
0 /* don't grow */, NULL, nop_free, "rb");
|
||||||
if (! input)
|
if (! input)
|
||||||
return gpg_error_from_syserror ();
|
return my_error_from_syserror ();
|
||||||
}
|
}
|
||||||
|
|
||||||
output = es_fopenmem (0, "wb");
|
output = es_fopenmem (0, "wb");
|
||||||
if (! output)
|
if (! output)
|
||||||
{
|
{
|
||||||
err = gpg_error_from_syserror ();
|
err = my_error_from_syserror ();
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +420,7 @@ gnupg_exec_tool (const char *pgmname, const char *argv[],
|
|||||||
*result = xtrymalloc (len);
|
*result = xtrymalloc (len);
|
||||||
if (*result == NULL)
|
if (*result == NULL)
|
||||||
{
|
{
|
||||||
err = gpg_error_from_syserror ();
|
err = my_error_from_syserror ();
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user