rpms/coolkey/devel coolkey-thread-fix.patch, NONE, 1.1 coolkey.spec, 1.32, 1.33

Robert Relyea rrelyea at fedoraproject.org
Fri Dec 18 23:37:45 UTC 2009


Author: rrelyea

Update of /cvs/extras/rpms/coolkey/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv27263

Modified Files:
	coolkey.spec 
Added Files:
	coolkey-thread-fix.patch 
Log Message:


Fix coolkey thread issues:
1) Coolkey returned errors when ever thread safety was requested, 
   even though coolkey was thread safe.
2) Coolkey would hang if used with non-threaded applications which did not link
   with -lpthreads


coolkey-thread-fix.patch:
 coolkey.cpp |   36 +++++++++++++++++++++++++-----------
 machdep.cpp |    9 +++++++++
 machdep.h   |    2 ++
 3 files changed, 36 insertions(+), 11 deletions(-)

--- NEW FILE coolkey-thread-fix.patch ---
Index: src/coolkey/coolkey.cpp
===================================================================
RCS file: /cvs/dirsec/coolkey/src/coolkey/coolkey.cpp,v
retrieving revision 1.2
diff -u -r1.2 coolkey.cpp
--- src/coolkey/coolkey.cpp	14 Feb 2007 19:54:01 -0000	1.2
+++ src/coolkey/coolkey.cpp	18 Dec 2009 23:22:58 -0000
@@ -42,7 +42,9 @@
 
 static SlotList *slotList = NULL;
 
-static OSLock finalizeLock(false);
+static OSLock *finalizeLock = NULL;
+#define FINALIZE_GETLOCK() if (finalizeLock) finalizeLock->getLock();
+#define FINALIZE_RELEASELOCK() if (finalizeLock) finalizeLock->releaseLock();
 
 static CK_BBOOL initialized = FALSE;
 static CK_BBOOL finalizing = FALSE;
@@ -208,11 +210,13 @@
     if( initialized ) {
         return CKR_CRYPTOKI_ALREADY_INITIALIZED;
     }
