Create ready file for all loaders
[platform/core/appfw/launchpad.git] / src / launchpad-process-pool / loader_context.cc
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