@@ -122,19 +122,30 @@ msc_engine *modsecurity_create(apr_pool_t *mp, int processing_mode) {
122
122
return msce ;
123
123
}
124
124
125
+ int acquire_global_lock (apr_global_mutex_t * lock , apr_pool_t * mp ) {
126
+ apr_status_t rc ;
127
+ apr_file_t * lock_name ;
128
+ // use temp path template for lock files
129
+ char * path = apr_pstrcat (p , temp_dir , GLOBAL_LOCK_TEMPLATE , NULL );
130
+
131
+ rc = apr_file_mktemp (& lock_name , path , 0 , p )
132
+ if (rc != APR_SUCCESS ) {
133
+ return -1
134
+ }
135
+
136
+ rc = apr_global_mutex_create (& lock_name , lock_name -> fname , APR_LOCK_DEFAULT , mp );
137
+ if (rc != APR_SUCCESS ) {
138
+ return -1 ;
139
+ }
140
+ return APR_SUCCESS ;
141
+ }
125
142
/**
126
143
* Initialise the modsecurity engine. This function must be invoked
127
144
* after configuration processing is complete as Apache needs to know the
128
145
* username it is running as.
129
146
*/
130
147
int modsecurity_init (msc_engine * msce , apr_pool_t * mp ) {
131
148
apr_status_t rc ;
132
- apr_file_t * auditlog_lock_name ;
133
- apr_file_t * geo_lock_name ;
134
- apr_file_t * dbm_lock_name ;
135
-
136
- // use temp path template for lock files
137
- char * path = apr_pstrcat (p , temp_dir , "/modsec-lock-tmp.XXXXXX" , NULL );
138
149
139
150
msce -> auditlog_lock = msce -> geo_lock = NULL ;
140
151
#ifdef GLOBAL_COLLECTION_LOCK
@@ -151,12 +162,8 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
151
162
#ifdef WITH_CURL
152
163
curl_global_init (CURL_GLOBAL_ALL );
153
164
#endif
154
- /* Serial audit log mutext */
155
- rc = apr_file_mktemp (& auditlog_lock_name , path , 0 , p )
156
- if (rc != APR_SUCCESS ) {
157
- return -1
158
- }
159
- rc = apr_global_mutex_create (& msce -> auditlog_lock , auditlog_lock_name , APR_LOCK_DEFAULT , mp );
165
+ /* Serial audit log mutex */
166
+ rc = acquire_global_lock (& msce -> auditlog_lock , mp );
160
167
if (rc != APR_SUCCESS ) {
161
168
return -1 ;
162
169
}
@@ -175,11 +182,7 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
175
182
}
176
183
#endif /* SET_MUTEX_PERMS */
177
184
178
- rc = apr_file_mktemp (& geo_lock_name , path , 0 , p )
179
- if (rc != APR_SUCCESS ) {
180
- return -1
181
- }
182
- rc = apr_global_mutex_create (& msce -> geo_lock , geo_lock_name , APR_LOCK_DEFAULT , mp );
185
+ rc = acquire_global_lock (& msce -> geo_lock , mp );
183
186
if (rc != APR_SUCCESS ) {
184
187
return -1 ;
185
188
}
@@ -196,11 +199,7 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
196
199
#endif /* SET_MUTEX_PERMS */
197
200
198
201
#ifdef GLOBAL_COLLECTION_LOCK
199
- rc = apr_file_mktemp (& dbm_lock_name , path , 0 , p )
200
- if (rc != APR_SUCCESS ) {
201
- return -1
202
- }
203
- rc = apr_global_mutex_create (& msce -> dbm_lock , dbm_lock_name , APR_LOCK_DEFAULT , mp );
202
+ rc = acquire_global_lock (& msce -> dbm_lock , mp );
204
203
if (rc != APR_SUCCESS ) {
205
204
return -1 ;
206
205
}
0 commit comments