From 5a5bad86b2c129aa53e9003dcd1525df96c7642b Mon Sep 17 00:00:00 2001 From: sun_fan Date: Wed, 22 Sep 2021 17:10:37 +0800 Subject: [PATCH] init: fix bugs Signed-off-by: sun_fan --- services/src/init_cmds.c | 2 +- services/src/init_service_socket.c | 2 +- ueventd/ueventd.c | 2 +- ueventd/ueventd_read_cfg.c | 12 +++++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/services/src/init_cmds.c b/services/src/init_cmds.c index 5cfd88bf..065d33a7 100644 --- a/services/src/init_cmds.c +++ b/services/src/init_cmds.c @@ -95,6 +95,7 @@ int GetParamValue(const char *symValue, char *paramValue, unsigned int paramLen) return -1; } INIT_CHECK_RETURN_VALUE(strncpy_s(tmpName, MAX_PARAM_NAME_LEN, p, tmpLen) == EOK, -1); + tmpLen = MAX_PARAM_VALUE_LEN; int ret = SystemReadParam(tmpName, tmpValue, &tmpLen); // get param if (ret != 0) { INIT_LOGE("Failed to read parameter \" %s \"", tmpName); @@ -429,7 +430,6 @@ static void DoCopy(const char *cmdContent, int maxArg) struct CmdArgs *ctx = GetCmd(cmdContent, " ", maxArg); if (ctx == NULL || ctx->argv == NULL || ctx->argc != DEFAULT_COPY_ARGS_CNT) { INIT_LOGE("Command copy with invalid arguments"); - FreeCmd(ctx); return; } char srcPath[PATH_MAX] = {0}; diff --git a/services/src/init_service_socket.c b/services/src/init_service_socket.c index 653f3f82..bc67176c 100644 --- a/services/src/init_service_socket.c +++ b/services/src/init_service_socket.c @@ -50,7 +50,7 @@ static int CreateSocket(struct ServiceSocket *sockopt) sockopt->name) < 0) { return -1; } - if (access(addr.sun_path, F_OK)) { + if (access(addr.sun_path, F_OK) == 0) { INIT_LOGE("%s already exist, remove it", addr.sun_path); if (unlink(addr.sun_path) != 0) { INIT_LOGE("ulink fail err %d ", errno); diff --git a/ueventd/ueventd.c b/ueventd/ueventd.c index c086608b..26e2ccec 100755 --- a/ueventd/ueventd.c +++ b/ueventd/ueventd.c @@ -119,7 +119,7 @@ static void HandleUevent(const struct Uevent *uevent) static void AddUevent(struct Uevent *uevent, const char *event, size_t len) { - if (uevent == NULL || uevent == NULL || len == 0) { + if (uevent == NULL || event == NULL || len == 0) { return; } diff --git a/ueventd/ueventd_read_cfg.c b/ueventd/ueventd_read_cfg.c index 2036696f..5678545c 100755 --- a/ueventd/ueventd_read_cfg.c +++ b/ueventd/ueventd_read_cfg.c @@ -207,6 +207,7 @@ static int ParseSysfsConfig(char *p) config->uid = (uid_t)StringToInt(items[SYS_CONFIG_UID_NUM], 0); config->gid = (gid_t)StringToInt(items[SYS_CONFIG_GID_NUM], 0); ListAddTail(&g_sysDevices, &config->list); + FreeConfigItems(items, count); return 0; } @@ -216,11 +217,6 @@ static int ParseFirmwareConfig(char *p) if (INVALIDSTRING(p)) { INIT_LOGE("Invalid argument"); } - struct FirmwareUdevConf *config = calloc(1, sizeof(struct FirmwareUdevConf)); - if (config == NULL) { - errno = ENOMEM; - return -1; - } // Sanity checks struct stat st = {}; @@ -234,6 +230,12 @@ static int ParseFirmwareConfig(char *p) return -1; } + struct FirmwareUdevConf *config = calloc(1, sizeof(struct FirmwareUdevConf)); + if (config == NULL) { + errno = ENOMEM; + return -1; + } + config->fmPath = strdup(p); ListAddTail(&g_firmwares, &config->list); return 0; -- GitLab