2002-01-22 Marcus Brinkmann <marcus@g10code.de>

* wait.c (_gpgme_wait_on_condition): If the process finished,
	reset the pending flag.  Also if the operation was cancelled.

	(struct proc_s): Rename READY to DONE.
	(wait_item_s): Likewise.
	(set_process_ready): Rename to ...
	(set_process_done): ... this.
	(_gpgme_remove_proc_from_wait_queue): Call set_process_done
	instead set_process_ready.
	(_gpgme_wait_on_condition): Likewise.
	(do_select): Rename READY to DONE.

	* verify.c (gpgme_op_verify): Do not set pending to zero here.
	* sign.c (gpgme_op_sign): Likewise.
	* import.c (gpgme_op_import): Likewise.
	* genkey.c (gpgme_op_genkey): Likewise.
	* export.c (gpgme_op_export): Likewise.
	* encrypt.c (gpgme_op_encrypt): Likewise.
	* delete.c (gpgme_op_delete): Likewise.
	* decrypt-verify.c (gpgme_op_decrypt_verify): Likewise.
	* decrypt.c (gpgme_op_decrypt): Likewise.
This commit is contained in:
Marcus Brinkmann 2002-01-22 15:11:53 +00:00
parent abe732ef1c
commit 6f7d1bc770
12 changed files with 256 additions and 219 deletions

View File

@ -1,3 +1,27 @@
2002-01-22 Marcus Brinkmann <marcus@g10code.de>
* wait.c (_gpgme_wait_on_condition): If the process finished,
reset the pending flag. Also if the operation was cancelled.
(struct proc_s): Rename READY to DONE.
(wait_item_s): Likewise.
(set_process_ready): Rename to ...
(set_process_done): ... this.
(_gpgme_remove_proc_from_wait_queue): Call set_process_done
instead set_process_ready.
(_gpgme_wait_on_condition): Likewise.
(do_select): Rename READY to DONE.
* verify.c (gpgme_op_verify): Do not set pending to zero here.
* sign.c (gpgme_op_sign): Likewise.
* import.c (gpgme_op_import): Likewise.
* genkey.c (gpgme_op_genkey): Likewise.
* export.c (gpgme_op_export): Likewise.
* encrypt.c (gpgme_op_encrypt): Likewise.
* delete.c (gpgme_op_delete): Likewise.
* decrypt-verify.c (gpgme_op_decrypt_verify): Likewise.
* decrypt.c (gpgme_op_decrypt): Likewise.
2002-01-22 Marcus Brinkmann <marcus@g10code.de> 2002-01-22 Marcus Brinkmann <marcus@g10code.de>
* export.c: Cleanup. * export.c: Cleanup.

View File

@ -74,7 +74,6 @@ gpgme_op_decrypt_verify (GpgmeCtx ctx,
if (! err) if (! err)
*r_stat = _gpgme_intersect_stati (ctx->result.verify); *r_stat = _gpgme_intersect_stati (ctx->result.verify);
} }
ctx->pending = 0;
} }
return err; return err;
} }

View File

@ -195,7 +195,6 @@ gpgme_op_decrypt (GpgmeCtx ctx, GpgmeData in, GpgmeData out)
{ {
gpgme_wait (ctx, 1); gpgme_wait (ctx, 1);
err = _gpgme_decrypt_result (ctx); err = _gpgme_decrypt_result (ctx);
ctx->pending = 0;
} }
return err; return err;
} }

View File

@ -102,17 +102,13 @@ gpgme_op_delete_start (GpgmeCtx ctx, const GpgmeKey key, int allow_secret)
* Return value: 0 on success or an error code. * Return value: 0 on success or an error code.
**/ **/
GpgmeError GpgmeError
gpgme_op_delete ( GpgmeCtx c, const GpgmeKey key, int allow_secret ) gpgme_op_delete (GpgmeCtx ctx, const GpgmeKey key, int allow_secret)
{ {
int rc = gpgme_op_delete_start ( c, key, allow_secret ); GpgmeError err = gpgme_op_delete_start (ctx, key, allow_secret);
if ( !rc ) { if (!err)
gpgme_wait (c, 1); {
c->pending = 0; gpgme_wait (ctx, 1);
/* FIXME: check for success */ /* FIXME: check for success */
} }
return rc; return err;
} }

