Write socket status to Id file 60/266360/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 11 Nov 2021 03:51:10 +0000 (12:51 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 11 Nov 2021 06:42:27 +0000 (15:42 +0900)
While calling the aul_initialize() function, the process writes the flag to
the id file. If AMD is restarted, AMD will check the file whether
the socket of the application is listening or not.

Requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/launchpad/+/266359/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/266360/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/266361/

Change-Id: Ie2e158bd8b31a1f3140d13022bed1524911dd375
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launch.cc

index 74e30fd..11d375c 100644 (file)
@@ -99,6 +99,27 @@ int GetPreInitFd() {
   return fd;
 }
 
+void WriteStatusToIdFile(int status) {
+  const char* env_str = getenv("AUL_APPID");
+  if (env_str == nullptr) {
+    if (getuid() >= REGULAR_UID_MIN)
+      _W("Failed to get AUL_APPID");
+
+    return;
+  }
+
+  std::string path = "/run/aul/apps/" + std::to_string(getuid()) + "/" +
+      std::to_string(getpid()) + "/" +  std::string(env_str);
+  FILE* fp = fopen(path.c_str(), "w");
+  if (fp == nullptr) {
+    _E("fopen() is failed. path(%s), errno(%d)", path.c_str(), errno);
+    return;
+  }
+
+  fprintf(fp, "%d", status);
+  fclose(fp);
+}
+
 }  // namespace
 
 extern "C" int aul_is_initialized() {
@@ -209,6 +230,7 @@ extern "C" int aul_initialize() {
       return AUL_R_ECOMM;
     }
   }
+  WriteStatusToIdFile(1);
   aul_notify_start();
 
   aul_initialized = 1;