From 61613cc824e7785919151eb22f1d208779d9282d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Sat, 6 Sep 2025 14:55:42 +0800 Subject: [PATCH 1/6] add restart in processEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- services/loopevent/loop/le_loop.c | 38 ++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/services/loopevent/loop/le_loop.c b/services/loopevent/loop/le_loop.c index 28122c5a5..b15586eec 100644 --- a/services/loopevent/loop/le_loop.c +++ b/services/loopevent/loop/le_loop.c @@ -14,8 +14,17 @@ */ #include "le_loop.h" +#include +#include +#include +#include +#include +#include "securec.h" #include "le_epoll.h" - +#define PATH_MAX_LENGTH 128 +#define FD_TIMEOUT (10 * 1000) +static int invalidateCount = 0; +static uint64_t lastFailed = 0; static int TaskNodeCompare(const HashNode *node1, const HashNode *node2) { @@ -90,6 +99,20 @@ LE_STATUS CloseLoop(EventLoop *loop) return LE_SUCCESS; } +static void CheckFdInfo(int fd) { + LE_CHECK(fd >= 0, return, "invalid fd"); + char fd_path[PATH_MAX_LENGTH] = {0}; + int len = snprintf_s(fd_path, sizeof(fd_path), sizeof(fd_path) - 1, + "/proc/%d/fd/%d", getpid(), fd); + LE_CHECK(len > 0, return, "build fd path failed"); + + char fd_link[PATH_MAX_LENGTH] = {0}; + ssize_t bytes = readlink(fd_path, fd_link, sizeof(fd_link) - 1); + LE_CHECK(bytes > 0, return, "read fd link failed %d", errno); + fd_link[bytes] = '\0'; + LE_LOGI("Get fd link %s", fd_link); +} + LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper) { BaseTask *task = GetTaskByFd((EventLoop *)loop, fd); @@ -97,6 +120,19 @@ LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper) task->handleEvent((LoopHandle)loop, (TaskHandle)task, oper); } else { LE_LOGE("ProcessEvent with invalid fd %d", fd); + LE_CHECK(getpid() != 1, return, "ignore init loop"); + CheckFdInfo(fd); + + struct timespec current; + clock_gettime(CLOCK_REALTIME, ¤t); + uint64_t currentTime = (uint64_t)(current.tv_sec * 1000 + current.tv_nsec / 1000000); + uint64_t diffTime = lastFailed == 0 ? 0 : currentTime - lastFailed; + lastFailed = currentTime; + LE_CHECK(diffTime <= FD_TIMEOUT, invalidateCount = 0; + return LE_FAILURE, "reset LastFailed"); + invalidateCount++; + LE_ONLY_CHECK(invalidateCount >= 1000, return LE_FAILURE); + LE_LOGE("To many invalidate fd, try restart with %d", kill(getpid(), SIGTERM)); } return LE_SUCCESS; } -- Gitee From 0127fdbb88d9bdd8be62b45ed77a5d25f715f680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Sat, 6 Sep 2025 15:12:02 +0800 Subject: [PATCH 2/6] add restart in processEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- services/loopevent/BUILD.gn | 5 ++++- services/loopevent/loop/le_loop.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/services/loopevent/BUILD.gn b/services/loopevent/BUILD.gn index 196b92a68..e84dd62f4 100644 --- a/services/loopevent/BUILD.gn +++ b/services/loopevent/BUILD.gn @@ -48,7 +48,10 @@ if (defined(ohos_lite)) { sources = common_sources include_dirs = common_include external_deps = [ "bounds_checking_function:libsec_shared" ] - defines = [ "_GNU_SOURCE" ] + defines = [ + "_GNU_SOURCE", + "OHOS_LITE" + ] public_configs = [ ":exported_header_files" ] } } else { diff --git a/services/loopevent/loop/le_loop.c b/services/loopevent/loop/le_loop.c index b15586eec..e79420a86 100644 --- a/services/loopevent/loop/le_loop.c +++ b/services/loopevent/loop/le_loop.c @@ -99,6 +99,7 @@ LE_STATUS CloseLoop(EventLoop *loop) return LE_SUCCESS; } +#ifndef OHOS_LITE static void CheckFdInfo(int fd) { LE_CHECK(fd >= 0, return, "invalid fd"); char fd_path[PATH_MAX_LENGTH] = {0}; @@ -112,6 +113,7 @@ static void CheckFdInfo(int fd) { fd_link[bytes] = '\0'; LE_LOGI("Get fd link %s", fd_link); } +#endif LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper) { @@ -120,7 +122,8 @@ LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper) task->handleEvent((LoopHandle)loop, (TaskHandle)task, oper); } else { LE_LOGE("ProcessEvent with invalid fd %d", fd); - LE_CHECK(getpid() != 1, return, "ignore init loop"); +#ifndef OHOS_LITE + LE_CHECK(getpid() != 1, return LE_FAILURE, "ignore init loop"); CheckFdInfo(fd); struct timespec current; @@ -133,6 +136,7 @@ LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper) invalidateCount++; LE_ONLY_CHECK(invalidateCount >= 1000, return LE_FAILURE); LE_LOGE("To many invalidate fd, try restart with %d", kill(getpid(), SIGTERM)); +#endif } return LE_SUCCESS; } -- Gitee From 12ec1c986264a5a7bff9e10d9f23d42bc9f2a50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Sat, 6 Sep 2025 15:13:29 +0800 Subject: [PATCH 3/6] add restart in processEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- services/loopevent/loop/le_loop.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/services/loopevent/loop/le_loop.c b/services/loopevent/loop/le_loop.c index e79420a86..e9e90e074 100644 --- a/services/loopevent/loop/le_loop.c +++ b/services/loopevent/loop/le_loop.c @@ -23,8 +23,8 @@ #include "le_epoll.h" #define PATH_MAX_LENGTH 128 #define FD_TIMEOUT (10 * 1000) -static int invalidateCount = 0; -static uint64_t lastFailed = 0; +static int g_invalidateCount = 0; +static uint64_t g_lastFailed = 0; static int TaskNodeCompare(const HashNode *node1, const HashNode *node2) { @@ -100,14 +100,15 @@ LE_STATUS CloseLoop(EventLoop *loop) } #ifndef OHOS_LITE -static void CheckFdInfo(int fd) { +static void CheckFdInfo(int fd) +{ LE_CHECK(fd >= 0, return, "invalid fd"); char fd_path[PATH_MAX_LENGTH] = {0}; int len = snprintf_s(fd_path, sizeof(fd_path), sizeof(fd_path) - 1, "/proc/%d/fd/%d", getpid(), fd); LE_CHECK(len > 0, return, "build fd path failed"); - char fd_link[PATH_MAX_LENGTH] = {0}; + char fdLink[PATH_MAX_LENGTH] = {0}; ssize_t bytes = readlink(fd_path, fd_link, sizeof(fd_link) - 1); LE_CHECK(bytes > 0, return, "read fd link failed %d", errno); fd_link[bytes] = '\0'; @@ -129,12 +130,12 @@ LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper) struct timespec current; clock_gettime(CLOCK_REALTIME, ¤t); uint64_t currentTime = (uint64_t)(current.tv_sec * 1000 + current.tv_nsec / 1000000); - uint64_t diffTime = lastFailed == 0 ? 0 : currentTime - lastFailed; - lastFailed = currentTime; - LE_CHECK(diffTime <= FD_TIMEOUT, invalidateCount = 0; + uint64_t diffTime = g_lastFailed == 0 ? 0 : currentTime - g_lastFailed; + g_lastFailed = currentTime; + LE_CHECK(diffTime <= FD_TIMEOUT, g_invalidateCount = 0; return LE_FAILURE, "reset LastFailed"); - invalidateCount++; - LE_ONLY_CHECK(invalidateCount >= 1000, return LE_FAILURE); + g_invalidateCount++; + LE_ONLY_CHECK(g_invalidateCount >= 1000, return LE_FAILURE); LE_LOGE("To many invalidate fd, try restart with %d", kill(getpid(), SIGTERM)); #endif } -- Gitee From 36de80fe35b15b0733f49d890a69d3c280e800b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Sat, 6 Sep 2025 15:39:40 +0800 Subject: [PATCH 4/6] add restart in processEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- services/loopevent/loop/le_loop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/loopevent/loop/le_loop.c b/services/loopevent/loop/le_loop.c index e9e90e074..1a7217dd3 100644 --- a/services/loopevent/loop/le_loop.c +++ b/services/loopevent/loop/le_loop.c @@ -14,17 +14,20 @@ */ #include "le_loop.h" + +#ifndef OHOS_LITE #include #include #include #include #include #include "securec.h" -#include "le_epoll.h" + #define PATH_MAX_LENGTH 128 #define FD_TIMEOUT (10 * 1000) static int g_invalidateCount = 0; static uint64_t g_lastFailed = 0; +#endif static int TaskNodeCompare(const HashNode *node1, const HashNode *node2) { @@ -103,7 +106,7 @@ LE_STATUS CloseLoop(EventLoop *loop) static void CheckFdInfo(int fd) { LE_CHECK(fd >= 0, return, "invalid fd"); - char fd_path[PATH_MAX_LENGTH] = {0}; + char fdPath[PATH_MAX_LENGTH] = {0}; int len = snprintf_s(fd_path, sizeof(fd_path), sizeof(fd_path) - 1, "/proc/%d/fd/%d", getpid(), fd); LE_CHECK(len > 0, return, "build fd path failed"); -- Gitee From 7c305f3d26154c2c1438148b004ae17b079fac34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Sat, 6 Sep 2025 15:40:41 +0800 Subject: [PATCH 5/6] add restart in processEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- services/loopevent/loop/le_loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/loopevent/loop/le_loop.c b/services/loopevent/loop/le_loop.c index 1a7217dd3..b13f006d6 100644 --- a/services/loopevent/loop/le_loop.c +++ b/services/loopevent/loop/le_loop.c @@ -107,15 +107,15 @@ static void CheckFdInfo(int fd) { LE_CHECK(fd >= 0, return, "invalid fd"); char fdPath[PATH_MAX_LENGTH] = {0}; - int len = snprintf_s(fd_path, sizeof(fd_path), sizeof(fd_path) - 1, + int len = snprintf_s(fdPath, sizeof(fdPath), sizeof(fdPath) - 1, "/proc/%d/fd/%d", getpid(), fd); LE_CHECK(len > 0, return, "build fd path failed"); char fdLink[PATH_MAX_LENGTH] = {0}; - ssize_t bytes = readlink(fd_path, fd_link, sizeof(fd_link) - 1); + ssize_t bytes = readlink(fdPath, fdLink, sizeof(fdLink) - 1); LE_CHECK(bytes > 0, return, "read fd link failed %d", errno); - fd_link[bytes] = '\0'; - LE_LOGI("Get fd link %s", fd_link); + fdLink[bytes] = '\0'; + LE_LOGI("Get fd link %s", fdLink); } #endif -- Gitee From 40646b0abba438d1dc380e8022f10a42b3f4037d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Sat, 6 Sep 2025 16:05:25 +0800 Subject: [PATCH 6/6] add restart in processEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- services/loopevent/loop/le_loop.c | 1 + 1 file changed, 1 insertion(+) diff --git a/services/loopevent/loop/le_loop.c b/services/loopevent/loop/le_loop.c index b13f006d6..cffa34dd9 100644 --- a/services/loopevent/loop/le_loop.c +++ b/services/loopevent/loop/le_loop.c @@ -14,6 +14,7 @@ */ #include "le_loop.h" +#include "le_epoll.h" #ifndef OHOS_LITE #include -- Gitee