Use a file descriptor passed by the launchpad 71/176471/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 19 Apr 2018 11:03:44 +0000 (20:03 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Fri, 20 Apr 2018 00:19:40 +0000 (00:19 +0000)
While calling the aul_initialize(), the application can get
the aul listen socketfd by using getenv(). The launchpad sets the
environment variable about the aul listen socketfd before
executing an application.

Requires:
 - https://review.tizen.org/gerrit/#/c/176470/
 - https://review.tizen.org/gerrit/#/c/176467/

Change-Id: Ifaaacc9bea9275e2bb25a5d9fc902a0681f5baa6
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul.h
include/aul_cmd.h
src/launch.c
src/status.c

index 1a1350e..41ac944 100644 (file)
@@ -3073,6 +3073,7 @@ int aul_ignore_app_status(status_listen_h handle);
  * This API is only for Appfw internally.
  */
 int aul_notify_exit(void);
+int aul_notify_start(void);
 
 #ifdef __cplusplus
        }
index 7a944fa..17162b6 100755 (executable)
@@ -133,6 +133,7 @@ enum app_cmd {
        RPC_PORT_CREATE_SOCKET_PAIR = 101,
        RPC_PORT_NOTIFY_RPC_FINISHED = 102,
        COMPLICATION_UPDATE_REQUEST = 103,
+       APP_NOTIFY_START = 104,
 
        APP_CMD_MAX
 };
index 867f8cc..f52abf9 100755 (executable)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <dirent.h>
+#include <ctype.h>
 #include <glib.h>
 #include <gio/gio.h>
 #include <ttrace.h>
@@ -576,17 +577,42 @@ int aul_register_init_callback(
        return 0;
 }
 
+static int __get_preinit_fd(void)
+{
+       int fd = -1;
+       const char *listen_fd;
+
+       listen_fd = getenv("AUL_LISTEN_FD");
+       if (listen_fd) {
+               if (isdigit(*listen_fd))
+                       fd = atoi(listen_fd);
+               unsetenv("AUL_LISTEN_FD");
+       }
+
+       return fd;
+}
+
 int aul_initialize()
 {
+       int flag;
+
        if (aul_initialized)
                return AUL_R_ECANCELED;
 
-
-       aul_fd = aul_sock_create_server(getpid(), getuid());
-       if (aul_fd < 0) {
-               _E("aul_init create sock failed");
-               return AUL_R_ECOMM;
+       aul_fd = __get_preinit_fd();
+       if (aul_fd > 0 && aul_fd < sysconf(_SC_OPEN_MAX)) {
+               flag = fcntl(aul_fd, F_GETFD);
+               flag |= FD_CLOEXEC;
+               (void)fcntl(aul_fd, F_SETFD, flag);
+       } else {
+               _W("Failed to get preinit fd");
+               aul_fd = aul_sock_create_server(getpid(), getuid());
+               if (aul_fd < 0) {
+                       _E("aul_init create sock failed");
+                       return AUL_R_ECOMM;
+               }
        }
+       aul_notify_start();
 
        aul_initialized = 1;
 
index 2e30634..ed9d2c0 100644 (file)
@@ -376,4 +376,13 @@ API int aul_notify_exit(void)
 {
        return aul_sock_send_raw(AUL_UTIL_PID, getuid(),
                        APP_NOTIFY_EXIT, NULL, 0, AUL_SOCK_NOREPLY);
-}
\ No newline at end of file
+}
+
+API int aul_notify_start(void)
+{
+       int r;
+
+       r = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
+                       APP_NOTIFY_START, NULL, 0, AUL_SOCK_NOREPLY);
+       return r;
+}