Delete loader .ready file on context disposal 20/325320/5
authorChanggyu Choi <changyu.choi@samsung.com>
Mon, 9 Jun 2025 01:55:01 +0000 (10:55 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 9 Jun 2025 06:29:00 +0000 (15:29 +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 a0137f9876a021270f990d7ec8b6b1ee219a88d4..f8263f8b9f75687f2d21fe763ef969412c817ed4 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.
@@ -191,6 +191,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)
@@ -640,7 +641,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;
   }
@@ -660,4 +661,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();