diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-06-28 01:55:26 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-06-28 01:55:26 +0800 |
commit | 29d21a6a098383604887d0e1205a03a1a231d0b4 (patch) | |
tree | 4150a302ea3718260f9411b56b21de9ec98cfd85 /camel/camel-gpg-context.c | |
parent | 95d75ed01d0e8590de62cdeef7a102442dc0121f (diff) | |
download | gsoc2013-evolution-29d21a6a098383604887d0e1205a03a1a231d0b4.tar.gz gsoc2013-evolution-29d21a6a098383604887d0e1205a03a1a231d0b4.tar.zst gsoc2013-evolution-29d21a6a098383604887d0e1205a03a1a231d0b4.zip |
Loop on our reads while errno is EINTR or EAGAIN. Also make sure to
2002-06-27 Jeffrey Stedfast <fejj@ximian.com>
* camel-gpg-context.c (gpg_ctx_op_step): Loop on our reads while
errno is EINTR or EAGAIN. Also make sure to completely read stdout
and stderr by keeping better state.
svn path=/trunk/; revision=17311
Diffstat (limited to 'camel/camel-gpg-context.c')
-rw-r--r-- | camel/camel-gpg-context.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c index 6994337ecc..2483a10c59 100644 --- a/camel/camel-gpg-context.c +++ b/camel/camel-gpg-context.c @@ -250,8 +250,8 @@ struct _GpgCtx { GByteArray *diagnostics; unsigned int complete:1; - unsigned int await_read:1; - unsigned int reading:2; + unsigned int seen_eof1:1; + unsigned int seen_eof2:1; unsigned int always_trust:1; unsigned int armor:1; unsigned int need_passwd:1; @@ -262,7 +262,7 @@ struct _GpgCtx { unsigned int validsig:1; unsigned int trust:3; - unsigned int padding:18; + unsigned int padding:19; }; static struct _GpgCtx * @@ -276,8 +276,8 @@ gpg_ctx_new (CamelSession *session, const char *path) camel_object_ref (CAMEL_OBJECT (session)); gpg->userid_hint = g_hash_table_new (g_str_hash, g_str_equal); gpg->complete = FALSE; - gpg->await_read = FALSE; - gpg->reading = 0; + gpg->seen_eof1 = FALSE; + gpg->seen_eof2 = FALSE; gpg->pid = (pid_t) -1; gpg->path = g_strdup (path); @@ -787,7 +787,6 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) case GPG_CTX_MODE_SIGN: if (!strncmp (status, "SIG_CREATED ", 12)) { gpg->complete = TRUE; - gpg->await_read = TRUE; } break; case GPG_CTX_MODE_VERIFY: @@ -804,21 +803,23 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) } gpg->complete = TRUE; + + /* Since verifying a signature will never produce output + on gpg's stdout descriptor, we use this EOF bit for + making sure that we get a TRUST metric. */ + gpg->seen_eof1 = TRUE; } else if (!strncmp (status, "VALIDSIG", 8)) { gpg->validsig = TRUE; - gpg->complete = TRUE; } else if (!strncmp (status, "BADSIG", 6)) { gpg->validsig = FALSE; - gpg->complete = TRUE; } else if (!strncmp (status, "ERRSIG", 6)) { /* Note: NO_PUBKEY often comes after an ERRSIG, but do we really care? */ gpg->validsig = FALSE; - gpg->complete = TRUE; } break; case GPG_CTX_MODE_ENCRYPT: if (!strncmp (status, "BEGIN_ENCRYPTION", 16)) { - gpg->await_read = TRUE; + /* nothing to do... but we know to expect data on stdout soon */ } else if (!strncmp (status, "END_ENCRYPTION", 14)) { gpg->complete = TRUE; } else if (!strncmp (status, "NO_RECP", 7)) { @@ -829,7 +830,7 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex) break; case GPG_CTX_MODE_DECRYPT: if (!strncmp (status, "BEGIN_DECRYPTION", 16)) { - gpg->await_read = TRUE; + /* nothing to do... but we know to expect data on stdout soon */ } else if (!strncmp (status, "END_DECRYPTION", 14)) { gpg->complete = TRUE; } @@ -930,7 +931,7 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex) can to all of them. If one fails along the way, return -1. */ - if (FD_ISSET (gpg->status_fd, &rdset) && !gpg->complete) { + if (FD_ISSET (gpg->status_fd, &rdset)) { /* read the status message and decide what to do... */ char buffer[4096]; ssize_t nread; @@ -951,7 +952,6 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex) } } - gpg->reading--; if (FD_ISSET (gpg->stdout, &rdset) && gpg->ostream) { char buffer[4096]; ssize_t nread; @@ -967,11 +967,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex) if (nread > 0) { if (camel_stream_write (gpg->ostream, buffer, (size_t) nread) == -1) goto exception; - - gpg->await_read = FALSE; - - /* make sure we don't exit before reading all the data... */ - gpg->reading = 3; + } else { + gpg->seen_eof1 = TRUE; } } @@ -989,9 +986,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex) if (nread > 0) { g_byte_array_append (gpg->diagnostics, buffer, nread); - - /* make sure we don't exit before reading all the data... */ - gpg->reading = 3; + } else { + gpg->seen_eof2 = TRUE; } } @@ -1094,7 +1090,7 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex) static gboolean gpg_ctx_op_complete (struct _GpgCtx *gpg) { - return gpg->complete && !gpg->await_read && !gpg->reading; + return gpg->complete && gpg->seen_eof1 && gpg->seen_eof2; } static void |