Change socket file name ref/for/tizen
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 Jan 2025 10:32:27 +0000 (19:32 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 Jan 2025 10:32:27 +0000 (19:32 +0900)
This patch changes the file name to the previous socket file for
backward compatibility.

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

index 4e9e99fd7aaffc9e0ae430435138b4735ca03f65..8ee59fd5edbd8368d510127f757b51eca3d0c8fc 100644 (file)
@@ -59,6 +59,19 @@ const int kReceivedBufferSize = 131071;
 const int kMaxPendingConnection = 128;
 const uid_t kRegularUidMin = 5000;
 
+void CreatePreviousSocketFile() {
+  auto path = std::format("{}/{}/.launchpad-process-pool-sock",
+                          kRunAulDaemonsPath, getuid());
+  int fd = open(path.c_str(), O_RDWR | O_CREAT,
+                S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+  if (fd != 0) {
+    _E("open() is failed. errno=%d", errno);
+    return;
+  }
+
+  close(fd);
+}
+
 int GetLaunchpadFdFromSystemd() {
   auto path = std::format("{}-{}", kLaunchpadProcessPoolSock, getuid());
   path[0] = '\0';
@@ -85,36 +98,21 @@ int GetLaunchpadFdFromEnvironment() {
 }
 
 ServerSocket* GetLaunchpadSocket() {
-  int marker;
-  char path[PATH_MAX] = {0,};
-
-  //TODO(Abstract Socket Issue): file-based socket check
   int fd = GetLaunchpadFdFromSystemd();
   if (fd < 0) fd = GetLaunchpadFdFromEnvironment();
   if (fd > -1) {
-    snprintf(path, PATH_MAX, "%s%d/%s",
-        kRunAulDaemonsPath, getuid(), kLaunchpadProcessPoolSock);
-    marker = open(path, O_RDWR | O_CREAT,
-        S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
-    close(marker);
-
+    CreatePreviousSocketFile();
     return new ServerSocket(fd);
-  } else {
-    auto* socket = new ServerSocket();
-    const std::string endpoint = std::string(kLaunchpadProcessPoolSock) + "-" +
-                                 std::to_string(getuid());
-    socket->Bind(endpoint);
-    socket->SetReceiveBufferSize(kReceivedBufferSize);
-    socket->Listen(kMaxPendingConnection);
+  }
 
-    snprintf(path, PATH_MAX, "%s%d/%s",
-        kRunAulDaemonsPath, getuid(), kLaunchpadProcessPoolSock);
-    marker = open(path, O_RDWR | O_CREAT,
-        S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
-    close(marker);
+  auto* socket = new ServerSocket();
+  auto endpoint = std::format("{}-{}", kLaunchpadProcessPoolSock, getuid());
+  socket->Bind(endpoint);
+  socket->SetReceiveBufferSize(kReceivedBufferSize);
+  socket->Listen(kMaxPendingConnection);
 
-    return socket;
-  }
+  CreatePreviousSocketFile();
+  return socket;
 }
 
 void PrintAppInfo(const AppInfo* app_info) {