Create ready file for all loaders 30/297330/1
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 17 Aug 2023 03:56:53 +0000 (12:56 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 17 Aug 2023 03:56:53 +0000 (12:56 +0900)
When the loader process is connecting to the launchpad-process-pool,
the launchpad-process-pool creates a ready file to notify that the loader
is ready.

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

index 53e8ab1..b47e57d 100644 (file)
 #include <malloc.h>
 #include <stdio.h>
 #include <sys/capability.h>
+#include <sys/smack.h>
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <filesystem>
+#include <fstream>
+#include <iostream>
+#include <string>
 #include <utility>
 
 #include <exception.hh>
@@ -632,8 +637,10 @@ void LoaderContext::HandleLoaderEvent() {
         SetPid(peer_cred->GetPid());
 
       prepared_ = true;
-      if (listener_ != nullptr)
+      if (listener_ != nullptr) {
+        CreateReadyFile();
         listener_->OnLoaderPrepared(this);
+      }
 
       SECURE_LOGI("Type %d loader was connected. pid: %d", GetType(), pid_);
       UserTracer::Print("Type " + std::to_string(GetType()) +
@@ -666,4 +673,25 @@ void LoaderContext::OnIOEventReceived(int fd, int condition) {
     HandleLoaderClientEvent(condition);
 }
 
+void LoaderContext::CreateReadyFile() {
+  std::string path = "/run/aul/daemons/" + std::to_string(getuid()) + "/." +
+      GetLoaderName() + ".ready";
+  std::filesystem::path file_path(path);
+  if (std::filesystem::exists(file_path))
+    return;
+
+  std::ofstream file_stream(file_path);
+  if (!file_stream.is_open()) {
+    _E("Failed to create the file. path(%s)", path.c_str());
+    return;
+  }
+
+  file_stream.close();
+
+  if (smack_setlabel(path.c_str(), "*", SMACK_LABEL_ACCESS) != 0)
+    _E("smack_setlabel() is failed. path: %s, errno: %d", path.c_str(), errno);
+
+  _W("File(%s) created successfully", path.c_str());
+}
+
 }  // namespace launchpad
index 15ad2b8..1bba362 100644 (file)
@@ -115,6 +115,7 @@ class LoaderContext : public std::enable_shared_from_this<LoaderContext>,
   void SetPrepared(bool prepared);
   void OnIOEventReceived(int fd, int condition) override;
   int GetSchedPriority() const;
+  void CreateReadyFile();
 
  private:
   void UpdateScore();