Create ready files of loader process 55/296855/4
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 7 Aug 2023 00:16:41 +0000 (09:16 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 17 Aug 2023 02:20:59 +0000 (11:20 +0900)
A new function is added to create a ready file of the loader.
The function creates the file that the path is
"/run/user/<uid>/.<loader_name>.ready".

Change-Id: Id2c6181793650c55b866deddbf2c68ff3b43f1d6
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/app-defined-loader/app-defined-loader.cc
src/launchpad-loader/launchpad_loader.cc
src/launchpad-process-pool/loader_info.cc
src/lib/launchpad/inc/launchpad.h
src/lib/launchpad/launchpad_loader.cc
src/lib/launchpad/launchpad_loader.hh

index 57e7ffd..5c8ebef 100644 (file)
@@ -18,6 +18,7 @@
 #include <bundle_cpp.h>
 #include <bundle_internal.h>
 #include <dlfcn.h>
+#include <glib.h>
 #include <launchpad.h>
 #include <linux/limits.h>
 #include <stdint.h>
@@ -156,6 +157,11 @@ class AppDefinedLoader {
       _E("Plugin::PrepareApp() is failed. error(%d)", ret);
       _exit(EXIT_FAILURE);
     }
+
+    g_idle_add([](gpointer data) {
+          launchpad_loader_create_ready_file();
+          return G_SOURCE_REMOVE;
+        }, nullptr);
   }
 
   static int OnLaunch(int argc, char** argv, const char* app_path,
index cc62aa1..2cae7ac 100644 (file)
@@ -17,6 +17,7 @@
 #include "launchpad-loader/launchpad_loader.hh"
 
 #include <dlfcn.h>
+#include <glib.h>
 
 #include <aul_keys.hh>
 #include <procfs.hh>
@@ -174,6 +175,10 @@ void LaunchpadLoader::OnCreate(const tizen_base::Bundle& extra, int type) {
   InitializeElementary();
 
   hw_acc_config_.reset(new launchpad::HWAccelerationConfig());
+  g_idle_add([](gpointer user_data) {
+        launchpad_loader_create_ready_file();
+        return G_SOURCE_REMOVE;
+      }, nullptr);
 }
 
 int LaunchpadLoader::OnLaunch(const LaunchArgs& args) {
index df00c5c..4640a0d 100644 (file)
@@ -27,6 +27,8 @@
 #include <sstream>
 #include <utility>
 
+#include <aul_keys.hh>
+
 #include "launchpad-process-pool/log_private.hh"
 #include "launchpad-process-pool/util.hh"
 
@@ -278,6 +280,7 @@ LoaderInfo::LoaderInfo(LoaderType type, std::string name, std::string exe,
       on_boot_timeout_(on_boot_timeout),
       sched_priority_(sched_priority),
       condition_path_exists_(std::move(condition_path_exists)) {
+  extra_.Add(kAulLoaderName, name_);
 }
 
 LoaderType LoaderInfo::GetType() const {
index b7d6c21..d95d624 100644 (file)
@@ -85,7 +85,7 @@ bundle *launchpad_loader_get_bundle(void);
  * @brief Blocks all sub threads of the loader.
  * @remarks This function has to be called in the main thread.
  *
- * @return @c on success,
+ * @return @c on success,
  *         otherwise a negative error value
  *
  * @see #launchpad_loader_unblock_threads()
@@ -96,12 +96,22 @@ int launchpad_loader_block_threads(void);
  * @brief Unblocks all sub threads of the loader.
  * @remarks This function has to be called in the main thread.
  *
- * @return @c on success,
+ * @return @c on success,
  *         otherwise a negative error value
  * @see #launchpad_loader_block_threads()
  */
 int launchpad_loader_unblock_threads(void);
 
+/**
+ * @brief Creates a ready file.
+ * @details This function creates a ready file.
+ *          The path of the ready file is "/run/user/<uid>/.<loader_name>.ready".
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ */
+int launchpad_loader_create_ready_file(void);
+
 #ifdef __cplusplus
 }
 #endif
index e7d733c..f967ea6 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <filesystem>
+#include <fstream>
+#include <iostream>
 #include <memory>
 
 #include <app_info.hh>
+#include <aul_keys.hh>
 #include <client_socket.hh>
 #include <exception.hh>
 #include <parcel.hh>
 #include <sched_priority.hh>
 #include <socket.hh>
-#include <util.hh>
 #include <types.hh>
+#include <util.hh>
 
 #include "launchpad/log_private.hh"
 #include "launchpad/step_prepare_execution.hh"
@@ -122,6 +126,10 @@ const tizen_base::Bundle& LaunchpadLoader::GetBundle() const {
   return app_info_.GetBundle();
 }
 
+const std::string& LaunchpadLoader::GetLoaderName() const {
+  return loader_name_;
+}
+
 void LaunchpadLoader::ResetArgs() {
   memset(argv_[LoaderArg::Type], 0, strlen(argv_[LoaderArg::Type]));
   memset(argv_[LoaderArg::Id], 0, strlen(argv_[LoaderArg::Id]));
@@ -185,6 +193,10 @@ bool LaunchpadLoader::OnCreate() {
     threads = std::stoi(threads_str);
   }
 
+  loader_name_ = extra.GetString(kAulLoaderName);
+  if (!loader_name_.empty())
+    _W("name: %s", loader_name_.c_str());
+
   callback_.create(extra.GetHandle(), loader_type_, user_data_);
   aul_launch_worker_init();
   WaitForThreads(threads);
@@ -384,3 +396,26 @@ extern "C" EXPORT_API int launchpad_loader_block_threads(void) {
 extern "C" EXPORT_API int launchpad_loader_unblock_threads(void) {
   return ThreadControl::GetInst().UnblockThreads();
 }
+
+extern "C" EXPORT_API int launchpad_loader_create_ready_file(void) {
+  if (!::context)
+    return -1;
+
+  std::string path = "/run/user/" + std::to_string(getuid()) + "/." +
+      ::context->GetLoaderName() + ".ready";
+  std::filesystem::path file_path(path);
+  if (std::filesystem::exists(file_path)) {
+    _D("Already exists. path(%s)", path.c_str());
+    return 0;
+  }
+
+  std::ofstream file_stream(file_path);
+  if (!file_stream.is_open()) {
+    _E("Failed to create the file. path(%s)", path.c_str());
+    return -1;
+  }
+
+  file_stream.close();
+  _W("File(%s) created successfully", path.c_str());
+  return 0;
+}
index 8f44252..4277d3a 100644 (file)
@@ -41,6 +41,7 @@ class LaunchpadLoader {
       void* user_data);
   void Quit();
   const tizen_base::Bundle& GetBundle() const;
+  const std::string& GetLoaderName() const;
 
  private:
   void WaitForThreads(int threads);
@@ -68,6 +69,7 @@ class LaunchpadLoader {
   char** argv_;
   int loader_type_;
   int loader_id_;
+  std::string loader_name_;
   loader_lifecycle_callback_s callback_ = { nullptr, };
   loader_adapter_s adapter_callback_ = { nullptr, };
   void* user_data_ = nullptr;