Wait for threads ready 59/286859/6
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 16 Jan 2023 01:00:42 +0000 (01:00 +0000)
committerHwanKyu Jhun <h.jhun@samsung.com>
Mon, 16 Jan 2023 05:21:08 +0000 (05:21 +0000)
Before calling the security_manager_prepare_app2() function, all threads
of the loader process MUST be ready. After this patch is applied,
the loader porcess waits until threads are ready if the key-value data
related to the thread exists in the extra data.

Change-Id: I871b1a53e602dadc50134fca5575a54d6fc1b249
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
packaging/launchpad.spec
src/launchpad-loader/conf/default_arch32.loader.in
src/launchpad-loader/conf/default_arch64.loader.in
src/lib/launchpad/src/launchpad_lib.c

index 3fd262b..8ad01c6 100644 (file)
@@ -45,12 +45,18 @@ Obsoletes: amd-mod-launchpad
 
 %define tizen_feature_priority_change 0
 %define tizen_feature_loader_priority 0
-%ifarch armv7l i586
+%ifarch armv7l i686 i586
 %define tizen_arch32 1
 %else
 %define tizen_arch32 0
 %endif
 
+%ifarch x86_64 i686 i586
+%define tizen_emulator 1
+%else
+%define tizen_emulator 0
+%endif
+
 %if "%{?_prelink_enable}" == "y"
 %define tizen_feature_prelink 1
 %else
@@ -125,9 +131,16 @@ _TIZEN_FEATURE_LOADER_ARCH64=ON
 _TIZEN_FEATURE_PRELINK=ON
 %endif
 
+%if 0%{?tizen_emulator}
+HW_LOADER_THREADS=7
+%else
+HW_LOADER_THREADS=8
+%endif
+
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake -DVERSION=%{version} \
        -DMAJORVER=${MAJORVER} \
+       -DHW_LOADER_THREADS=${HW_LOADER_THREADS} \
        -D_TIZEN_FEATURE_PRIORITY_CHANGE:BOOL=${_TIZEN_FEATURE_PRIORITY_CHANGE} \
        -D_TIZEN_FEATURE_LOADER_PRIORITY:BOOL=${_TIZEN_FEATURE_LOADER_PRIORITY} \
        -D_TIZEN_FEATURE_SET_PERSONALITY_32:BOOL=${_TIZEN_FEATURE_SET_PERSONALITY_32} \
index 3e076ce..b663eb7 100644 (file)
@@ -17,6 +17,7 @@ EXTRA_ARRAY_VAL               @LIB_INSTALL_DIR@/libcapi-media-player.so.0
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/libcapi-media-camera.so.0
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/ecore_evas/engines/extn/@EFL_MODULE_VERSION@/module.so
 ALTERNATIVE_LOADER     common-loader1
+EXTRA   threads   @HW_LOADER_THREADS@
 
 [LOADER]
 NAME   common-loader1
@@ -31,6 +32,6 @@ EXTRA_ARRAY_VAL               @LIB_INSTALL_DIR@/libappcore-common.so.1
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/@EFL_MODULE_VERSION@/module.so
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/ecore_evas/engines/extn/@EFL_MODULE_VERSION@/module.so
-
+EXTRA   threads   6
 
 
index c1fdc92..bb50a88 100644 (file)
@@ -13,6 +13,7 @@ EXTRA_ARRAY_VAL               @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/@EFL_MODULE_VERSION@/module.so
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/ecore_evas/engines/extn/@EFL_MODULE_VERSION@/module.so
 ALTERNATIVE_LOADER     common-loader1
+EXTRA   threads   @HW_LOADER_THREADS@
 
 [LOADER]
 NAME   common-loader1
@@ -27,6 +28,6 @@ EXTRA_ARRAY_VAL               @LIB_INSTALL_DIR@/libappcore-common.so.1
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/@EFL_MODULE_VERSION@/module.so
 EXTRA_ARRAY_VAL                @LIB_INSTALL_DIR@/ecore_evas/engines/extn/@EFL_MODULE_VERSION@/module.so
-
+EXTRA   threads   6
 
 
index 9bd3832..af20cae 100644 (file)
  */
 
 #define _GNU_SOURCE
+#include <dirent.h>
+#include <malloc.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/prctl.h>
 #include <sys/socket.h>
-#include <unistd.h>
 #include <sys/types.h>
-#include <sys/prctl.h>
-#include <malloc.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
 #include <bundle_internal.h>
 #include <aul.h>
 #include <security-manager.h>
 #include <buxton2.h>
 #include <vconf.h>
 
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
 #include "launchpad.h"
 #include "launchpad_common.h"
 #include "launchpad_types.h"
@@ -355,11 +356,78 @@ static void __region_format_changed_cb(keynode_t *node, void *user_data)
        setenv("LC_CTYPE", region, 1);
 }
 
+#ifndef USE_STATUS
+static unsigned int __get_thread_count(void)
+{
+       DIR *dp;
+       struct dirent *dentry;
+       unsigned int count = 0;
+
+       dp = opendir("/proc/self/task");
+       if (dp == NULL) {
+               _E("opendir() is failed. errno(%d)", errno);
+               return 0;
+       }
+
+       while ((dentry = readdir(dp)) != NULL) {
+               if (!isdigit(dentry->d_name[0]))
+                       continue;
+
+               count++;
+       }
+
+       closedir(dp);
+       return count;
+}
+#else
+static unsigned int __get_thread_count(void)
+{
+       unsigned int count = 0;
+       char line[LINE_MAX];
+       FILE *fp;
+
+       fp = fopen("/proc/self/status", "r");
+       if (fp == NULL) {
+               _E("fopen() is failed");
+               return 0;
+       }
+
+       while (fgets(line, sizeof(line), fp)) {
+               if (sscanf(line, "Threads: %u", &count) == 1)
+                       break;
+       }
+
+       fclose(fp);
+       return count;
+}
+#endif
+
+static void __wait_for_threads(unsigned int threads)
+{
+       unsigned int thread_count;
+
+       if (threads <= 1)
+               return;
+
+       _W("Thread count = %u", threads);
+       do {
+               thread_count = __get_thread_count();
+               _D("Current thread count = %u", thread_count);
+               if (thread_count >= threads)
+                       break;
+
+               usleep(50 * 1000);
+       } while (threads != thread_count);
+       _E("Threads(%u) are ready", thread_count);
+}
+
 static int __before_loop(int argc, char **argv)
 {
        int client_fd;
        int ret = -1;
        bundle *extra = NULL;
+       const char *val;
+       unsigned int threads = 0;
        int r;
 
        if (_verify_proc_caps() < 0)
@@ -382,9 +450,17 @@ static int __before_loop(int argc, char **argv)
        }
 
        if (__loader_callbacks->create) {
+               val = bundle_get_val(extra, "threads");
+               if (val && isdigit(val[0])) {
+                       _D("threads: %s", val);
+                       threads = atoi(val);
+               }
+
                __loader_callbacks->create(extra, __loader_type,
                                __loader_user_data);
                ret = 0;
+               aul_launch_worker_init();
+               __wait_for_threads(threads);
        }
 
        if (extra)
@@ -409,8 +485,6 @@ static int __before_loop(int argc, char **argv)
        if (r != VCONF_OK)
                _E("Failed to register callback for regionformat. error(%d)", r);
 
-       aul_launch_worker_init();
-
        return ret;
 }