Change to use abstract socket in amd,launchpad 84/317284/4
authornewb1e <jihoi.kim@samsung.com>
Mon, 30 Dec 2024 05:06:02 +0000 (14:06 +0900)
committernewb1e <jihoi.kim@samsung.com>
Mon, 30 Dec 2024 07:14:32 +0000 (16:14 +0900)
- Change socket names: ex) @org.tizen.appfw.amd
- Path name starts with '@' will be abstract sockets
- Change connect(), bind() wrapper classes to handle '@' path

Change-Id: Idf5bbed349e48102fafedf605260fed5d2c4cc97
Signed-off-by: newb1e <jihoi.kim@samsung.com>
packaging/ac.socket
src/lib/amd_comp_port.cc
src/lib/amd_login_monitor.c
src/lib/amd_socket.c
src/lib/amd_socket.h
src/lib/launchpad/launchpad.cc
src/lib/request/request_manager.cc
src/lib/socket/client_socket.cc
src/modules/rpc-port/port_info.cc

index dd886d13d1d95df32158b0a7be9bbbb34fd3836a..9334701c9a1c7d62a34ea83a3cec090e3c807450 100644 (file)
@@ -4,9 +4,8 @@ DefaultDependencies=no
 Before=sockets.target
 
 [Socket]
-ListenStream=/run/aul/daemons/.amd-sock
+ListenStream=@org.tizen.appfw.amd
 SocketMode=0777
-DirectoryMode=0777
 
 [Install]
 WantedBy=sockets.target
index 5670768c80a3c2df28d63e182a3e0b8a8b42b6c5..2669c047aa582060f69bffb6116921d95d39c298 100644 (file)
@@ -137,12 +137,19 @@ class PortInfo {
     }
 
     struct sockaddr_un addr = { 0, };
+    socklen_t len = 0;
     addr.sun_family = AF_UNIX;
     snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path.c_str());
-    unlink(path.c_str());
+    if (addr.sun_path[0] == '@') {
+      len = offsetof(struct sockaddr_un, sun_path) + path.length();
+      addr.sun_path[0] = '\0';
+    } else {
+      len = sizeof(struct sockaddr_un);
+      unlink(path.c_str());
+    }
 
     struct sockaddr* addr_ptr = reinterpret_cast<struct sockaddr*>(&addr);
