mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Take advantage of newer gpg-error features.
This commit is contained in:
parent
9577dd45ab
commit
03d3322e5f
55 changed files with 297 additions and 260 deletions
|
@ -1,3 +1,11 @@
|
|||
2006-09-14 Werner Koch <wk@g10code.com>
|
||||
|
||||
* util.h (out_of_core): Use new gpg_error_from_syserror function.
|
||||
|
||||
* http.c (init_sockets): Changed it to require 2.2 unless it is
|
||||
build within gnupg 1 where we require 1.1 (and not anymore allow
|
||||
for 1.0).
|
||||
|
||||
2006-09-07 Werner Koch <wk@g10code.com>
|
||||
|
||||
* exechelp.c (gnupg_spawn_process): Factor out post fork code to ..
|
||||
|
|
|
@ -44,7 +44,7 @@ send_one_option (assuan_context_t ctx, gpg_err_source_t errsource,
|
|||
if (!value || !*value)
|
||||
err = 0; /* Avoid sending empty strings. */
|
||||
else if (asprintf (&optstr, "OPTION %s=%s", name, value ) < 0)
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
else
|
||||
{
|
||||
err = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
@ -116,7 +116,7 @@ send_pinentry_environment (assuan_context_t ctx,
|
|||
{
|
||||
old_lc = strdup (old_lc);
|
||||
if (!old_lc)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
dft_lc = setlocale (LC_CTYPE, "");
|
||||
#endif
|
||||
|
@ -142,7 +142,7 @@ send_pinentry_environment (assuan_context_t ctx,
|
|||
{
|
||||
old_lc = strdup (old_lc);
|
||||
if (!old_lc)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
dft_lc = setlocale (LC_MESSAGES, "");
|
||||
#endif
|
||||
|
|
|
@ -57,7 +57,7 @@ b64enc_start (struct b64state *state, FILE *fp, const char *title)
|
|||
{
|
||||
state->title = xtrystrdup (title);
|
||||
if (!state->title)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ b64enc_write (struct b64state *state, const void *buffer, size_t nbytes)
|
|||
return 0;
|
||||
|
||||
write_error:
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
|
||||
gpg_error_t
|
||||
|
@ -200,7 +200,7 @@ b64enc_finish (struct b64state *state)
|
|||
goto cleanup;
|
||||
|
||||
write_error:
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
|
||||
cleanup:
|
||||
if (state->title)
|
||||
|
|
|
@ -96,7 +96,7 @@ build_w32_commandline (const char *pgmname, const char **argv, char **cmdline)
|
|||
|
||||
buf = p = xtrymalloc (n);
|
||||
if (!buf)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
/* fixme: PGMNAME may not contain spaces etc. */
|
||||
p = stpcpy (p, pgmname);
|
||||
|
@ -342,7 +342,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||
}
|
||||
if (!*statusfile)
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error (_("can't fdopen pipe for reading: %s\n"), gpg_strerror (err));
|
||||
CloseHandle (pi.hProcess);
|
||||
return err;
|
||||
|
@ -366,7 +366,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||
|
||||
if (pipe (rp) == -1)
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error (_("error creating a pipe: %s\n"), strerror (errno));
|
||||
return err;
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||
#endif
|
||||
if (*pid == (pid_t)(-1))
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error (_("error forking process: %s\n"), strerror (errno));
|
||||
close (rp[0]);
|
||||
close (rp[1]);
|
||||
|
@ -399,7 +399,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||
*statusfile = fdopen (rp[0], "r");
|
||||
if (!*statusfile)
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error (_("can't fdopen pipe for reading: %s\n"), strerror (errno));
|
||||
kill (*pid, SIGTERM);
|
||||
*pid = (pid_t)(-1);
|
||||
|
@ -528,7 +528,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
|
|||
return gpg_error (GPG_ERR_BUG);
|
||||
|
||||
if (access (pgmname, X_OK))
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
#ifdef USE_GNU_PTH
|
||||
pid = pth_fork? pth_fork () : fork ();
|
||||
|
@ -538,7 +538,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
|
|||
if (pid == (pid_t)(-1))
|
||||
{
|
||||
log_error (_("error forking process: %s\n"), strerror (errno));
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
if (!pid)
|
||||
{
|
||||
|
|
|
@ -200,6 +200,16 @@ struct http_context_s
|
|||
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
|
||||
#if GNUPG_MAJOR_VERSION == 1
|
||||
#define REQ_WINSOCK_MAJOR 1
|
||||
#define REQ_WINSOCK_MINOR 1
|
||||
#else
|
||||
#define REQ_WINSOCK_MAJOR 2
|
||||
#define REQ_WINSOCK_MINOR 2
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
deinit_sockets (void)
|
||||
{
|
||||
|
@ -215,16 +225,18 @@ init_sockets (void)
|
|||
if (initialized)
|
||||
return;
|
||||
|
||||
if ( WSAStartup( 0x0101, &wsdata ) )
|
||||
if ( WSAStartup( MAKEWORD (REQ_WINSOCK_MINOR, REQ_WINSOCK_MAJOR), &wsdata ) )
|
||||
{
|
||||
log_error ("error initializing socket library: ec=%d\n",
|
||||
(int)WSAGetLastError () );
|
||||
return;
|
||||
}
|
||||
if ( wsdata.wVersion < 0x0001 )
|
||||
if ( LOBYTE(wsdata.wVersion) != REQ_WINSOCK_MAJOR
|
||||
|| HIBYTE(wsdata.wVersion) != REQ_WINSOCK_MINOR )
|
||||
{
|
||||
log_error ("socket library version is %x.%x - but 1.1 needed\n",
|
||||
LOBYTE(wsdata.wVersion), HIBYTE(wsdata.wVersion));
|
||||
log_error ("socket library version is %x.%x - but %d.%d needed\n",
|
||||
LOBYTE(wsdata.wVersion), HIBYTE(wsdata.wVersion)
|
||||
REQ_WINSOCK_MAJOR, REQ_WINSOCK_MINOR);
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
@ -313,7 +325,7 @@ http_open (http_t *r_hd, http_req_t reqtype, const char *url,
|
|||
/* Create the handle. */
|
||||
hd = xtrycalloc (1, sizeof *hd);
|
||||
if (!hd)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
hd->sock = -1;
|
||||
hd->req_type = reqtype;
|
||||
hd->flags = flags;
|
||||
|
@ -383,7 +395,7 @@ http_wait_response (http_t hd)
|
|||
{
|
||||
hd->sock = dup (hd->sock);
|
||||
if (hd->sock == -1)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
P_ES(fclose) (hd->fp_write);
|
||||
hd->fp_write = NULL;
|
||||
|
@ -401,7 +413,7 @@ http_wait_response (http_t hd)
|
|||
|
||||
cookie = xtrycalloc (1, sizeof *cookie);
|
||||
if (!cookie)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
cookie->fd = hd->sock;
|
||||
if (hd->uri->use_tls)
|
||||
cookie->tls_session = hd->tls_context;
|
||||
|
@ -410,13 +422,13 @@ http_wait_response (http_t hd)
|
|||
if (!hd->fp_read)
|
||||
{
|
||||
xfree (cookie);
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
}
|
||||
#else /*!HTTP_USE_ESTREAM*/
|
||||
hd->fp_read = fdopen (hd->sock, "r");
|
||||
if (!hd->fp_read)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
#endif /*!HTTP_USE_ESTREAM*/
|
||||
|
||||
err = parse_response (hd);
|
||||
|
@ -851,7 +863,7 @@ send_request (http_t hd, const char *auth, const char *proxy)
|
|||
uri->auth, strlen(uri->auth));
|
||||
if (!proxy_authstr)
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
http_release_parsed_uri (uri);
|
||||
return err;
|
||||
}
|
||||
|
@ -919,7 +931,7 @@ send_request (http_t hd, const char *auth, const char *proxy)
|
|||
if (!myauth)
|
||||
{
|
||||
xfree (proxy_authstr);
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
remove_escapes (myauth);
|
||||
}
|
||||
|
@ -937,13 +949,13 @@ send_request (http_t hd, const char *auth, const char *proxy)
|
|||
if (!authstr)
|
||||
{
|
||||
xfree (proxy_authstr);
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
}
|
||||
|
||||
p = build_rel_path (hd->uri);
|
||||
if (!p)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
|
||||
request = xtrymalloc (2 * strlen (server)
|
||||
+ strlen (p)
|
||||
|
@ -952,7 +964,7 @@ send_request (http_t hd, const char *auth, const char *proxy)
|
|||
+ 100);
|
||||
if (!request)
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
xfree (p);
|
||||
xfree (authstr);
|
||||
xfree (proxy_authstr);
|
||||
|
@ -997,7 +1009,7 @@ send_request (http_t hd, const char *auth, const char *proxy)
|
|||
cookie = xtrycalloc (1, sizeof *cookie);
|
||||
if (!cookie)
|
||||
{
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
goto leave;
|
||||
}
|
||||
cookie->fd = hd->sock;
|
||||
|
@ -1011,10 +1023,10 @@ send_request (http_t hd, const char *auth, const char *proxy)
|
|||
if (!hd->fp_write)
|
||||
{
|
||||
xfree (cookie);
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
}
|
||||
else if (es_fputs (request, hd->fp_write) || es_fflush (hd->fp_write))
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
else
|
||||
err = 0;
|
||||
}
|
||||
|
@ -1030,7 +1042,7 @@ send_request (http_t hd, const char *auth, const char *proxy)
|
|||
{
|
||||
hd->fp_write = fdopen (hd->sock, "w");
|
||||
if (!hd->fp_write)
|
||||
err = gpg_error_from_errno (errno);
|
||||
err = gpg_error_from_syserror ();
|
||||
}
|
||||
#endif /*!HTTP_USE_ESTREAM*/
|
||||
|
||||
|
@ -1237,7 +1249,7 @@ store_header (http_t hd, char *line)
|
|||
n += strlen (hd->headers->value);
|
||||
p = xtrymalloc (n+1);
|
||||
if (!p)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
strcpy (stpcpy (p, hd->headers->value), line);
|
||||
xfree (hd->headers->value);
|
||||
hd->headers->value = p;
|
||||
|
@ -1262,7 +1274,7 @@ store_header (http_t hd, char *line)
|
|||
it is a comma separated list and merge them. */
|
||||
p = xtrymalloc (strlen (h->value) + 1 + strlen (value)+ 1);
|
||||
if (!p)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
strcpy (stpcpy (stpcpy (p, h->value), ","), value);
|
||||
xfree (h->value);
|
||||
h->value = p;
|
||||
|
@ -1272,13 +1284,13 @@ store_header (http_t hd, char *line)
|
|||
/* Append a new header. */
|
||||
h = xtrymalloc (sizeof *h + strlen (line));
|
||||
if (!h)
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
strcpy (h->name, line);
|
||||
h->value = xtrymalloc (strlen (value)+1);
|
||||
if (!h->value)
|
||||
{
|
||||
xfree (h);
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
strcpy (h->value, value);
|
||||
h->next = hd->headers;
|
||||
|
@ -1334,7 +1346,7 @@ parse_response (http_t hd)
|
|||
len = my_read_line (hd->fp_read, &hd->buffer, &hd->buffer_size, &maxlen);
|
||||
line = hd->buffer;
|
||||
if (!line)
|
||||
return gpg_error_from_errno (errno); /* Out of core. */
|
||||
return gpg_error_from_syserror (); /* Out of core. */
|
||||
if (!maxlen)
|
||||
return gpg_error (GPG_ERR_TRUNCATED); /* Line has been truncated. */
|
||||
if (!len)
|
||||
|
@ -1378,7 +1390,7 @@ parse_response (http_t hd)
|
|||
len = my_read_line (hd->fp_read, &hd->buffer, &hd->buffer_size, &maxlen);
|
||||
line = hd->buffer;
|
||||
if (!line)
|
||||
return gpg_error_from_errno (errno); /* Out of core. */
|
||||
return gpg_error_from_syserror (); /* Out of core. */
|
||||
/* Note, that we can silently ignore truncated lines. */
|
||||
if (!len)
|
||||
return gpg_error (GPG_ERR_EOF);
|
||||
|
@ -1700,7 +1712,7 @@ write_server (int sock, const char *data, size_t length)
|
|||
continue;
|
||||
}
|
||||
log_info ("network write failed: %s\n", strerror (errno));
|
||||
return gpg_error_from_errno (errno);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
#endif /*!HAVE_W32_SYSTEM*/
|
||||
nleft -= nwritten;
|
||||
|
|
|
@ -392,7 +392,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
|
|||
}
|
||||
else if (ferror (f) && errno != EPIPE)
|
||||
{
|
||||
rc = gpg_error_from_errno (errno);
|
||||
rc = gpg_error_from_syserror ();
|
||||
log_error ("%s: read error: %s\n", a->fname, strerror (errno));
|
||||
}
|
||||
*ret_len = nbytes;
|
||||
|
@ -406,7 +406,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
|
|||
nbytes = fwrite (buf, 1, size, f);
|
||||
if (ferror (f))
|
||||
{
|
||||
rc = gpg_error_from_errno (errno);
|
||||
rc = gpg_error_from_syserror ();
|
||||
log_error ("%s: write error: %s\n", a->fname, strerror (errno));
|
||||
}
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
|
|||
{ /* error */
|
||||
if (errno != EPIPE)
|
||||
{
|
||||
rc = gpg_error_from_errno (errno);
|
||||
rc = gpg_error_from_syserror ();
|
||||
log_error ("%s: read error: %s\n",
|
||||
a->fname, strerror (errno));
|
||||
}
|
||||
|
@ -543,7 +543,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf,
|
|||
while (n != -1 && nbytes);
|
||||
if (n == -1)
|
||||
{
|
||||
rc = gpg_error_from_errno (errno);
|
||||
rc = gpg_error_from_syserror ();
|
||||
log_error ("%s: write error: %s\n", a->fname, strerror (errno));
|
||||
}
|
||||
nbytes = p - buf;
|
||||
|
@ -849,14 +849,14 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer,
|
|||
{ /* write stuff from the buffer */
|
||||
assert (n == OP_MIN_PARTIAL_CHUNK);
|
||||
if (iobuf_write (chain, a->buffer, n))
|
||||
rc = gpg_error_from_errno (errno);
|
||||
rc = gpg_error_from_syserror ();
|
||||
a->buflen = 0;
|
||||
nbytes -= n;
|
||||
}
|
||||
if ((n = nbytes) > blen)
|
||||
n = blen;
|
||||
if (n && iobuf_write (chain, p, n))
|
||||
rc = gpg_error_from_errno (errno);
|
||||
rc = gpg_error_from_syserror ();
|
||||
p += n;
|
||||
nbytes -= n;
|
||||
}
|
||||
|
@ -935,7 +935,7 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer,
|
|||
{
|
||||
log_error ("block_filter: write error: %s\n",
|
||||
strerror (errno));
|
||||
rc = gpg_error_from_errno (errno);
|
||||
rc = gpg_error_from_syserror ();
|
||||
}
|
||||
xfree (a->buffer);
|
||||
a->buffer = NULL;
|
||||
|
@ -1649,7 +1649,7 @@ underflow (iobuf_t a)
|
|||
if (len < a->d.size)
|
||||
{
|
||||
if (ferror (fp))
|
||||
a->error = gpg_error_from_errno (errno);
|
||||
a->error = gpg_error_from_syserror ();
|
||||
}
|
||||
a->d.len = len;
|
||||
a->d.start = 0;
|
||||
|
|
|
@ -99,7 +99,7 @@ is_file_compressed (const char *s, int *ret_rc)
|
|||
|
||||
a = iobuf_open( s );
|
||||
if ( a == NULL ) {
|
||||
*ret_rc = gpg_error_from_errno (errno);
|
||||
*ret_rc = gpg_error_from_syserror ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,9 +71,7 @@
|
|||
static inline gpg_error_t
|
||||
out_of_core (void)
|
||||
{
|
||||
return gpg_error (errno
|
||||
? gpg_err_code_from_errno(errno)
|
||||
: GPG_ERR_MISSING_ERRNO);
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
|
||||
/* A type to hold the ISO time. Note that this this is the same as
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue