From fcf02bef88a17724aa230547459a9eaf1159d6c1 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sat, 24 Apr 2004 21:09:44 +0000 Subject: Added support for library initialization and finalization, and verification that the initializer completed successfully. Delay initialization on POSIX until the first "verification" call. Currently specific to a few platforms, but should still build on others without thread support enabled. Use it to finish creating (if necessary) and destroy mutexes, and free some other storage "permanently" allocated by libraries (currently, libkrb5 cache/keytab type registries only). Change initialization of static mutexes to a two-step operation, a static "partial" initializer and a "finish_init" routine called from a thread-safe environment like library initialization is assumed to be. POSIX will use the former, Windows will use the latter, and the debug support will check that *both* have been used. Added init/fini functions to com_err, profile, krb5, and gssapi libraries. (The profile library one may need to be removed later.) The existing ones, not thread-safe, are still around. Use weak symbol support if available to figure out if the pthread library has been linked in, and avoid calling certain routines if the C library stubs are known not to exist or work. Stub declarations for thread-specific data. Minor bugfixes, whitespace changes. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16268 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/gssapi/gss_libinit.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/lib/gssapi/gss_libinit.c') diff --git a/src/lib/gssapi/gss_libinit.c b/src/lib/gssapi/gss_libinit.c index 0568f29640..fb80c89463 100644 --- a/src/lib/gssapi/gss_libinit.c +++ b/src/lib/gssapi/gss_libinit.c @@ -5,6 +5,7 @@ #include "gssapiP_krb5.h" #include "gss_libinit.h" +#include "k5-platform.h" static int initialized = 0; @@ -12,19 +13,33 @@ static int initialized = 0; * Initialize the GSSAPI library. */ +MAKE_INIT_FUNCTION(gssint_lib_init); +MAKE_FINI_FUNCTION(gssint_lib_fini); + +int gssint_lib_init(void) +{ + return k5_mutex_finish_init(&kg_vdb.mutex); +} + +void gssint_lib_fini(void) +{ + if (!INITIALIZER_RAN(gssint_lib_init) || PROGRAM_EXITING()) + return; + k5_mutex_destroy(&kg_vdb.mutex); +} + OM_uint32 gssint_initialize_library (void) { - if (!initialized) { #if !USE_BUNDLE_ERROR_STRINGS add_error_table(&et_k5g_error_table); add_error_table(&et_ggss_error_table); #endif - initialized = 1; + initialized = 1; } - - return 0; + + return CALL_INIT_FUNCTION(gssint_lib_init); } /* @@ -33,13 +48,12 @@ OM_uint32 gssint_initialize_library (void) void gssint_cleanup_library (void) { - assert (initialized); - + #if !USE_BUNDLE_ERROR_STRINGS remove_error_table(&et_k5g_error_table); remove_error_table(&et_ggss_error_table); #endif - + initialized = 0; } -- cgit