View File

@ -227,7 +227,6 @@ gpgme_op_encrypt ( GpgmeCtx c, GpgmeRecipients recp,
if (c->result.encrypt->no_recipients) if (c->result.encrypt->no_recipients)
err = mk_error (No_Recipients); err = mk_error (No_Recipients);
} }
c->pending = 0;
/* Old gpg versions don't return status info for invalid /* Old gpg versions don't return status info for invalid
* recipients, so we simply check whether we got any output at * recipients, so we simply check whether we got any output at
* all and if not assume that we don't have valid recipients * all and if not assume that we don't have valid recipients

View File

@ -94,9 +94,6 @@ gpgme_op_export (GpgmeCtx ctx, GpgmeRecipients recipients, GpgmeData keydata)
{ {
GpgmeError err = gpgme_op_export_start (ctx, recipients, keydata); GpgmeError err = gpgme_op_export_start (ctx, recipients, keydata);
if (!err) if (!err)
{
gpgme_wait (ctx, 1); gpgme_wait (ctx, 1);
ctx->pending = 0;
}
return err; return err;
} }

View File

@ -204,15 +204,13 @@ gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms,
* Return value: 0 for success or an error code * Return value: 0 for success or an error code
**/ **/
GpgmeError GpgmeError
gpgme_op_genkey( GpgmeCtx c, const char *parms, gpgme_op_genkey (GpgmeCtx ctx, const char *parms,
GpgmeData pubkey, GpgmeData seckey) GpgmeData pubkey, GpgmeData seckey)
{ {
int rc = gpgme_op_genkey_start ( c, parms, pubkey, seckey ); GpgmeError err = gpgme_op_genkey_start (ctx, parms, pubkey, seckey);
if ( !rc ) { if (!err)
gpgme_wait (c, 1); gpgme_wait (ctx, 1);
c->pending = 0; return err;
}
return rc;
} }

View File

@ -89,14 +89,12 @@ gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata)
* Return value: o on success or an error code. * Return value: o on success or an error code.
**/ **/
GpgmeError GpgmeError
gpgme_op_import ( GpgmeCtx c, GpgmeData keydata ) gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata)
{ {
int rc = gpgme_op_import_start ( c, keydata ); GpgmeError err = gpgme_op_import_start (ctx, keydata);
if ( !rc ) { if (!err)
gpgme_wait (c, 1); gpgme_wait (ctx, 1);
c->pending = 0; return err;
}
return rc;
} }

View File

@ -277,7 +277,6 @@ gpgme_op_sign (GpgmeCtx ctx, GpgmeData in, GpgmeData out, GpgmeSigMode mode)
err = mk_error (No_Data); /* Hmmm: choose a better error? */ err = mk_error (No_Data); /* Hmmm: choose a better error? */
} }
} }
ctx->pending = 0;
} }
return err; return err;
} }

View File

@ -355,7 +355,6 @@ gpgme_op_verify ( GpgmeCtx c, GpgmeData sig, GpgmeData text,
} }
*r_stat = _gpgme_intersect_stati (c->result.verify); *r_stat = _gpgme_intersect_stati (c->result.verify);
} }
c->pending = 0;
} }
return rc; return rc;
} }

View File

