From e472b5dd07e78f0180f4fbf5f22fc2fff2ab2548 Mon Sep 17 00:00:00 2001 From: Alexandra Ellwood Date: Thu, 4 Sep 2008 18:43:14 +0000 Subject: [PATCH] CCAPI should only use one pthread key Use k5 thread functions. Also add destructors so if we ever have a way to detect application exit that the pthread key is destroyed. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20705 dc483132-0cff-0310-8789-dd5450dbe970 --- src/ccapi/lib/ccapi_context.c | 14 +++++++++ src/ccapi/lib/ccapi_context_change_time.c | 7 +++++ src/ccapi/lib/ccapi_context_change_time.h | 1 + src/ccapi/lib/ccapi_ipc.c | 7 +++++ src/ccapi/lib/ccapi_ipc.h | 1 + src/ccapi/lib/ccapi_os_ipc.h | 1 + src/ccapi/lib/mac/ccapi_os_ipc.c | 35 +++++++++++++---------- src/ccapi/lib/win/ccapi_os_ipc.cxx | 7 +++++ src/include/k5-thread.h | 5 ++++ 9 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/ccapi/lib/ccapi_context.c b/src/ccapi/lib/ccapi_context.c index 3b8d60e3e..640e153e8 100644 --- a/src/ccapi/lib/ccapi_context.c +++ b/src/ccapi/lib/ccapi_context.c @@ -80,6 +80,7 @@ static cc_int32 cci_context_sync (cci_context_t in_context, #endif MAKE_INIT_FUNCTION(cci_thread_init); +MAKE_FINI_FUNCTION(cci_thread_fini); /* ------------------------------------------------------------------------ */ @@ -98,6 +99,19 @@ static int cci_thread_init (void) return err; } +/* ------------------------------------------------------------------------ */ + +static void cci_thread_fini (void) +{ + if (!INITIALIZER_RAN (cci_thread_init) || PROGRAM_EXITING ()) { + return; + } + + cci_context_change_time_thread_fini (); + cci_ipc_thread_fini (); +} + + #ifdef TARGET_OS_MAC #pragma mark - #endif diff --git a/src/ccapi/lib/ccapi_context_change_time.c b/src/ccapi/lib/ccapi_context_change_time.c index f701c22fe..4efc7db60 100644 --- a/src/ccapi/lib/ccapi_context_change_time.c +++ b/src/ccapi/lib/ccapi_context_change_time.c @@ -41,6 +41,13 @@ cc_int32 cci_context_change_time_thread_init (void) return k5_mutex_finish_init(&g_change_time_mutex); } +/* ------------------------------------------------------------------------ */ + +void cci_context_change_time_thread_fini (void) +{ + k5_mutex_destroy(&g_change_time_mutex); +} + /* ------------------------------------------------------------------------ */ /* WARNING! Mutex must be locked when calling this! */ diff --git a/src/ccapi/lib/ccapi_context_change_time.h b/src/ccapi/lib/ccapi_context_change_time.h index 536c492d8..ecf3583a9 100644 --- a/src/ccapi/lib/ccapi_context_change_time.h +++ b/src/ccapi/lib/ccapi_context_change_time.h @@ -30,6 +30,7 @@ #include "cci_common.h" cc_int32 cci_context_change_time_thread_init (void); +void cci_context_change_time_thread_fini (void); cc_int32 cci_context_change_time_get (cc_time_t *out_change_time); diff --git a/src/ccapi/lib/ccapi_ipc.c b/src/ccapi/lib/ccapi_ipc.c index 4d2e4314d..fe541db4e 100644 --- a/src/ccapi/lib/ccapi_ipc.c +++ b/src/ccapi/lib/ccapi_ipc.c @@ -36,6 +36,13 @@ cc_int32 cci_ipc_thread_init (void) /* ------------------------------------------------------------------------ */ +void cci_ipc_thread_fini (void) +{ + cci_os_ipc_thread_fini (); +} + +/* ------------------------------------------------------------------------ */ + static cc_int32 _cci_ipc_send (enum cci_msg_id_t in_request_name, cc_int32 in_launch_server, cci_identifier_t in_identifier, diff --git a/src/ccapi/lib/ccapi_ipc.h b/src/ccapi/lib/ccapi_ipc.h index 73c5b2497..2ba7637ac 100644 --- a/src/ccapi/lib/ccapi_ipc.h +++ b/src/ccapi/lib/ccapi_ipc.h @@ -30,6 +30,7 @@ #include "cci_common.h" cc_int32 cci_ipc_thread_init (void); +void cci_ipc_thread_fini (void); cc_int32 cci_ipc_send (enum cci_msg_id_t in_request_name, cci_identifier_t in_identifier, diff --git a/src/ccapi/lib/ccapi_os_ipc.h b/src/ccapi/lib/ccapi_os_ipc.h index d9eb79f1c..0121adadb 100644 --- a/src/ccapi/lib/ccapi_os_ipc.h +++ b/src/ccapi/lib/ccapi_os_ipc.h @@ -30,6 +30,7 @@ #include "cci_common.h" cc_int32 cci_os_ipc_thread_init (void); +void cci_os_ipc_thread_fini (void); cc_int32 cci_os_ipc (cc_int32 in_launch_server, cci_stream_t in_request_stream, diff --git a/src/ccapi/lib/mac/ccapi_os_ipc.c b/src/ccapi/lib/mac/ccapi_os_ipc.c index 2fabb1922..d51e4c321 100644 --- a/src/ccapi/lib/mac/ccapi_os_ipc.c +++ b/src/ccapi/lib/mac/ccapi_os_ipc.c @@ -34,29 +34,34 @@ #define cci_server_bundle_id "edu.mit.Kerberos.CCacheServer" #define cci_server_path "/System/Library/CoreServices/CCacheServer.app/Contents/MacOS/CCacheServer" -static pthread_key_t g_request_port_key = 0; -static pthread_key_t g_reply_stream_key = 0; -static pthread_key_t g_server_died_key = 0; - /* ------------------------------------------------------------------------ */ cc_int32 cci_os_ipc_thread_init (void) { cc_int32 err = ccNoError; - err = pthread_key_create (&g_request_port_key, free); + err = k5_key_register (K5_KEY_CCAPI_REQUEST_PORT, free); if (!err) { - err = pthread_key_create (&g_reply_stream_key, NULL); + err = k5_key_register (K5_KEY_CCAPI_REPLY_STREAM, NULL); } if (!err) { - err = pthread_key_create (&g_server_died_key, NULL); + err = k5_key_register (K5_KEY_CCAPI_SERVER_DIED, NULL); } return err; } +/* ------------------------------------------------------------------------ */ + +void cci_os_ipc_thread_fini (void) +{ + k5_key_delete (K5_KEY_CCAPI_REQUEST_PORT); + k5_key_delete (K5_KEY_CCAPI_REPLY_STREAM); + k5_key_delete (K5_KEY_CCAPI_SERVER_DIED); +} + #pragma mark - /* ------------------------------------------------------------------------ */ @@ -67,7 +72,7 @@ static boolean_t cci_server_demux (mach_msg_header_t *request, boolean_t handled = false; if (!handled && request->msgh_id == MACH_NOTIFY_NO_SENDERS) { - cc_int32 *server_died = pthread_getspecific (g_server_died_key); + cc_int32 *server_died = k5_getspecific (K5_KEY_CCAPI_SERVER_DIED); if (!server_died) { *server_died = 1; } @@ -94,7 +99,7 @@ kern_return_t cci_mipc_reply (mach_port_t in_reply_port, cci_stream_t reply_stream = NULL; if (!err) { - reply_stream = pthread_getspecific (g_reply_stream_key); + reply_stream = k5_getspecific (K5_KEY_CCAPI_REPLY_STREAM); if (!reply_stream) { err = cci_check_error (ccErrBadInternalMessage); } } @@ -161,7 +166,7 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, } if (!err) { - request_port = pthread_getspecific (g_request_port_key); + request_port = k5_getspecific (K5_KEY_CCAPI_REQUEST_PORT); if (!request_port) { request_port = malloc (sizeof (mach_port_t)); @@ -169,7 +174,7 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, if (!err) { *request_port = MACH_PORT_NULL; - err = pthread_setspecific (g_request_port_key, request_port); + err = k5_setspecific (K5_KEY_CCAPI_REQUEST_PORT, request_port); } } } @@ -226,11 +231,11 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, } if (!err) { - err = pthread_setspecific (g_reply_stream_key, reply_stream); + err = k5_setspecific (K5_KEY_CCAPI_REPLY_STREAM, reply_stream); } if (!err) { - err = pthread_setspecific (g_server_died_key, &server_died); + err = k5_setspecific (K5_KEY_CCAPI_SERVER_DIED, &server_died); } if (!err) { @@ -265,8 +270,8 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, reply_stream = NULL; } - pthread_setspecific (g_reply_stream_key, NULL); - pthread_setspecific (g_server_died_key, NULL); + k5_setspecific (K5_KEY_CCAPI_REPLY_STREAM, NULL); + k5_setspecific (K5_KEY_CCAPI_SERVER_DIED, NULL); if (reply_port != MACH_PORT_NULL) { mach_port_destroy (mach_task_self (), reply_port); } if (ool_request_length ) { vm_deallocate (mach_task_self (), (vm_address_t) ool_request, ool_request_length); } if (reply_stream ) { cci_stream_release (reply_stream); } diff --git a/src/ccapi/lib/win/ccapi_os_ipc.cxx b/src/ccapi/lib/win/ccapi_os_ipc.cxx index 617598b77..4b00e2de3 100644 --- a/src/ccapi/lib/win/ccapi_os_ipc.cxx +++ b/src/ccapi/lib/win/ccapi_os_ipc.cxx @@ -118,6 +118,13 @@ extern "C" cc_int32 cci_os_ipc_thread_init (void) { } +/* ------------------------------------------------------------------------ */ + +void cci_os_ipc_thread_fini (void) +{ +} + + /* ------------------------------------------------------------------------ */ cc_int32 cci_os_ipc (cc_int32 in_launch_server, diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h index 0450eb277..ad1ad8b73 100644 --- a/src/include/k5-thread.h +++ b/src/include/k5-thread.h @@ -410,6 +410,11 @@ typedef enum { K5_KEY_GSS_KRB5_CCACHE_NAME, K5_KEY_GSS_KRB5_ERROR_MESSAGE, K5_KEY_KIM_ERROR_MESSAGE, +#if defined(__MACH__) && defined(__APPLE__) + K5_KEY_CCAPI_REQUEST_PORT, + K5_KEY_CCAPI_REPLY_STREAM, + K5_KEY_CCAPI_SERVER_DIED, +#endif K5_KEY_MAX } k5_key_t; /* rename shorthand symbols for export */ -- 2.26.2