Properly handle disappearing threads during sync 33/316033/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 9 Dec 2024 10:21:25 +0000 (11:21 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 9 Dec 2024 10:21:25 +0000 (11:21 +0100)
Plus few minor fixes

Change-Id: I0928f0ce811e26b25e3e3f566410f2ba95054416

src/client/client-security-manager.cpp

index 1856842819e6af947ea77be11781853000e3a0c7..cc68915ced3c3e696bc821d8a3a6581f3e6b9f41 100644 (file)
@@ -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<gid_t>
         return SECURITY_MANAGER_ERROR_MEMORY;
     }
 
-       auto deleter = [&](gid_t* ptr){free(ptr);};
+    auto deleter = [&](gid_t* ptr){free(ptr);};
     std::unique_ptr<gid_t, decltype(deleter)> scopedGidBuffer(grp, deleter);
 
     ret = getgroups(NGROUPS_MAX + 1, grp);