diff options
author | Marcus Brinkmann <[email protected]> | 2012-01-03 21:12:37 +0000 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2012-01-25 13:07:08 +0000 |
commit | e917c07b2664bb01a5f7b5975723b90da0f396c9 (patch) | |
tree | e31e737fe07e96b596f8bbbaf16a1e122ac683ae /scd/app.c | |
parent | Require gitlog-to-changelog to be installed. (diff) | |
download | gnupg-npth-3.tar.gz gnupg-npth-3.zip |
Port to npth.npth-3
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
Diffstat (limited to 'scd/app.c')
-rw-r--r-- | scd/app.c | 49 |
1 files changed, 17 insertions, 32 deletions
@@ -22,7 +22,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <pth.h> +#include <npth.h> #include "scdaemon.h" #include "app-common.h" @@ -37,7 +37,7 @@ static struct { int initialized; - pth_mutex_t lock; + npth_mutex_t lock; app_t app; /* Application context in use or NULL. */ app_t last_app; /* Last application object used as this slot or NULL. */ } lock_table[10]; @@ -72,30 +72,30 @@ print_progress_line (void *opaque, const char *what, int pc, int cur, int tot) static gpg_error_t lock_reader (int slot, ctrl_t ctrl) { - gpg_error_t err; + int res; if (slot < 0 || slot >= DIM (lock_table)) return gpg_error (slot<0? GPG_ERR_INV_VALUE : GPG_ERR_RESOURCE_LIMIT); if (!lock_table[slot].initialized) { - if (!pth_mutex_init (&lock_table[slot].lock)) + res = npth_mutex_init (&lock_table[slot].lock, NULL); + if (res) { - err = gpg_error_from_syserror (); - log_error ("error initializing mutex: %s\n", strerror (errno)); - return err; + log_error ("error initializing mutex: %s\n", strerror (res)); + return gpg_error_from_errno (res); } lock_table[slot].initialized = 1; lock_table[slot].app = NULL; lock_table[slot].last_app = NULL; } - if (!pth_mutex_acquire (&lock_table[slot].lock, 0, NULL)) + res = npth_mutex_lock (&lock_table[slot].lock); + if (res) { - err = gpg_error_from_syserror (); log_error ("failed to acquire APP lock for slot %d: %s\n", - slot, strerror (errno)); - return err; + slot, strerror (res)); + return gpg_error_from_errno (res); } apdu_set_progress_cb (slot, print_progress_line, ctrl); @@ -107,32 +107,18 @@ lock_reader (int slot, ctrl_t ctrl) static void unlock_reader (int slot) { + int res; + if (slot < 0 || slot >= DIM (lock_table) || !lock_table[slot].initialized) log_bug ("unlock_reader called for invalid slot %d\n", slot); apdu_set_progress_cb (slot, NULL, NULL); - if (!pth_mutex_release (&lock_table[slot].lock)) + res = npth_mutex_unlock (&lock_table[slot].lock); + if (res) log_error ("failed to release APP lock for slot %d: %s\n", - slot, strerror (errno)); -} - - -static void -dump_mutex_state (pth_mutex_t *m) -{ -#ifdef _W32_PTH_H - (void)m; - log_printf ("unknown under W32"); -#else - if (!(m->mx_state & PTH_MUTEX_INITIALIZED)) - log_printf ("not_initialized"); - else if (!(m->mx_state & PTH_MUTEX_LOCKED)) - log_printf ("not_locked"); - else - log_printf ("locked tid=0x%lx count=%lu", (long)m->mx_owner, m->mx_count); -#endif + slot, strerror (res)); } @@ -146,8 +132,7 @@ app_dump_state (void) for (slot=0; slot < DIM (lock_table); slot++) if (lock_table[slot].initialized) { - log_info ("app_dump_state: slot=%d lock=", slot); - dump_mutex_state (&lock_table[slot].lock); + log_info ("app_dump_state: slot=%d", slot); if (lock_table[slot].app) { log_printf (" app=%p", lock_table[slot].app); |