core: Use a better name for the internal synchronous wait.

* src/wait.c (_gpgme_wait_on_condition): Rename to ...
(_gpgme_sync_wait): this.  Small code refactoring.
(_gpgme_wait_one, _gpgme_wait_one_ext): Remove and change all callers
to use _gpgme_sync_wait.

* src/fdtable.c (_gpgme_fdtable_run_io_cbs): Move TRACE up.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-06-14 10:12:56 +02:00
parent 28e620fa16
commit 153f1128f8
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
24 changed files with 69 additions and 94 deletions

View File

@ -126,7 +126,7 @@ gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher,
err = decrypt_verify_start (ctx, 1, GPGME_DECRYPT_VERIFY, cipher, plain);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
ctx->ignore_mdc_error = 0; /* Always reset. */
return TRACE_ERR (err);
}
@ -177,7 +177,7 @@ gpgme_op_decrypt_ext (gpgme_ctx_t ctx,
else
err = _gpgme_decrypt_start (ctx, 1, flags, cipher, plain);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
ctx->ignore_mdc_error = 0; /* Always reset. */
return TRACE_ERR (err);
}

View File

@ -613,7 +613,7 @@ gpgme_op_decrypt (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_data_t plain)
err = _gpgme_decrypt_start (ctx, 1, 0, cipher, plain);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
ctx->ignore_mdc_error = 0; /* Always reset. */
return TRACE_ERR (err);
}

View File

