summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2018-04-19 20:03:44 +0900
committerHwanKyu Jhun <h.jhun@samsung.com>2018-04-20 00:19:40 +0000
commitb7a5312a3b3916e510b41273f27eb38e289b3af8 (patch)
tree41b2d149321e86294fc0b0baedcc1720b6b2ec4f
parentac8a729194669f526d348714e11286ce25e8df41 (diff)
downloadaul-1-b7a5312a3b3916e510b41273f27eb38e289b3af8.tar.gz
aul-1-b7a5312a3b3916e510b41273f27eb38e289b3af8.tar.bz2
aul-1-b7a5312a3b3916e510b41273f27eb38e289b3af8.zip
Use a file descriptor passed by the launchpad
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>
-rw-r--r--include/aul.h1
-rwxr-xr-xinclude/aul_cmd.h1
-rwxr-xr-xsrc/launch.c36
-rw-r--r--src/status.c11
4 files changed, 43 insertions, 6 deletions
diff --git a/include/aul.h b/include/aul.h
index 1a1350e9..41ac9449 100644
--- a/include/aul.h
+++ b/include/aul.h
@@ -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
}
diff --git a/include/aul_cmd.h b/include/aul_cmd.h
index 7a944fa4..17162b6c 100755
--- a/include/aul_cmd.h
+++ b/include/aul_cmd.h
@@ -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
};
diff --git a/src/launch.c b/src/launch.c
index 867f8cca..f52abf91 100755
--- a/src/launch.c
+++ b/src/launch.c
@@ -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;
diff --git a/src/status.c b/src/status.c
index 2e30634b..ed9d2c02 100644
--- a/src/status.c
+++ b/src/status.c
@@ -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;
+}