[git] GnuPG - branch, scd-backport-2-0, updated. gnupg-2.0.19-28-gff40c05
by NIIBE Yutaka
cvs at cvs.gnupg.org
Mon Jun 18 10:14:23 CEST 2012
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".
The branch, scd-backport-2-0 has been updated
via ff40c05e8b563471278cb7c92df0310bc5967749 (commit)
via 7f3ea446609355c96e90f0b6beb057daa1152643 (commit)
from 29b431fcf97a9e615d34a7a40e570e63834b360a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ff40c05e8b563471278cb7c92df0310bc5967749
Author: NIIBE Yutaka <gniibe at fsij.org>
Date: Mon Jun 18 15:08:01 2012 +0900
scd: acquire lock in new_reader_slot.
* scd/apdu.c (new_reader_slot): Acquire lock.
(open_ct_reader, open_pcsc_reader_direct, open_pcsc_reader_wrapped)
(open_ccid_reader, open_rapdu_reader): Release lock.
--
Fixes a test case of:
No libpcsclite1 installed.
Run gpg-agent
Run command "gpg-connect-agent learn /bye" with no card/token
Sometimes it fails: ERR 100663356 Not supported <SCD>
While it should be always: ERR 100663404 Card error <SCD>
diff --git a/scd/apdu.c b/scd/apdu.c
index 07df9fe..a343307 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -367,7 +367,8 @@ unlock_slot (int slot)
/* Find an unused reader slot for PORTSTR and put it into the reader
- table. Return -1 on error or the index into the reader table. */
+ table. Return -1 on error or the index into the reader table.
+ Acquire slot's lock on successful return. Caller needs to unlock it. */
static int
new_reader_slot (void)
{
@@ -394,6 +395,11 @@ new_reader_slot (void)
reader_table[reader].lock_initialized = 1;
}
#endif /*USE_GNU_PTH*/
+ if (lock_slot (reader))
+ {
+ log_error ("error locking mutex: %s\n", strerror (errno));
+ return -1;
+ }
reader_table[reader].connect_card = NULL;
reader_table[reader].disconnect_card = NULL;
reader_table[reader].close_reader = NULL;
@@ -675,6 +681,7 @@ open_ct_reader (int port)
log_error ("apdu_open_ct_reader failed on port %d: %s\n",
port, ct_error_string (rc));
reader_table[reader].used = 0;
+ unlock_slot (reader);
return -1;
}
@@ -696,6 +703,7 @@ open_ct_reader (int port)
reader_table[reader].keypad_modify = NULL;
dump_reader_status (reader);
+ unlock_slot (reader);
return reader;
}
@@ -1701,6 +1709,7 @@ open_pcsc_reader_direct (const char *portstr)
log_error ("pcsc_establish_context failed: %s (0x%lx)\n",
pcsc_error_string (err), err);
reader_table[slot].used = 0;
+ unlock_slot (slot);
if (err == 0x8010001d)
pcsc_no_service = 1;
return -1;
@@ -1717,6 +1726,7 @@ open_pcsc_reader_direct (const char *portstr)
log_error ("error allocating memory for reader list\n");
pcsc_release_context (reader_table[slot].pcsc.context);
reader_table[slot].used = 0;
+ unlock_slot (slot);
return -1 /*SW_HOST_OUT_OF_CORE*/;
}
err = pcsc_list_readers (reader_table[slot].pcsc.context,
@@ -1729,6 +1739,7 @@ open_pcsc_reader_direct (const char *portstr)
pcsc_release_context (reader_table[slot].pcsc.context);
reader_table[slot].used = 0;
xfree (list);
+ unlock_slot (slot);
return -1;
}
@@ -1755,6 +1766,7 @@ open_pcsc_reader_direct (const char *portstr)
log_error ("error allocating memory for reader name\n");
pcsc_release_context (reader_table[slot].pcsc.context);
reader_table[slot].used = 0;
+ unlock_slot (slot);
return -1;
}
strcpy (reader_table[slot].rdrname, portstr? portstr : list);
@@ -1774,6 +1786,7 @@ open_pcsc_reader_direct (const char *portstr)
reader_table[slot].dump_status_reader = dump_pcsc_reader_status;
dump_reader_status (slot);
+ unlock_slot (slot);
return slot;
}
#endif /*!NEED_PCSC_WRAPPER */
@@ -1821,6 +1834,7 @@ open_pcsc_reader_wrapped (const char *portstr)
{
log_error ("error creating a pipe: %s\n", strerror (errno));
slotp->used = 0;
+ unlock_slot (slot);
return -1;
}
if (pipe (wp) == -1)
@@ -1829,6 +1843,7 @@ open_pcsc_reader_wrapped (const char *portstr)
close (rp[0]);
close (rp[1]);
slotp->used = 0;
+ unlock_slot (slot);
return -1;
}
@@ -1841,6 +1856,7 @@ open_pcsc_reader_wrapped (const char *portstr)
close (wp[0]);
close (wp[1]);
slotp->used = 0;
+ unlock_slot (slot);
return -1;
}
slotp->pcsc.pid = pid;
@@ -1976,6 +1992,7 @@ open_pcsc_reader_wrapped (const char *portstr)
pcsc_get_status (slot, &dummy_status);
dump_reader_status (slot);
+ unlock_slot (slot);
return slot;
command_failed:
@@ -1986,6 +2003,7 @@ open_pcsc_reader_wrapped (const char *portstr)
kill (slotp->pcsc.pid, SIGTERM);
slotp->pcsc.pid = (pid_t)(-1);
slotp->used = 0;
+ unlock_slot (slot);
/* There is no way to return SW. */
return -1;
@@ -2422,6 +2440,7 @@ open_ccid_reader (const char *portstr)
if (err)
{
slotp->used = 0;
+ unlock_slot (slot);
return -1;
}
@@ -2456,6 +2475,7 @@ open_ccid_reader (const char *portstr)
reader_table[slot].is_t0 = 0;
dump_reader_status (slot);
+ unlock_slot (slot);
return slot;
}
@@ -2694,6 +2714,7 @@ open_rapdu_reader (int portno,
if (!slotp->rapdu.handle)
{
slotp->used = 0;
+ unlock_slot (slot);
return -1;
}
@@ -2748,12 +2769,14 @@ open_rapdu_reader (int portno,
dump_reader_status (slot);
rapdu_msg_release (msg);
+ unlock_slot (slot);
return slot;
failure:
rapdu_msg_release (msg);
rapdu_release (slotp->rapdu.handle);
slotp->used = 0;
+ unlock_slot (slot);
return -1;
}
commit 7f3ea446609355c96e90f0b6beb057daa1152643
Author: NIIBE Yutaka <gniibe at fsij.org>
Date: Mon Jun 18 14:52:53 2012 +0900
scd: move lock_slot, trylock_slot, unlock_slot functions.
* scd/apdu.c (lock_slot, trylock_slot, unlock_slot): Move.
--
This is for upcoming changes.
diff --git a/scd/apdu.c b/scd/apdu.c
index 0e52909..07df9fe 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -328,6 +328,44 @@ static int pcsc_keypad_modify (int slot, int class, int ins, int p0, int p1,
*/
+static int
+lock_slot (int slot)
+{
+#ifdef USE_GNU_PTH
+ if (!pth_mutex_acquire (&reader_table[slot].lock, 0, NULL))
+ {
+ log_error ("failed to acquire apdu lock: %s\n", strerror (errno));
+ return SW_HOST_LOCKING_FAILED;
+ }
+#endif /*USE_GNU_PTH*/
+ return 0;
+}
+
+static int
+trylock_slot (int slot)
+{
+#ifdef USE_GNU_PTH
+ if (!pth_mutex_acquire (&reader_table[slot].lock, TRUE, NULL))
+ {
+ if (errno == EBUSY)
+ return SW_HOST_BUSY;
+ log_error ("failed to acquire apdu lock: %s\n", strerror (errno));
+ return SW_HOST_LOCKING_FAILED;
+ }
+#endif /*USE_GNU_PTH*/
+ return 0;
+}
+
+static void
+unlock_slot (int slot)
+{
+#ifdef USE_GNU_PTH
+ if (!pth_mutex_release (&reader_table[slot].lock))
+ log_error ("failed to release apdu lock: %s\n", strerror (errno));
+#endif /*USE_GNU_PTH*/
+}
+
+
/* Find an unused reader slot for PORTSTR and put it into the reader
table. Return -1 on error or the index into the reader table. */
static int
@@ -2728,44 +2766,6 @@ open_rapdu_reader (int portno,
*/
-static int
-lock_slot (int slot)
-{
-#ifdef USE_GNU_PTH
- if (!pth_mutex_acquire (&reader_table[slot].lock, 0, NULL))
- {
- log_error ("failed to acquire apdu lock: %s\n", strerror (errno));
- return SW_HOST_LOCKING_FAILED;
- }
-#endif /*USE_GNU_PTH*/
- return 0;
-}
-
-static int
-trylock_slot (int slot)
-{
-#ifdef USE_GNU_PTH
- if (!pth_mutex_acquire (&reader_table[slot].lock, TRUE, NULL))
- {
- if (errno == EBUSY)
- return SW_HOST_BUSY;
- log_error ("failed to acquire apdu lock: %s\n", strerror (errno));
- return SW_HOST_LOCKING_FAILED;
- }
-#endif /*USE_GNU_PTH*/
- return 0;
-}
-
-static void
-unlock_slot (int slot)
-{
-#ifdef USE_GNU_PTH
- if (!pth_mutex_release (&reader_table[slot].lock))
- log_error ("failed to release apdu lock: %s\n", strerror (errno));
-#endif /*USE_GNU_PTH*/
-}
-
-
/* Open the reader and return an internal slot number or -1 on
error. If PORTSTR is NULL we default to a suitable port (for ctAPI:
the first USB reader. For PC/SC the first listed reader). */
-----------------------------------------------------------------------
Summary of changes:
scd/apdu.c | 101 ++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 62 insertions(+), 39 deletions(-)
hooks/post-receive
--
The GNU Privacy Guard
http://git.gnupg.org
More information about the Gnupg-commits
mailing list