diff --git a/src/config.c b/src/config.c index 82d1bb7..df88870 100644 --- a/src/config.c +++ b/src/config.c @@ -14,12 +14,13 @@ ConfigData *load_config() { DEBUG_LOG("Attaching to shared memory for config data"); // 不指定大小,让shmget自动获取已存在的共享内存段大小 - int shm_id = shmget(SHM_KEY, SHM_SIZE, 0); // 把size参数设为0 + int shm_id = shmget(SHM_KEY, SHM_SIZE, IPC_CREAT | 0640); // 把size参数设为0 DEBUG_LOG("shm_id is: %d", shm_id); if (shm_id == -1) { DEBUG_LOG("shmget failed"); + DEBUG_LOG("err: %d", errno); return NULL; } @@ -31,6 +32,6 @@ ConfigData *load_config() { return NULL; } DEBUG_LOG("Successfully attached to shared memory"); - DEBUG_LOG("Current configuration has %d rules", shared_config->rule_count); + DEBUG_LOG("Current configuration has %d rules", shared_config == NULL? -1 : shared_config->rule_count); return shared_config; } \ No newline at end of file diff --git a/src/config.h b/src/config.h index c62285c..487ac74 100644 --- a/src/config.h +++ b/src/config.h @@ -3,6 +3,8 @@ #include "exec_hook.h" +#define HOOK 1 + ConfigData *load_config(); #endif // CONFIG_H \ No newline at end of file diff --git a/src/exec_hook.h b/src/exec_hook.h index 389d395..9b95b16 100644 --- a/src/exec_hook.h +++ b/src/exec_hook.h @@ -51,6 +51,6 @@ #define ANSI_COLOR_BLUE "\x1b[34m" #define SHM_KEY 0x78945 -#define SHM_SIZE 512 * 1024 +#define SHM_SIZE 1024 * 1024 #endif // EXEC_HOOK_H \ No newline at end of file diff --git a/src/struct.h b/src/struct.h index ebbba4a..7706382 100644 --- a/src/struct.h +++ b/src/struct.h @@ -3,13 +3,17 @@ #define _GNU_SOURCE #define MAX_RULES 128 -#define MAX_ARGS 10 +#define MAX_ARGS 32 +#define MAX_RULE_CMD_LEN 256 +#define MAX_TYPE_LEN 32 +#define MAX_MSG_LEN 256 +#define MAX_ARGS_LEN 128 typedef struct { - char cmd[256]; - char type[32]; - char msg[1024]; - char args[MAX_ARGS][256]; + char cmd[MAX_RULE_CMD_LEN]; + char type[MAX_TYPE_LEN]; + char msg[MAX_MSG_LEN]; + char args[MAX_ARGS][MAX_ARGS_LEN]; int arg_count; } Rule;