Initialize threads before running main loop 26/294326/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Jun 2023 05:56:21 +0000 (05:56 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Jun 2023 06:21:00 +0000 (06:21 +0000)
This patch adds the DBus::Init() call in the OnCreate() of Launchpad
to avoid a blocking issue of the child process.
If a new child process is creating while creating the thread, the child
process can be blocked when the child process tries to allocate the memory.
The initialization of the cleaner thread is moved.

Change-Id: I3c93eca912c69051523651a8b9892eaf4b718b8a
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/dbus.cc
src/launchpad-process-pool/dbus.hh
src/launchpad-process-pool/launchpad.cc

index ef6b38c..3bf7bff 100644 (file)
@@ -88,7 +88,6 @@ class DBusManager {
 
   static DBusManager& GetInst() {
     static DBusManager inst;
-    inst.Init();
     return inst;
   }
 
@@ -115,10 +114,6 @@ class DBusManager {
     queue_->Push(std::move(message));
   }
 
- private:
-  DBusManager() = default;
-  ~DBusManager() { Dispose(); }
-
   void Init() {
     if (!disposed_)
       return;
@@ -128,6 +123,10 @@ class DBusManager {
     disposed_ = false;
   }
 
+ private:
+  DBusManager() = default;
+  ~DBusManager() { Dispose(); }
+
   GDBusConnection* GetConnection() {
     if (conn_)
       return conn_;
@@ -215,4 +214,12 @@ void DBus::SendAppDeadSignal(pid_t pid) {
           g_variant_new("(u)", pid), "App Dead. " + std::to_string(pid)));
 }
 
+void DBus::Init() {
+  DBusManager::GetInst().Init();
+}
+
+void DBus::Finish() {
+  DBusManager::GetInst().Dispose();
+}
+
 }  // namespace launchpad
index dd54090..032165b 100644 (file)
@@ -26,6 +26,8 @@ namespace launchpad {
 
 class DBus {
  public:
+  static void Init();
+  static void Finish();
   static void SendAppLaunchSignal(pid_t pid, const std::string_view appid);
   static void SendAppDeadSignal(pid_t pid);
 };
index 39be747..8a24ddd 100644 (file)
@@ -256,6 +256,9 @@ bool Launchpad::OnCreate() {
     return false;
   }
 
+  cleaner_.reset(new Worker("cleaner+"));
+  DBus::Init();
+
   LoaderManager::GetInst().AddDefaultLoaderContexts();
   LoaderManager::GetInst().SetEventListener(this);
   launchpad::Debug::GetInst().Init();
@@ -264,20 +267,20 @@ bool Launchpad::OnCreate() {
   lang_config_.reset(new LanguageConfig());
   region_format_config_.reset(new RegionFormatConfig());
 
-  cleaner_.reset(new Worker("cleaner+"));
   Log::Init();
   return true;
 }
 
 void Launchpad::OnTerminate() {
   Log::Finish();
-  cleaner_.reset();
   region_format_config_.reset();
   lang_config_.reset();
 
   pid_map_.clear();
   Util::SendCmdToAmd(AmdCmd::LaunchpadDeadSignal);
   Debug::GetInst().Dispose();
+  DBus::Finish();
+  cleaner_.reset();
 
   LoaderManager::GetInst().Dispose();
   channel_.reset();