-    if (!finalizeLock.isValid()) {
+    if (finalizeLock && !finalizeLock->isValid()) {
 	return CKR_CANT_LOCK;
     }
     CK_C_INITIALIZE_ARGS* initArgs = (CK_C_INITIALIZE_ARGS*) pInitArgs;
+    OSLock::setThreadSafe(0);
     if( initArgs != NULL ) {
+	bool needThreads;
 	/* work around a bug in NSS where the library parameters are only
 	 * send if locking is requested */
 	if (initArgs->LibraryParameters) {
@@ -220,7 +224,17 @@
 	} else {
 	    Params::ClearParams();
 	}
-        if( (initArgs->flags & CKF_OS_LOCKING_OK) || initArgs->LockMutex ){
+  	needThreads = ((initArgs->flags & CKF_OS_LOCKING_OK) != 0);
+	OSLock::setThreadSafe(needThreads);
+	/* don't get a finalize lock unless someone initializes us asking
+	 * us to use threads */
+	if (needThreads && !finalizeLock) {
+	    finalizeLock = new OSLock(true);
+	    if (finalizeLock == NULL) return CKR_HOST_MEMORY;
+	}
+	/* only support OS LOCKING threads */
+        if( ((initArgs->flags & CKF_OS_LOCKING_OK) == 0) 
+						&& initArgs->LockMutex ){
             throw PKCS11Exception(CKR_CANT_LOCK);
         }
     }
@@ -259,9 +273,9 @@
     // the finalizing call first, we know it will set waitEvent before
     // we can get the lock, so we only need to protect setting finalizing
     // to true.
-    finalizeLock.getLock();
+    FINALIZE_GETLOCK();
     finalizing = TRUE;
-    finalizeLock.releaseLock();
+    FINALIZE_RELEASELOCK();
     if (waitEvent) {
 	/* we're waiting on a slot event, shutdown first to allow
 	 * the wait function to complete before we pull the rug out.
@@ -273,10 +287,10 @@
     } 
     delete slotList;
     delete log;
-    finalizeLock.getLock();
+    FINALIZE_GETLOCK();
     finalizing = FALSE;
     initialized = FALSE;
-    finalizeLock.releaseLock();
+    FINALIZE_RELEASELOCK();
     return CKR_OK;
 }
 
@@ -595,17 +609,17 @@
 CK_RV
 C_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, CK_VOID_PTR pReserved)
 {
-    finalizeLock.getLock();
+    FINALIZE_GETLOCK();
     if( ! initialized ) {
-        finalizeLock.releaseLock();
+	FINALIZE_RELEASELOCK();
         return CKR_CRYPTOKI_NOT_INITIALIZED;
     }
     if (finalizing) {
-        finalizeLock.releaseLock();
+	FINALIZE_RELEASELOCK();
         return CKR_CRYPTOKI_NOT_INITIALIZED;
     }
     waitEvent = TRUE;
-    finalizeLock.releaseLock();
+    FINALIZE_RELEASELOCK();
     try {
         log->log("C_WaitForSlotEvent called\n");
         slotList->waitForSlotEvent(flags, pSlot, pReserved);
Index: src/coolkey/machdep.cpp
===================================================================
RCS file: /cvs/dirsec/coolkey/src/coolkey/machdep.cpp,v
retrieving revision 1.7
diff -u -r1.7 machdep.cpp
--- src/coolkey/machdep.cpp	14 Feb 2008 23:48:19 -0000	1.7
+++ src/coolkey/machdep.cpp	18 Dec 2009 23:22:58 -0000
@@ -37,6 +37,8 @@
 #include <stdlib.h>
 #endif
 
+bool OSLock::needThread = 0;
+
 #ifdef _WIN32
 //
 // Windows functions to grab a named shared memory segment of a specific size,
@@ -123,6 +125,10 @@
 
 OSLock::OSLock(bool exceptionAllowed)
 {
+    if (!needThread) {
+	lockData = NULL;
+	return;
+    }
     lockData = new OSLockData;
     if (lockData) {
 	InitializeCriticalSection(&lockData->mutex);
@@ -360,6 +366,9 @@
     int rc;
 
     lockData = NULL;
+    if (!needThread) {
+	return;
+    }
 #ifdef MAC
     if (!OSLock_attr_init) {
 	rc = pthread_mutexattr_init(&OSLock_attr);
Index: src/coolkey/machdep.h
===================================================================
RCS file: /cvs/dirsec/coolkey/src/coolkey/machdep.h,v
retrieving revision 1.1
diff -u -r1.1 machdep.h
--- src/coolkey/machdep.h	9 Jun 2006 18:39:11 -0000	1.1
+++ src/coolkey/machdep.h	18 Dec 2009 23:22:58 -0000
@@ -40,12 +40,14 @@
 class OSLock {
 private:
    OSLockData *lockData;
+   static bool needThread;
 public:
    OSLock(bool exceptionAllowed = true);
    ~OSLock();
    bool isValid();
    void getLock();
    void releaseLock();
+   static void setThreadSafe(bool thread) { needThread = thread; }
 };
 
 typedef unsigned long OSTime;


Index: coolkey.spec
===================================================================
RCS file: /cvs/extras/rpms/coolkey/devel/coolkey.spec,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -p -r1.32 -r1.33
--- coolkey.spec	17 Sep 2009 00:09:52 -0000	1.32
+++ coolkey.spec	18 Dec 2009 23:37:45 -0000	1.33
@@ -22,7 +22,7 @@
 
 Name: coolkey
 Version: 1.1.0
-Release: 11%{dist}
+Release: 12%{?dist}
 Summary: CoolKey PKCS #11 module
 License: LGPLv2
 URL: http://directory.fedora.redhat.com/wiki/CoolKey
@@ -31,6 +31,7 @@ Patch1: coolkey-cache-dir-move.patch
 Patch2: coolkey-gcc43.patch
 Patch3: coolkey-latest.patch
 Patch4: coolkey-simple-bugs.patch
+Patch5: coolkey-thread-fix.patch
 Group: System Environment/Libraries
 BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires: autoconf
@@ -64,6 +65,7 @@ Linux Driver support to access the CoolK
 %patch2 -b .coolkey-gcc43
 %patch3 -b .coolkey-latest
 %patch4 -b .coolkey-simple-bugs
+%patch5 -b .coolkey-thread-fix
 
 %build
 autoconf
@@ -112,10 +114,16 @@ fi
 
 
 %changelog
+* Wed Dec 18 2009 Robert Relyea <rrelyea at redhat.com> - 1.1.0-11
+- Fix threading issue. Coolkey will now work with non-threaded applications 
+- that don't link with libpthread.
+
 * Wed Sep 16 2009 Jack magne <jmagne at redhat.com> - 1.1.0-11
 - Misc bug fixes. Resolves: 485032, #250738, #497758.
+
 * Fri Sep 11 2009 Jack Magne <jmagne at redhat.com> - 1.1.0-10
 - Include latest changes for Gemalto 64K and Safenet 330J.
+
 * Fri Jul 24 2009 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.1.0-9
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild
 




More information about the fedora-extras-commits mailing list