Get LAUNCHPAD_LISTEN_FD variable from the environment 13/261413/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Jul 2021 11:16:46 +0000 (20:16 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 16 Jul 2021 11:16:46 +0000 (20:16 +0900)
Currently, the file descriptior is not generated sequentially in some devices.
The launchpad-process-pool is not always started by systemd. In this
case, the program sets LAUNCHPAD_LISTEN_FD variable to the environment.
After this patch is applied, the launchpad-process-pool tries to get the
fd from the environment if calling sd_listen_fd() is failed.

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

index be7a14a..8bc1d78 100644 (file)
@@ -1385,18 +1385,37 @@ static int __create_sock_activation(void)
        return -1;
 }
 
+static int __get_launchpad_listen_fd(void)
+{
+       const char *val;
+
+       val = getenv("LAUNCHPAD_LISTEN_FD");
+       if (!val) {
+               _E("Failed to get LAUNCHPAD_LISTEN_FD");
+               return -1;
+       }
+
+       _W("Listen Fd: %s", val);
+       return atoi(val);
+}
+
 static int __launchpad_pre_init(int argc, char **argv)
 {
        int fd;
 
        /* create launchpad sock */
        fd = __create_sock_activation();
+       if (fd >= 0)
+               return fd;
+
+       fd = __get_launchpad_listen_fd();
+       if (fd >= 0)
+               return fd;
+
+       fd = _create_server_sock(PROCESS_POOL_LAUNCHPAD_SOCK);
        if (fd < 0) {
-               fd = _create_server_sock(PROCESS_POOL_LAUNCHPAD_SOCK);
-               if (fd < 0) {
-                       _E("server sock error %d", fd);
-                       return -1;
-               }
+               _E("server sock error %d", fd);
+               return -1;
        }
 
        return fd;