Skip to content

Commit dd93292

Browse files
committed
In Windows, create Memory and Lock in the global namespace.
1 parent 027b145 commit dd93292

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

apache2/ag_mdb/ag_mdb.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ int Lock_create(struct agmdb_lock *new_lock, const char* lock_name, int lock_nam
5858
return AGMDB_SUCCESS_LOCK_OPEN;
5959
}
6060
#else
61-
read_lock_name_len = (strlen(READ_LOCK_PREFIX) + strlen(lock_name) + 1) * sizeof(char);
62-
write_lock_name_len = (strlen(WRITE_LOCK_PREFIX) + strlen(lock_name) + 1) * sizeof(char);
61+
read_lock_name_len = (strlen(READ_LOCK_SUFFIX) + strlen(lock_name) + 1) * sizeof(char);
62+
write_lock_name_len = (strlen(WRITE_LOCK_SUFFIX) + strlen(lock_name) + 1) * sizeof(char);
6363

6464
if (AGMDB_isstring(lock_name, lock_name_length) != AGMDB_SUCCESS)
6565
return AGMDB_ERROR_LOCK_WIN_NAME_INVALID_STRING;
6666

6767
read_lock_name = (char *)malloc(read_lock_name_len * sizeof(char));
68-
sprintf_s(read_lock_name, read_lock_name_len, "%s%s", READ_LOCK_PREFIX, lock_name);
68+
sprintf_s(read_lock_name, read_lock_name_len, "%s%s", lock_name, READ_LOCK_SUFFIX);
6969
new_lock->read_lock_handle = CreateMutex(
7070
NULL, // Default security settings.
7171
FALSE, // Do not take the lock after created.
@@ -81,7 +81,7 @@ int Lock_create(struct agmdb_lock *new_lock, const char* lock_name, int lock_nam
8181
lock_exists = true;
8282

8383
write_lock_name = (char *)malloc(write_lock_name_len * sizeof(char));
84-
sprintf_s(write_lock_name, write_lock_name_len, "%s%s", WRITE_LOCK_PREFIX, lock_name);
84+
sprintf_s(write_lock_name, write_lock_name_len, "%s%s", lock_name, WRITE_LOCK_SUFFIX);
8585
new_lock->write_lock_handle = CreateMutex(
8686
NULL, // Default security settings.
8787
FALSE, // Do not take the lock after created.

apache2/ag_mdb/ag_mdb_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ int Entry_setKeyValue(CPTR_VOID shm_base, PTR_OFFSET entry_id, const char* key,
341341
** Define the name prefix of Read/Write lock on Windows
342342
*/
343343
#ifdef _WIN32
344-
#define READ_LOCK_PREFIX "DB_LOCK_READ_"
345-
#define WRITE_LOCK_PREFIX "DB_LOCK_WRITE_"
344+
#define READ_LOCK_SUFFIX "_DB_LOCK_READ"
345+
#define WRITE_LOCK_SUFFIX "_DB_LOCK_WRITE"
346346
#endif
347347

348348
/**

apache2/persist_dbm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,11 @@ static int collection_store_ex(int db_option, modsec_rec *msr, apr_table_t *col)
609609
if(ag_dbm == NULL) {
610610
//Create the DB
611611
root_dcfg = msr->dcfg1->root_config;
612+
#ifdef _WIN32
613+
dbm_filename = apr_pstrcat(root_dcfg->mp, "Global\\", root_dcfg->data_dir, "/", var_name->value, NULL);
614+
#else
612615
dbm_filename = apr_pstrcat(root_dcfg->mp, root_dcfg->data_dir, "/", var_name->value, NULL);
616+
#endif
613617
if(root_dcfg == NULL){
614618
msr_log(msr, 1, "collection_retrieve_ex_agmdb: Cannot find root_config in msr->dcfg1.");
615619
goto error;
@@ -621,7 +625,7 @@ static int collection_store_ex(int db_option, modsec_rec *msr, apr_table_t *col)
621625

622626
rc = AGMDB_openDB(new_handle->handle, dbm_filename, strlen(dbm_filename), MAXIMUM_AGMDB_ENTRY_NUM);
623627
if(AGMDB_isError(rc)){
624-
msr_log(msr, 1, "collection_retrieve_ex_agmdb: Failed to create DBM name: %s. Error info: %s", apr_psprintf(msr->mp, "%.*s", var_name->value_len, var_name->value), AGMDB_getErrorInfo(rc));
628+
msr_log(msr, 1, "collection_retrieve_ex_agmdb: Failed to create DBM name: %s. Error info: %s", dbm_filename, AGMDB_getErrorInfo(rc));
625629
goto error;
626630
}
627631
ag_dbm = new_handle->handle;

0 commit comments

Comments
 (0)