From 6042a767a3d8c03837a707414882d7fd5a143731 Mon Sep 17 00:00:00 2001 From: "qcqcqc@wsl" <1220204124@zust.edu.cn> Date: Wed, 23 Apr 2025 17:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.c | 5 +++-- src/config.h | 2 ++ src/exec_hook.h | 2 +- src/struct.h | 14 +++++++++----- 4 files changed, 15 insertions(+), 8 deletions(-) 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;