From 5802ba80f71caac223cc1c1dbf95d0accf0ab7c6 Mon Sep 17 00:00:00 2001 From: sun_fan Date: Thu, 16 Sep 2021 15:45:42 +0800 Subject: [PATCH 1/3] init: fix codedex Signed-off-by: sun_fan --- services/src/init_cmds.c | 41 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/services/src/init_cmds.c b/services/src/init_cmds.c index 4fd57ceef..1545f865f 100644 --- a/services/src/init_cmds.c +++ b/services/src/init_cmds.c @@ -237,16 +237,19 @@ static void DoCopyInernal(const char *source, const char *target) break; } } - } - if (!isSuccess) { - INIT_LOGE("Copy from \" %s \" to \" %s \" failed", source, target); - } else { + if (!isSuccess) { + INIT_LOGE("Copy from \" %s \" to \" %s \" failed", source, target); + } fsync(dstFd); } - close(srcFd); - close(dstFd); - srcFd = -1; - dstFd = -1; + if (srcFd >= 0) { + close(srcFd); + srcFd = -1; + } + if (dstFd >= 0) { + close(dstFd); + dstFd = -1; + } } static void DoCopy(const char* cmdContent) @@ -257,21 +260,21 @@ static void DoCopy(const char* cmdContent) FreeCmd(&ctx); return; } - - char *sourceFile = realpath(ctx->argv[0], NULL); - char *targetFile = realpath(ctx->argv[1], NULL); - if (sourceFile == NULL || targetFile == NULL) { - FreeCmd(&ctx); - ctx = NULL; - return; + char sourceFile[PATH_MAX] = {0}; + char targetFile[PATH_MAX] = {0}; + if (realpath(ctx->argv[0], sourceFile) == NULL) { + if (errno != ENOENT) { + return; + } + } + if (realpath(ctx->argv[1], targetFile) == NULL) { + if (errno != ENOENT) { + return; + } } DoCopyInernal(sourceFile, targetFile); FreeCmd(&ctx); - free(sourceFile); - free(targetFile); ctx = NULL; - sourceFile = NULL; - targetFile = NULL; return; } -- Gitee From 30210122e7346d97753d6a42f2248fe0bc785610 Mon Sep 17 00:00:00 2001 From: sun_fan Date: Thu, 16 Sep 2021 16:15:16 +0800 Subject: [PATCH 2/3] init: fix codedex Signed-off-by: sun_fan --- services/src/init_cmds.c | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/init_cmds.c b/services/src/init_cmds.c index 1545f865f..a87e92790 100644 --- a/services/src/init_cmds.c +++ b/services/src/init_cmds.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include -- Gitee From 6e8edd19913084593b080bc918c0261a2317ddbf Mon Sep 17 00:00:00 2001 From: sun_fan Date: Thu, 16 Sep 2021 17:01:02 +0800 Subject: [PATCH 3/3] init: fix code style Signed-off-by: sun_fan --- services/src/init_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/init_cmds.c b/services/src/init_cmds.c index a87e92790..29a2d58a4 100644 --- a/services/src/init_cmds.c +++ b/services/src/init_cmds.c @@ -238,7 +238,7 @@ static void DoCopyInernal(const char *source, const char *target) break; } } - if (!isSuccess) { + if (!isSuccess) { INIT_LOGE("Copy from \" %s \" to \" %s \" failed", source, target); } fsync(dstFd); -- Gitee