From: Krzysztof Jackiewicz Date: Mon, 9 Dec 2024 10:21:25 +0000 (+0100) Subject: Properly handle disappearing threads during sync X-Git-Tag: accepted/tizen/9.0/unified/20241210.020008~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aaf1400d2a61cc1031cc75720776e252c9f12ee5;p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git Properly handle disappearing threads during sync Plus few minor fixes Change-Id: I0928f0ce811e26b25e3e3f566410f2ba95054416 --- diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index 18568428..cc68915c 100644 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -718,20 +718,19 @@ static int get_alive_threads(int own_tid) noexcept static int check_threads(int own_tid) noexcept { + int ret = 0; for (unsigned i = 0; i < 10; ++i) { - auto ret = get_alive_threads(own_tid); + ret = get_alive_threads(own_tid); if (ret == 0) break; /* - * This may happen if a thread disappears, an entry is removed from /proc and fstatat + * This may happen if a thread disappears, an entry is removed from /proc and getdents64 * fails. */ - if (i == 9) - return ret; } - return 0; + return ret; } static bool no_new_threads() noexcept @@ -748,8 +747,8 @@ static bool no_new_threads() noexcept static int signal_and_wait_for_handlers(pid_t own_pid, int own_tid) noexcept { - // No allocations allowed in this function - int ret = 0; + // No allocations allowed in this function + int ret = 0; int time_left = MAX_SIG_WAIT_TIME; do { ret = check_threads(own_tid); @@ -758,7 +757,7 @@ static int signal_and_wait_for_handlers(pid_t own_pid, int own_tid) noexcept for (int i = 0; i < g_managed_tids_num; ++i) { if (!g_thread_alive[i]) - break; + continue; if (!g_thread_signaled[i]) { g_thread_signaled[i] = true; @@ -805,7 +804,7 @@ static int signal_and_wait_for_handlers(pid_t own_pid, int own_tid) noexcept if (time_left == 0) return ETIME; - } while (1); + } while (true); return ret; } @@ -928,7 +927,7 @@ static int security_manager_set_process_groups_internal(const std::vector return SECURITY_MANAGER_ERROR_MEMORY; } - auto deleter = [&](gid_t* ptr){free(ptr);}; + auto deleter = [&](gid_t* ptr){free(ptr);}; std::unique_ptr scopedGidBuffer(grp, deleter); ret = getgroups(NGROUPS_MAX + 1, grp);