@@ -122,19 +122,41 @@ 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
+ const char * temp_dir ;
129
+ const char * filename ;
130
+
131
+ // get platform temp dir
132
+ rc = apr_temp_dir_get (& temp_dir , mp );
133
+ if (rc != APR_SUCCESS ) {
134
+ return -1 ;
135
+ }
136
+
137
+ // use temp path template for lock files
138
+ char * path = apr_pstrcat (mp , temp_dir , GLOBAL_LOCK_TEMPLATE , NULL );
139
+
140
+ rc = apr_file_mktemp (& lock_name , path , 0 , mp );
141
+ if (rc != APR_SUCCESS ) {
142
+ return -1 ;
143
+ }
144
+ // below func always return APR_SUCCESS
145
+ apr_file_name_get (& filename , lock_name );
146
+
147
+ rc = apr_global_mutex_create (& lock , filename , APR_LOCK_DEFAULT , mp );
148
+ if (rc != APR_SUCCESS ) {
149
+ return -1 ;
150
+ }
151
+ return APR_SUCCESS ;
152
+ }
125
153
/**
126
154
* Initialise the modsecurity engine. This function must be invoked
127
155
* after configuration processing is complete as Apache needs to know the
128
156
* username it is running as.
129
157
*/
130
158
int modsecurity_init (msc_engine * msce , apr_pool_t * mp ) {
131
159
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
160
139
161
msce -> auditlog_lock = msce -> geo_lock = NULL ;
140
162
#ifdef GLOBAL_COLLECTION_LOCK
@@ -151,12 +173,8 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
151
173
#ifdef WITH_CURL
152
174
curl_global_init (CURL_GLOBAL_ALL );
153
175
#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 );
176
+ /* Serial audit log mutex */
177
+ rc = acquire_global_lock (msce -> auditlog_lock , mp );
160
178
if (rc != APR_SUCCESS ) {
161
179
return -1 ;
162
180
}
@@ -175,11 +193,7 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
175
193
}
176
194
#endif /* SET_MUTEX_PERMS */
177
195
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 );
196
+ rc = acquire_global_lock (msce -> geo_lock , mp );
183
197
if (rc != APR_SUCCESS ) {
184
198
return -1 ;
185
199
}
@@ -196,11 +210,7 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
196
210
#endif /* SET_MUTEX_PERMS */
197
211
198
212
#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 );
213
+ rc = acquire_global_lock (& msce -> dbm_lock , mp );
204
214
if (rc != APR_SUCCESS ) {
205
215
return -1 ;
206
216
}
0 commit comments