@ -54,7 +54,7 @@ struct proc_s {
int pid; int pid;
GpgmeCtx ctx; GpgmeCtx ctx;
struct wait_item_s *handler_list; struct wait_item_s *handler_list;
int ready; int done;
}; };
struct wait_item_s { struct wait_item_s {
@ -63,7 +63,7 @@ struct wait_item_s {
void *handler_value; void *handler_value;
int inbound; /* this is an inbound data handler fd */ int inbound; /* this is an inbound data handler fd */
struct proc_s *proc; /* backlink */ struct proc_s *proc; /* backlink */
int ready; int done;
int frozen; /* copy of the frozen flag from the fd_table */ int frozen; /* copy of the frozen flag from the fd_table */
}; };
@ -80,8 +80,9 @@ count_running_fds ( struct proc_s *proc )
struct wait_item_s *q; struct wait_item_s *q;
int count = 0; int count = 0;
for (q=proc->handler_list; q; q=q->next) { for (q = proc->handler_list; q; q=q->next)
if ( !q->frozen && !q->ready ) {
if (!q->frozen && !q->done)
count++; count++;
} }
return count; return count;
@ -89,18 +90,21 @@ count_running_fds ( struct proc_s *proc )
/* only to be called with a locked proc_queue */ /* only to be called with a locked proc_queue */
static void static void
set_process_ready ( struct proc_s *proc ) set_process_done (struct proc_s *proc)
{ {
struct wait_item_s *q, *q2; struct wait_item_s *q, *q2;
int i; int i;
assert (proc); assert (proc);
DEBUG2 ("set_process_ready(%p) pid=%d", proc, proc->pid ); DEBUG2 ("set_process_done(%p) pid=%d", proc, proc->pid);
LOCK (fd_table_lock); LOCK (fd_table_lock);
for (q = proc->handler_list; q; q=q2) { for (q = proc->handler_list; q; q=q2)
{
q2 = q->next; q2 = q->next;
for (i=0; i < fd_table_size; i++ ) { for (i = 0; i < fd_table_size; i++)
if (fd_table[i].fd != -1 && q == fd_table[i].opaque ) { {
if (fd_table[i].fd != -1 && q == fd_table[i].opaque)
{
fd_table[i].opaque = NULL; fd_table[i].opaque = NULL;
fd_table[i].fd = -1; fd_table[i].fd = -1;
} }
@ -109,7 +113,7 @@ set_process_ready ( struct proc_s *proc )
} }
UNLOCK (fd_table_lock); UNLOCK (fd_table_lock);
proc->handler_list = NULL; proc->handler_list = NULL;
proc->ready = 1; proc->done = 1;
} }
void void
@ -119,9 +123,11 @@ _gpgme_remove_proc_from_wait_queue ( int pid )
DEBUG1 ("removing process %d", pid); DEBUG1 ("removing process %d", pid);
LOCK (proc_queue_lock); LOCK (proc_queue_lock);
for (last=NULL, proc=proc_queue; proc; last = proc, proc = proc->next ) { for (last = NULL, proc = proc_queue; proc; last = proc, proc = proc->next)
if (proc->pid == pid ) { {
set_process_ready (proc); if (proc->pid == pid)
{
set_process_done (proc);
if (!last) if (!last)
proc_queue = proc->next; proc_queue = proc->next;
else else
@ -148,16 +154,17 @@ _gpgme_remove_proc_from_wait_queue ( int pid )
* and no (or the given) request has finished. * and no (or the given) request has finished.
**/ **/
GpgmeCtx GpgmeCtx
gpgme_wait ( GpgmeCtx c, int hang ) gpgme_wait (GpgmeCtx ctx, int hang)
{ {
return _gpgme_wait_on_condition ( c, hang, NULL ); return _gpgme_wait_on_condition (ctx, hang, NULL);
} }
GpgmeCtx GpgmeCtx
_gpgme_wait_on_condition ( GpgmeCtx c, int hang, volatile int *cond ) _gpgme_wait_on_condition (GpgmeCtx ctx, int hang, volatile int *cond)
{
DEBUG3 ("waiting... ctx=%p hang=%d cond=%p", ctx, hang, cond);
do
{ {
DEBUG3 ("waiting... ctx=%p hang=%d cond=%p", c, hang, cond );
do {
int any = 0; int any = 0;
struct proc_s *proc; struct proc_s *proc;
@ -165,30 +172,38 @@ _gpgme_wait_on_condition ( GpgmeCtx c, int hang, volatile int *cond )
if (cond && *cond) if (cond && *cond)
hang = 0; hang = 0;
else { else
{
LOCK (proc_queue_lock); LOCK (proc_queue_lock);
for (proc=proc_queue; proc; proc = proc->next ) { for (proc = proc_queue; proc; proc = proc->next)
if ( !proc->ready && !count_running_fds (proc) ) { {
set_process_ready (proc); if (!proc->done && !count_running_fds (proc))
} set_process_done (proc);
if (c && proc->ready && proc->ctx == c) if (ctx && proc->done && proc->ctx == ctx)
{
hang = 0; hang = 0;
if ( !proc->ready ) ctx->pending = 0;
}
if (!proc->done)
any = 1; any = 1;
} }
UNLOCK (proc_queue_lock); UNLOCK (proc_queue_lock);
if (!any) if (!any)
hang = 0; hang = 0;
} }
/* fixme: we should check here for hanging processes */ /* fixme: We should check here for hanging processes. */
if (hang) if (hang)
run_idle (); run_idle ();
} while (hang && !c->cancel );
c->cancel = 0; /* fixme: fix all functions, to return a cancel error */
return c;
} }
while (hang && !ctx->cancel);
if (ctx->cancel)
{
ctx->cancel = 0; /* fixme: Fix all functions to return a cancel error. */
ctx->pending = 0;
}
return ctx;
}
/* /*
@ -210,9 +225,11 @@ do_select ( void )
if (n <= 0) if (n <= 0)
return 0; /* error or timeout */ return 0; /* error or timeout */
for (i=0; i < fd_table_size && n; i++ ) { for (i = 0; i < fd_table_size && n; i++)
{
if (fd_table[i].fd != -1 && fd_table[i].signaled if (fd_table[i].fd != -1 && fd_table[i].signaled
&& !fd_table[i].frozen ) { && !fd_table[i].frozen)
{
struct wait_item_s *q; struct wait_item_s *q;
assert (n); assert (n);
@ -221,13 +238,14 @@ do_select ( void )
q = fd_table[i].opaque; q = fd_table[i].opaque;
assert (q); assert (q);
assert (q->proc); assert (q->proc);
assert ( !q->ready ); assert (!q->done);
any = 1; any = 1;
if (q->handler (q->handler_value, if (q->handler (q->handler_value,
q->proc->pid, fd_table[i].fd ) ) { q->proc->pid, fd_table[i].fd))
DEBUG2 ("setting fd %d (q=%p) ready", fd_table[i].fd, q ); {
q->ready = 1; DEBUG2 ("setting fd %d (q=%p) done", fd_table[i].fd, q);
/* free the table entry*/ q->done = 1;
/* Free the table entry. */
LOCK (fd_table_lock); LOCK (fd_table_lock);
fd_table[i].for_read = 0; fd_table[i].for_read = 0;
fd_table[i].for_write = 0; fd_table[i].for_write = 0;
@ -242,7 +260,6 @@ do_select ( void )
} }
/* /*
* called by rungpg.c to register something for select() * called by rungpg.c to register something for select()
*/ */
@ -260,7 +277,7 @@ _gpgme_register_pipe_handler ( void *opaque,
assert (opaque); assert (opaque);
assert (handler); assert (handler);
/* Allocate a structure to hold info about the handler */ /* Allocate a structure to hold info about the handler. */
q = xtrycalloc (1, sizeof *q); q = xtrycalloc (1, sizeof *q);
if (!q) if (!q)
return mk_error (Out_Of_Core); return mk_error (Out_Of_Core);
@ -268,13 +285,16 @@ _gpgme_register_pipe_handler ( void *opaque,
q->handler = handler; q->handler = handler;
q->handler_value = handler_value; q->handler_value = handler_value;
/* Put this into the process queue */ /* Put this into the process queue. */
LOCK (proc_queue_lock); LOCK (proc_queue_lock);
for (proc = proc_queue; proc && proc->pid != pid; proc = proc->next) for (proc = proc_queue; proc && proc->pid != pid; proc = proc->next)
; ;
if (!proc) { /* a new process */ if (!proc)
{
/* A new process. */
proc = xtrycalloc (1, sizeof *proc); proc = xtrycalloc (1, sizeof *proc);
if (!proc) { if (!proc)
{
UNLOCK (proc_queue_lock); UNLOCK (proc_queue_lock);
return mk_error (Out_Of_Core); return mk_error (Out_Of_Core);
} }
@ -291,8 +311,10 @@ _gpgme_register_pipe_handler ( void *opaque,
LOCK (fd_table_lock); LOCK (fd_table_lock);
again: again:
for (i=0; i < fd_table_size; i++ ) { for (i=0; i < fd_table_size; i++)
if ( fd_table[i].fd == -1 ) { {
if (fd_table[i].fd == -1)
{
fd_table[i].fd = fd; fd_table[i].fd = fd;
fd_table[i].for_read = inbound; fd_table[i].for_read = inbound;
fd_table[i].for_write = !inbound; fd_table[i].for_write = !inbound;
@ -309,7 +331,8 @@ _gpgme_register_pipe_handler ( void *opaque,
struct io_select_fd_s *tmp; struct io_select_fd_s *tmp;
tmp = xtryrealloc (fd_table, (fd_table_size + 10) * sizeof *tmp); tmp = xtryrealloc (fd_table, (fd_table_size + 10) * sizeof *tmp);
if ( tmp ) { if (tmp)
{
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
tmp[fd_table_size+i].fd = -1; tmp[fd_table_size+i].fd = -1;
fd_table_size += i; fd_table_size += i;
@ -320,7 +343,7 @@ _gpgme_register_pipe_handler ( void *opaque,
UNLOCK (fd_table_lock); UNLOCK (fd_table_lock);
xfree (q); xfree (q);
/* FIXME: remove the proc table entry */ /* FIXME: Remove the proc table entry. */
return mk_error (Too_Many_Procs); return mk_error (Too_Many_Procs);
} }
@ -331,12 +354,15 @@ _gpgme_freeze_fd ( int fd )
int i; int i;
LOCK (fd_table_lock); LOCK (fd_table_lock);
for (i=0; i < fd_table_size; i++ ) { for (i = 0; i < fd_table_size; i++)
if ( fd_table[i].fd == fd ) { {
if (fd_table[i].fd == fd)
{
struct wait_item_s *q; struct wait_item_s *q;
fd_table[i].frozen = 1; fd_table[i].frozen = 1;
if ( (q=fd_table[i].opaque) ) q = fd_table[i].opaque;
if (q)
q->frozen = 1; q->frozen = 1;
DEBUG2 ("fd %d frozen (q=%p)", fd, q); DEBUG2 ("fd %d frozen (q=%p)", fd, q);
break; break;
@ -351,12 +377,15 @@ _gpgme_thaw_fd ( int fd )
int i; int i;
LOCK (fd_table_lock); LOCK (fd_table_lock);
for (i=0; i < fd_table_size; i++ ) { for (i = 0; i < fd_table_size; i++)
if ( fd_table[i].fd == fd ) { {
if (fd_table[i].fd == fd)
{
struct wait_item_s *q; struct wait_item_s *q;
fd_table[i].frozen = 0; fd_table[i].frozen = 0;
if ( (q=fd_table[i].opaque) ) q = fd_table[i].opaque;
if (q)
q->frozen = 0; q->frozen = 0;
DEBUG2 ("fd %d thawed (q=%p)", fd, q); DEBUG2 ("fd %d thawed (q=%p)", fd, q);
break; break;