-    int ret = bind(fd, addr_ptr, sizeof(addr));
+    int ret = bind(fd, addr_ptr, len);
     if (ret != 0) {
       ret = -errno;
       _E("bind() is failed. path(%s), errno(%d)", path.c_str(), errno);
index 8047d7bf882d8e5f1c04bfeb8d59b0dadea471f3..181325960855d589ad775eee57627e56088023bd 100644 (file)
@@ -551,6 +551,7 @@ static void __send_ping_to_launchpad(uid_t uid)
        bundle *b;
        char path[PATH_MAX];
 
+       //TODO(Abstract Socket Issue): replace file-based setup check
        snprintf(path, sizeof(path), "%s/%d/%s",
                        PATH_AUL_DAEMONS, uid, LAUNCHPAD_PROCESS_POOL_SOCK);
        if (access(path, F_OK) != 0) {
index e593f187331842e75f2b51a387dcd5900b69e410..3516281d5dd774fb117733191abdbdbe754732d8 100644 (file)
@@ -30,7 +30,7 @@
 #include "amd_util.h"
 #include "amd_socket.h"
 
-#define PATH_AMD_SOCK "/run/aul/daemons/.amd-sock"
+#define PATH_AMD_SOCK "@org.tizen.appfw.amd"
 
 int _create_sock_activation(void)
 {
@@ -52,6 +52,7 @@ int _create_server_sock(void)
 {
        int fd;
        struct sockaddr_un addr;
+       socklen_t len;
 
        fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
        if (fd < 0) {
@@ -62,9 +63,10 @@ int _create_server_sock(void)
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_UNIX;
        snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", PATH_AMD_SOCK);
-       unlink(addr.sun_path);
+       len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path);
+       addr.sun_path[0] = '\0';
 
-       if (bind(fd, (struct sockaddr *)&addr, sizeof(addr))) {
+       if (bind(fd, (struct sockaddr *)&addr, len)) {
                _E("bind error: %d", errno);
                close(fd);
                return -1;
@@ -154,6 +156,7 @@ static int __create_launchpad_client_sock(const char *pad_type, uid_t uid)
 {
        int fd = -1;
        struct sockaddr_un saddr = { 0, };
+       socklen_t len = 0;
        int retry = 1;
        int ret = -1;
 
@@ -173,11 +176,18 @@ static int __create_launchpad_client_sock(const char *pad_type, uid_t uid)
        }
 
        saddr.sun_family = AF_UNIX;
-       snprintf(saddr.sun_path, sizeof(saddr.sun_path),
-                       "/run/aul/daemons/%d/%s", uid, pad_type);
+       if (pad_type[0] == '@') {
+               snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s-%d", pad_type, uid);
+               len = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path);
+               saddr.sun_path[0] = '\0';
+       } else {
+               snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+                               "/run/aul/daemons/%d/%s", uid, pad_type);
+               len = sizeof(struct sockaddr_un);
+       }
+
  retry_con:
-       ret = __connect_client_sock(fd, (struct sockaddr *)&saddr,
-                       sizeof(saddr), 100 * 1000);
+       ret = __connect_client_sock(fd, (struct sockaddr *)&saddr, len, 100 * 1000);
        if (ret < -1) {
                _E("maybe peer not launched or peer dead\n");
                if (retry > 0) {
index 477292b61f80f03aa0e2f60962fdbbf824ad364b..1aa4bd77424eaa7cfea5d6bc7881a95e1a8b4fb1 100644 (file)
@@ -32,7 +32,7 @@
 extern "C" {
 #endif
 
-#define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock"
+#define LAUNCHPAD_PROCESS_POOL_SOCK "@org.tizen.appfw.launchpad-process-pool"
 
 int _create_sock_activation(void);
 
index 8593b0b84a9ff473257097f2954570c1bfd4b2ba..5d30edb09a982d174309c78d83988c088b5b7b76 100644 (file)
@@ -157,7 +157,11 @@ class ResultCb {
 };
 
 std::string GetEndpoint(uid_t uid, const std::string& name) {
-  return "/run/aul/daemons/" + std::to_string(uid) + "/" + name;
+  if (name[0] == '@') {
+    return name + "-" + std::to_string(uid);
+  } else {
+    return "/run/aul/daemons/" + std::to_string(uid) + "/" + name;
+  }
 }
 
 tizen_base::Parcel CreateParcel(int cmd, int opt, bundle* request) {
index d68c39087178f5e5eba557db1c3fce02b270d4f1..73df245ec9db8dd9eb85611405f76078f4b4e740 100644 (file)
@@ -547,6 +547,8 @@ gboolean RequestManager::RequestHandler(GIOChannel* io,
 }
 
 bool RequestManager::Init() {
+  int marker;
+
   amd_fd_ = _create_sock_activation();
   if (amd_fd_ == -1) {
     _D("Create server socket without socket activation");
@@ -558,6 +560,11 @@ bool RequestManager::Init() {
     }
   }
 
+  // TODO(Abstract Socket Issue): file-based socket check
+  marker = open("/run/aul/daemons/.amd-sock", O_RDWR | O_CREAT,
+      S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+  close(marker);
+
   amd_io_ = g_io_channel_unix_new(amd_fd_);
   if (amd_io_ == nullptr) {
     _E("Failed to create gio channel");
index 51f93278cc54b2661d782bf4c5038cb5a3bf57a7..099fc961abab292e62f11017896e9b30e6e944a5 100644 (file)
@@ -59,11 +59,17 @@ void ClientSocket::Connect(const std::string& endpoint) {
   fcntl(GetFd(), F_SETFL, flag | O_NONBLOCK);
 
   struct sockaddr_un sockaddr = { 0, };
+  socklen_t len = 0;
   sockaddr.sun_family = AF_UNIX;
   snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s",
       endpoint.c_str());
+  if (sockaddr.sun_path[0] == '@') {
+    len = offsetof(sockaddr_un, sun_path) + strlen(sockaddr.sun_path);
+    sockaddr.sun_path[0] = '\0';
+  } else {
+    len = sizeof(struct sockaddr_un);
+  }
   struct sockaddr* sockaddr_ptr = reinterpret_cast<struct sockaddr*>(&sockaddr);
-  socklen_t len = static_cast<socklen_t>(sizeof(sockaddr));
 
   int ret;
   int retry = 2;
index ab73bdc2e6bd7a3f08f2c6df26cd9dbfbbaf85e6..3c3e7bfd0dc14153c12336c865391514e7891854 100644 (file)
@@ -42,12 +42,19 @@ int CreateSocket(const std::string& path) {
   }
 
   struct sockaddr_un addr = { 0, };
+  socklen_t len = 0;
   addr.sun_family = AF_UNIX;
   snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path.c_str());
-  unlink(path.c_str());
+  if (addr.sun_path[0] == '@') {
+    len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path);
+    addr.sun_path[0] = '\0';
+  } else {
+    len = sizeof(struct sockaddr_un);
+    unlink(path.c_str());
+  }
 
   struct sockaddr* addr_ptr = reinterpret_cast<struct sockaddr*>(&addr);
-  int ret = bind(fd, addr_ptr, sizeof(addr));
+  int ret = bind(fd, addr_ptr, len);
   if (ret != 0) {
     ret = -errno;
     _E("bind() is failed. path(%s), errno(%d)", path.c_str(), errno);