6262oidc_cache_mutex_t * oidc_cache_mutex_create (apr_pool_t * pool , apr_byte_t global ) {
6363 oidc_cache_mutex_t * ctx = apr_pcalloc (pool , sizeof (oidc_cache_mutex_t ));
6464 ctx -> gmutex = NULL ;
65- ctx -> pmutex = NULL ;
65+ ctx -> tmutex = NULL ;
6666 ctx -> mutex_filename = NULL ;
6767 ctx -> is_parent = TRUE;
6868 ctx -> is_global = global ;
@@ -80,7 +80,7 @@ char *oidc_cache_status2str(apr_pool_t *p, apr_status_t statcode) {
8080 return apr_pstrdup (p , buf );
8181}
8282
83- apr_byte_t oidc_cache_mutex_post_config (server_rec * s , oidc_cache_mutex_t * m , const char * type ) {
83+ static apr_byte_t oidc_cache_mutex_global_create (server_rec * s , oidc_cache_mutex_t * m , const char * type ) {
8484
8585 apr_status_t rv = APR_SUCCESS ;
8686 const char * dir ;
@@ -108,31 +108,25 @@ apr_byte_t oidc_cache_mutex_post_config(server_rec *s, oidc_cache_mutex_t *m, co
108108 ;
109109
110110 /* create the mutex lock */
111- if (m -> is_global )
112- rv = apr_global_mutex_create (& m -> gmutex , (const char * )m -> mutex_filename , mech , s -> process -> pool );
113- else
114- rv = apr_proc_mutex_create (& m -> pmutex , (const char * )m -> mutex_filename , mech , s -> process -> pool );
111+ rv = apr_global_mutex_create (& m -> gmutex , (const char * )m -> mutex_filename , mech , s -> process -> pool );
115112
116113 if (rv != APR_SUCCESS ) {
117- oidc_serror (
118- s , "apr_global_mutex_create/apr_proc_mutex_create failed to create mutex (%d) on file %s: %s (%d)" ,
119- mech , m -> mutex_filename , oidc_cache_status2str (s -> process -> pool , rv ), rv );
114+ oidc_serror (s , "apr_global_mutex_create failed to create mutex (%d) on file %s: %s (%d)" , mech ,
115+ m -> mutex_filename , oidc_cache_status2str (s -> process -> pool , rv ), rv );
120116 return FALSE;
121117 }
122118
123119 /* need this on Linux */
124120#ifdef AP_NEED_SET_MUTEX_PERMS
125- if (m -> is_global ) {
126121#if MODULE_MAGIC_NUMBER_MAJOR >= 20081201
127- rv = ap_unixd_set_global_mutex_perms (m -> gmutex );
122+ rv = ap_unixd_set_global_mutex_perms (m -> gmutex );
128123#else
129- rv = unixd_set_global_mutex_perms (m -> gmutex );
124+ rv = unixd_set_global_mutex_perms (m -> gmutex );
130125#endif
131- if (rv != APR_SUCCESS ) {
132- oidc_serror (s , "unixd_set_global_mutex_perms failed; could not set permissions: %s (%d)" ,
133- oidc_cache_status2str (s -> process -> pool , rv ), rv );
134- return FALSE;
135- }
126+ if (rv != APR_SUCCESS ) {
127+ oidc_serror (s , "unixd_set_global_mutex_perms failed; could not set permissions: %s (%d)" ,
128+ oidc_cache_status2str (s -> process -> pool , rv ), rv );
129+ return FALSE;
136130 }
137131#endif
138132
@@ -141,6 +135,23 @@ apr_byte_t oidc_cache_mutex_post_config(server_rec *s, oidc_cache_mutex_t *m, co
141135 return TRUE;
142136}
143137
138+ apr_byte_t oidc_cache_mutex_post_config (server_rec * s , oidc_cache_mutex_t * m , const char * type ) {
139+
140+ apr_status_t rv = APR_SUCCESS ;
141+
142+ if (m -> is_global )
143+ return oidc_cache_mutex_global_create (s , m , type );
144+
145+ rv = apr_thread_mutex_create (& m -> tmutex , APR_THREAD_MUTEX_DEFAULT , s -> process -> pool );
146+ if (rv != APR_SUCCESS ) {
147+ oidc_serror (s , "apr_thread_mutex_create failed: %s (%d)" , oidc_cache_status2str (s -> process -> pool , rv ),
148+ rv );
149+ return FALSE;
150+ }
151+
152+ return TRUE;
153+ }
154+
144155/*
145156 * initialize the cache lock in a child process
146157 */
@@ -152,18 +163,16 @@ apr_status_t oidc_cache_mutex_child_init(apr_pool_t *p, server_rec *s, oidc_cach
152163 return APR_SUCCESS ;
153164
154165 /* initialize the lock for the child process */
155- apr_status_t rv ;
166+ apr_status_t rv = APR_SUCCESS ;
156167
157- if (m -> is_global )
168+ if (m -> is_global ) {
158169 rv = apr_global_mutex_child_init (& m -> gmutex , (const char * )m -> mutex_filename , p );
159- else
160- rv = apr_proc_mutex_child_init (& m -> pmutex , (const char * )m -> mutex_filename , p );
161-
162- if (rv != APR_SUCCESS ) {
163- oidc_serror (
164- s ,
165- "apr_global_mutex_child_init/apr_proc_mutex_child_init failed to reopen mutex on file %s: %s (%d)" ,
166- m -> mutex_filename , oidc_cache_status2str (p , rv ), rv );
170+ if (rv != APR_SUCCESS ) {
171+ oidc_serror (s ,
172+ "apr_global_mutex_child_init failed to reopen mutex on "
173+ "file %s: %s (%d)" ,
174+ m -> mutex_filename , oidc_cache_status2str (p , rv ), rv );
175+ }
167176 }
168177
169178 m -> is_parent = FALSE;
@@ -181,10 +190,10 @@ apr_byte_t oidc_cache_mutex_lock(apr_pool_t *pool, server_rec *s, oidc_cache_mut
181190 if (m -> is_global )
182191 rv = apr_global_mutex_lock (m -> gmutex );
183192 else
184- rv = apr_proc_mutex_lock (m -> pmutex );
193+ rv = apr_thread_mutex_lock (m -> tmutex );
185194
186195 if (rv != APR_SUCCESS )
187- oidc_serror (s , "apr_global_mutex_lock/apr_proc_mutex_lock failed: %s (%d)" ,
196+ oidc_serror (s , "apr_global_mutex_lock/apr_thread_mutex_lock failed: %s (%d)" ,
188197 oidc_cache_status2str (pool , rv ), rv );
189198
190199 return TRUE;
@@ -200,10 +209,10 @@ apr_byte_t oidc_cache_mutex_unlock(apr_pool_t *pool, server_rec *s, oidc_cache_m
200209 if (m -> is_global )
201210 rv = apr_global_mutex_unlock (m -> gmutex );
202211 else
203- rv = apr_proc_mutex_unlock (m -> pmutex );
212+ rv = apr_thread_mutex_unlock (m -> tmutex );
204213
205214 if (rv != APR_SUCCESS )
206- oidc_serror (s , "apr_global_mutex_unlock/apr_proc_mutex_unlock failed: %s (%d)" ,
215+ oidc_serror (s , "apr_global_mutex_unlock/apr_thread_mutex_unlock failed: %s (%d)" ,
207216 oidc_cache_status2str (pool , rv ), rv );
208217
209218 return TRUE;
@@ -222,11 +231,11 @@ apr_byte_t oidc_cache_mutex_destroy(server_rec *s, oidc_cache_mutex_t *m) {
222231 if ((m -> is_global ) && (m -> gmutex )) {
223232 rv = apr_global_mutex_destroy (m -> gmutex );
224233 m -> gmutex = NULL ;
225- } else if (m -> pmutex ) {
226- rv = apr_proc_mutex_destroy (m -> pmutex );
227- m -> pmutex = NULL ;
234+ } else if (m -> tmutex ) {
235+ rv = apr_thread_mutex_destroy (m -> tmutex );
236+ m -> tmutex = NULL ;
228237 }
229- oidc_sdebug (s , "apr_global_mutex_destroy/apr_proc_mutex_destroy returned :%d" , rv );
238+ oidc_sdebug (s , "apr_global_mutex_destroy/apr_thread_mutex_destroy returned :%d" , rv );
230239 }
231240
232241 return (rv == APR_SUCCESS );
0 commit comments