Delete loader .ready file on context disposal
authorChanggyu Choi <changyu.choi@samsung.com>
Mon, 9 Jun 2025 01:55:01 +0000 (10:55 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Tue, 10 Jun 2025 01:43:33 +0000 (10:43 +0900)
The .ready file signals that the loader is active and ready.
This change ensures the .ready file is removed when the LoaderContext is disposed.
By doing so, the presence or absence of the .ready file accurately
indicates the loader's current availability, allowing its operational
status to be determined by checking for the file's existence.

Change-Id: If4826b981c278e6a93750766e671a00e6c0efd1b
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/launchpad-process-pool/loader_context.cc
src/launchpad-process-pool/loader_context.hh

index ca3cd03dca98a3eaf59b1ccbf43a600985cbc43f..21f0251f20015d37c1d7e5f74ef6d6701de94780 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2023 - 2025 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -189,6 +189,7 @@ void LoaderContext::Dispose() {
   _E("Dispose. type(%d), name(%s), pid(%d)", GetType(), GetLoaderName().c_str(),
      GetPid());
 
+  DeleteReadyFile();
   if (pid_ > 0) {
     _D("Kill process(%d)", pid_);
     if (kill(pid_, SIGKILL) != 0)
@@ -639,7 +640,7 @@ void LoaderContext::CreateReadyFile() {
   std::string path =
       "/tmp/." + std::to_string(getuid()) + "-" + GetLoaderName() + ".ready";
   std::filesystem::path file_path(path);
-  if (std::filesystem::exists(file_path)) {
+  if (access(file_path.c_str(), F_OK) == 0) {
     ready_file_created_ = true;
     return;
   }
@@ -659,4 +660,27 @@ void LoaderContext::CreateReadyFile() {
   ready_file_created_ = true;
 }
 
+void LoaderContext::DeleteReadyFile() {
+  if (!ready_file_created_) return;
+
+  std::string path =
+      "/tmp/." + std::to_string(getuid()) + "-" + GetLoaderName() + ".ready";
+  std::filesystem::path file_path(path);
+  if (access(file_path.c_str(), F_OK) != 0) {
+    ready_file_created_ = false;
+    return;
+  }
+
+  std::error_code error;
+  std::filesystem::remove(file_path, error);
+  if (error) {
+    _E("Failed to remove the file. path(%s), error(%s)",
+        path.c_str(), error.message().c_str());
+    return;
+  }
+
+  _W("File(%s) deleted successfully", path.c_str());
+  ready_file_created_ = false;
+}
+
 }  // namespace launchpad
index e868c810e1a9b15a6465fa766a428ad7aba286cb..b01c604084b8a131e0436a4c51007d31917dffcb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2023 - 2025 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -118,6 +118,7 @@ class LoaderContext : public std::enable_shared_from_this<LoaderContext>,
   void OnIOEventReceived(int fd, int condition) override;
   int GetSchedPriority() const;
   void CreateReadyFile();
+  void DeleteReadyFile();
 
  private:
   void UpdateScore();