From c8823f15dec9a8f06304834812afb7fd9f4cacdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Thu, 20 Jul 2006 02:01:56 +0000 Subject: [PATCH] Make _gss_load_mech() atomic and run only once, this have the side effect that _gss_mechs and _gss_mech_oids is only initialized once, so if just the users of these two global variables calls _gss_load_mech() first, it will act as a barrier and make sure the variables are never changed and we don't need to lock them. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17842 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/gssapi/mech/gss_mech_switch.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/gssapi/mech/gss_mech_switch.c b/lib/gssapi/mech/gss_mech_switch.c index 924f84bcf..c7cbbe0d3 100644 --- a/lib/gssapi/mech/gss_mech_switch.c +++ b/lib/gssapi/mech/gss_mech_switch.c @@ -27,6 +27,7 @@ */ #include "mech_locl.h" +#include RCSID("$Id$"); #ifndef _PATH_GSS_MECH @@ -35,6 +36,7 @@ RCSID("$Id$"); struct _gss_mech_switch_list _gss_mechs = { NULL } ; gss_OID_set _gss_mech_oids; +static HEIMDAL_MUTEX _gss_mech_mutex = HEIMDAL_MUTEX_INITIALIZER; /* * Convert a string containing an OID in 'dot' form @@ -195,13 +197,20 @@ _gss_load_mech(void) struct _gss_mech_switch *m; void *so; - if (SLIST_FIRST(&_gss_mechs)) + + HEIMDAL_MUTEX_lock(&_gss_mech_mutex); + + if (SLIST_FIRST(&_gss_mechs)) { + HEIMDAL_MUTEX_unlock(&_gss_mech_mutex); return; + } major_status = gss_create_empty_oid_set(&minor_status, &_gss_mech_oids); - if (major_status) + if (major_status) { + HEIMDAL_MUTEX_unlock(&_gss_mech_mutex); return; + } add_builtin(__gss_krb5_initialize()); add_builtin(__gss_spnego_initialize()); @@ -209,6 +218,7 @@ _gss_load_mech(void) fp = fopen(_PATH_GSS_MECH, "r"); if (!fp) { /* perror(_PATH_GSS_MECH); */ + HEIMDAL_MUTEX_unlock(&_gss_mech_mutex); return; } @@ -293,6 +303,7 @@ _gss_load_mech(void) continue; } fclose(fp); + HEIMDAL_MUTEX_unlock(&_gss_mech_mutex); } gssapi_mech_interface