@ -162,7 +162,7 @@ gpgme_op_delete (gpgme_ctx_t ctx, const gpgme_key_t key, int allow_secret)
err = delete_start (ctx, 1, key,
allow_secret ? GPGME_DELETE_ALLOW_SECRET : 0);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return err;
}
@ -204,6 +204,6 @@ gpgme_op_delete_ext (gpgme_ctx_t ctx, const gpgme_key_t key,
err = delete_start (ctx, 1, key, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return err;
}

View File

@ -186,7 +186,7 @@ gpgme_op_interact (gpgme_ctx_t ctx, gpgme_key_t key, unsigned int flags,
err = interact_start (ctx, 1, key, flags, fnc, fnc_value, out);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return err;
}
@ -266,7 +266,7 @@ gpgme_op_edit (gpgme_ctx_t ctx, gpgme_key_t key,
err = edit_start (ctx, 1, 0, key, fnc, fnc_value, out);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}
@ -309,6 +309,6 @@ gpgme_op_card_edit (gpgme_ctx_t ctx, gpgme_key_t key,
err = edit_start (ctx, 1, 1, key, fnc, fnc_value, out);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -171,7 +171,7 @@ gpgme_op_encrypt_sign_ext (gpgme_ctx_t ctx, gpgme_key_t recp[],
err = encrypt_sign_start (ctx, 1, recp, recpstring, flags, plain, cipher);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -319,7 +319,7 @@ gpgme_op_encrypt_ext (gpgme_ctx_t ctx, gpgme_key_t recp[],
err = encrypt_start (ctx, 1, recp, recpstring, flags, plain, cipher);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -202,7 +202,7 @@ gpgme_op_export (gpgme_ctx_t ctx, const char *pattern,
err = export_start (ctx, 1, pattern, mode, keydata);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return err;
}
@ -319,7 +319,7 @@ gpgme_op_export_ext (gpgme_ctx_t ctx, const char *pattern[],
err = export_ext_start (ctx, 1, pattern, mode, keydata);
if (!err)
{
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
if (!err)
{
/* For this synchronous operation we check for operational
@ -459,7 +459,7 @@ gpgme_op_export_keys (gpgme_ctx_t ctx,
err = export_keys_start (ctx, 1, keys, mode, keydata);
if (!err)
{
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
if (!err)
{
/* For this synchronous operation we check for operational
@ -478,4 +478,3 @@ gpgme_op_export_keys (gpgme_ctx_t ctx,
return TRACE_ERR (err);
}

View File

@ -481,11 +481,11 @@ _gpgme_fdtable_run_io_cbs (uint64_t owner, gpg_error_t *r_op_err)
unsigned int cb_count;
gpgme_ctx_t actx;
TRACE_BEG (DEBUG_SYSIO, __func__, NULL, "ctx=%lu", owner);
if (r_op_err)
*r_op_err = 0;
TRACE_BEG (DEBUG_SYSIO, __func__, NULL, "ctx=%lu", owner);
for (;;)
{
fd = -1;

View File

@ -316,7 +316,7 @@ gpgme_op_genkey (gpgme_ctx_t ctx, const char *parms, gpgme_data_t pubkey,
err = genkey_start (ctx, 1, parms, pubkey, seckey);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}
@ -400,7 +400,7 @@ gpgme_op_createkey (gpgme_ctx_t ctx, const char *userid, const char *algo,
err = createkey_start (ctx, 1,
userid, algo, reserved, expires, anchorkey, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}
@ -487,7 +487,7 @@ gpgme_op_createsubkey (gpgme_ctx_t ctx, gpgme_key_t key, const char *algo,
err = createsubkey_start (ctx, 1, key, algo, reserved, expires, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}
@ -571,7 +571,7 @@ gpgme_op_adduid (gpgme_ctx_t ctx,
err = addrevuid_start (ctx, 1, 0, key, userid, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}
@ -608,7 +608,7 @@ gpgme_op_revuid (gpgme_ctx_t ctx,
err = addrevuid_start (ctx, 1, GENKEY_EXTRAFLAG_REVOKE, key, userid, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}
@ -640,7 +640,7 @@ set_uid_flag (gpgme_ctx_t ctx, int synchronous,
return err = gpg_error (GPG_ERR_UNKNOWN_NAME);
if (synchronous && !err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -99,7 +99,6 @@ gpgme_op_getauditlog (gpgme_ctx_t ctx, gpgme_data_t output, unsigned int flags)
err = getauditlog_start (ctx, 1, output, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -316,7 +316,7 @@ gpgme_op_import (gpgme_ctx_t ctx, gpgme_data_t keydata)
err = _gpgme_op_import_start (ctx, 1, keydata);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}
@ -433,7 +433,7 @@ gpgme_op_import_keys (gpgme_ctx_t ctx, gpgme_key_t *keys)
err = _gpgme_op_import_keys_start (ctx, 1, keys);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -1216,7 +1216,7 @@ gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key)
if (!opd->key_queue)
{
err = _gpgme_wait_on_condition (ctx, &opd->key_cond, NULL);
err = _gpgme_sync_wait (ctx, &opd->key_cond, NULL);
if (err)
return TRACE_ERR (err);

View File

@ -214,6 +214,6 @@ gpgme_op_keysign (gpgme_ctx_t ctx, gpgme_key_t key, const char *userid,
err = keysign_start (ctx, 1, key, userid, expires, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -136,7 +136,7 @@ gpgme_op_assuan_transact_ext (gpgme_ctx_t ctx,
if (err)
goto out;
err = _gpgme_wait_one_ext (ctx, &op_err);
err = _gpgme_sync_wait (ctx, NULL, &op_err);
if (op_err)
{
TRACE_LOG ("op_err = %s <%s>", gpgme_strerror (op_err),

View File

@ -33,10 +33,9 @@ void _gpgme_release_result (gpgme_ctx_t ctx);
/* From wait.c. */
gpgme_error_t _gpgme_wait_one (gpgme_ctx_t ctx);
gpgme_error_t _gpgme_wait_one_ext (gpgme_ctx_t ctx, gpgme_error_t *op_err);
gpgme_error_t _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond,
gpgme_error_t *op_err);
gpgme_error_t _gpgme_sync_wait (gpgme_ctx_t ctx,
volatile int *cond,
gpg_error_t *op_err);
/* From data.c. */

View File

@ -199,7 +199,6 @@ gpgme_op_passwd (gpgme_ctx_t ctx, gpgme_key_t key, unsigned int flags)
err = passwd_start (ctx, 1, key, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -495,6 +495,6 @@ gpgme_op_sign (gpgme_ctx_t ctx, gpgme_data_t plain, gpgme_data_t sig,
err = sign_start (ctx, 1, plain, sig, mode);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -101,6 +101,6 @@ gpgme_op_spawn (gpgme_ctx_t ctx, const char *file, const char *argv[],
err = spawn_start (ctx, 1, file, argv, datain, dataout, dataerr, flags);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -180,6 +180,6 @@ gpgme_op_tofu_policy (gpgme_ctx_t ctx,
err = tofu_policy_start (ctx, 1, key, policy);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -230,7 +230,7 @@ gpgme_op_trustlist_next (gpgme_ctx_t ctx, gpgme_trust_item_t *r_item)
if (!opd->trust_queue)
{
err = _gpgme_wait_on_condition (ctx, &opd->trust_cond, NULL);
err = _gpgme_sync_wait (ctx, &opd->trust_cond, NULL);
if (err)
return TRACE_ERR (err);
if (!opd->trust_cond)

View File

@ -1194,7 +1194,7 @@ gpgme_op_verify (gpgme_ctx_t ctx, gpgme_data_t sig, gpgme_data_t signed_text,
err = verify_start (ctx, 1, sig, signed_text, plaintext);
if (!err)
err = _gpgme_wait_one (ctx);
err = _gpgme_sync_wait (ctx, NULL, NULL);
return TRACE_ERR (err);
}

View File

@ -97,7 +97,7 @@ gpgme_op_vfs_transact (gpgme_ctx_t ctx,
err = vfs_start (ctx, 1, command, data_cb, data_cb_value,
inq_cb, inq_cb_value, status_cb, status_cb_value);
if (!err)
err = _gpgme_wait_one_ext (ctx, op_err);
err = _gpgme_sync_wait (ctx, NULL, op_err);
return err;
}
@ -202,4 +202,3 @@ gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[],
err = _gpgme_op_vfs_create (ctx, recp, container_file, flags, op_err);
return TRACE_ERR (err);
}

View File

@ -154,7 +154,7 @@ gpgme_op_vfs_transact (gpgme_ctx_t ctx,
err = vfs_start (ctx, 1, command, data_cb, data_cb_value,
inq_cb, inq_cb_value, status_cb, status_cb_value);
if (!err)
err = _gpgme_wait_one_ext (ctx, op_err);
err = _gpgme_sync_wait (ctx, NULL, op_err);
return err;
}
@ -244,4 +244,3 @@ gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
err = _gpgme_op_vfs_mount (ctx, container_file, mount_dir, flags, op_err);
return TRACE_ERR (err);
}

View File

@ -385,25 +385,29 @@ gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang)
/* If COND is a null pointer, wait until the blocking operation in CTX
finished and return its error value. Otherwise, wait until COND is
satisfied or the operation finished. */
/* Wait until the blocking operation in context CTX has finished and
* return the error value. If COND is not NULL return early if COND
* is satisfied. A session based error will be returned at R_OP_ERR
* if it is not NULL. */
gpgme_error_t
_gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond,
gpgme_error_t *r_op_err)
_gpgme_sync_wait (gpgme_ctx_t ctx, volatile int *cond, gpg_error_t *r_op_err)
{
gpgme_error_t err = 0;
int hang = 1;
io_select_t fds = NULL;
unsigned int nfds;
int op_err;
int nr;
TRACE_BEG (DEBUG_SYSIO, __func__, NULL, "ctx=%lu", CTXSERIAL (ctx));
if (r_op_err)
*r_op_err = 0;
if (!ctx)
return gpg_error (GPG_ERR_INV_VALUE);
{
err = gpg_error (GPG_ERR_INV_VALUE);
goto leave;
}
do
{
@ -415,35 +419,29 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond,
{
err = gpg_error_from_syserror ();
if (gpg_err_code (err) != GPG_ERR_MISSING_ERRNO)
{
free (fds);
return err;
}
/* Nothing to select. Run the select anyway, so that we use
* its timeout. */
goto leave;
}
nr = _gpgme_io_select (fds, nfds, 0);
if (nr < 0)
{
/* An error occurred. Close all fds in this context, and
signal it. */
err = gpg_error_from_syserror ();
_gpgme_cancel_with_err (ctx->serial, err, 0);
free (fds);
return err;
}
_gpgme_fdtable_set_signaled (fds, nfds);
err = _gpgme_fdtable_run_io_cbs (ctx->serial, r_op_err);
if (err || (r_op_err && *r_op_err))
else
{
free (fds);
return err;
nr = _gpgme_io_select (fds, nfds, 0);
if (nr < 0)
{
/* An error occurred. Close all fds in this context, and
signal it. */
err = gpg_error_from_syserror ();
_gpgme_cancel_with_err (ctx->serial, err, 0);
goto leave;
}
_gpgme_fdtable_set_signaled (fds, nfds);
err = _gpgme_fdtable_run_io_cbs (ctx->serial, r_op_err);
if (err || (r_op_err && *r_op_err))
goto leave;
}
if (!_gpgme_fdtable_io_cb_count (ctx->serial))
{
/* No more matching fds with IO callbacks. */
struct gpgme_io_event_done_data data = {0, 0};
_gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &data);
hang = 0;
@ -452,26 +450,9 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond,
hang = 0;
}
while (hang);
err = 0;
leave:
free (fds);
return 0;
}
/* Wait until the blocking operation in context CTX has finished and
return the error value. This variant can not be used for
session-based protocols. */
gpgme_error_t
_gpgme_wait_one (gpgme_ctx_t ctx)
{
return _gpgme_wait_on_condition (ctx, NULL, NULL);
}
/* Wait until the blocking operation in context CTX has finished and
return the error value. This is the right variant to use for
sesion-based protocols. */
gpgme_error_t
_gpgme_wait_one_ext (gpgme_ctx_t ctx, gpgme_error_t *op_err)
{
return _gpgme_wait_on_condition (ctx, NULL, op_err);
return TRACE_ERR (err);
}