Wait mountpoints before executing an application 80/164180/6
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 18 Dec 2017 00:54:32 +0000 (09:54 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 18 Dec 2017 04:32:42 +0000 (13:32 +0900)
Change-Id: I810a297ecf966ead6f49aa42954413f7eba73946
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
inc/key.h
inc/launchpad_common.h
src/launchpad.c
src/launchpad_common.c
src/launchpad_lib.c

index aedaa17..d6f77ec 100755 (executable)
@@ -34,6 +34,7 @@ PKG_CHECK_MODULES(${this_target_loader} REQUIRED
        buxton2
        libsystemd
        voice-control-elm
+       gio-2.0
        )
 
 FOREACH(flag ${${this_target_loader}_CFLAGS})
index 2628999..fcce5bb 100644 (file)
--- a/inc/key.h
+++ b/inc/key.h
@@ -44,6 +44,7 @@ extern "C" {
 #define AUL_K_ORG_CALLER_PID           "__AUL_ORG_CALLER_PID__"
 #define AUL_K_HIGHPRIORITY             "__AUL_HIGHPRIORITY__"
 #define AUL_K_IS_GLOBAL                        "__AUL_IS_GLOBAL__"
+#define AUL_K_TEP_PATH                 "_AUL_TEP_PATH_"
 
 #ifdef __cplusplus
 }
index b7c0096..dcfcac6 100644 (file)
@@ -59,6 +59,7 @@
 #define _E(fmt, arg...) LOGE(fmt, ##arg)
 #define _D(fmt, arg...) LOGD(fmt, ##arg)
 #define _W(fmt, arg...) LOGW(fmt, ##arg)
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
 
 #define FREE_AND_NULL(x) do {          \
        if (x) {                        \
@@ -123,6 +124,7 @@ int _close_all_fds(void);
 void _get_cpu_idle(unsigned long long *total, unsigned long long *idle);
 int _setup_stdio(const char *ident);
 int _set_priority(int prio);
+int _wait_tep_mount(bundle *b);
 
 #endif /* __LAUNCHPAD_COMMON_H__ */
 
index 5e66ce0..7e79a65 100755 (executable)
@@ -777,6 +777,10 @@ static int __prepare_exec(const char *appid, const char *app_path,
        /* SET ENVIROMENT*/
        _set_env(menu_info, kb);
 
+       ret = _wait_tep_mount(kb);
+       if (ret < 0)
+               return PAD_ERR_FAILED;
+
        return 0;
 }
 
index e6123b5..ab93f12 100644 (file)
@@ -37,6 +37,8 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/personality.h>
+#include <glib.h>
+#include <gio/gio.h>
 
 #include "launchpad_common.h"
 #include "key.h"
 #define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int) + sizeof(int))
 #define PATH_AMD_SOCK "/run/aul/daemons/.amd-sock"
 #define PATH_DEV_NULL "/dev/null"
+#define MAX_TEP_IS_MOUNT_RETRY_CNT 100
+
+#define TEP_BUS_NAME                   "org.tizen.system.deviced"
+#define TEP_OBJECT_PATH                        "/Org/Tizen/System/DeviceD/Tzip"
+#define TEP_INTERFACE_NAME             "org.tizen.system.deviced.Tzip"
+#define TEP_IS_MOUNTED_METHOD          "IsMounted"
 
 static int __read_proc(const char *path, char *buf, int size)
 {
@@ -895,3 +903,107 @@ int _set_priority(int prio)
 
        return r;
 }
+
+static int __is_tep_mount_done(const char *tep_path)
+{
+       GError *err = NULL;
+       GDBusConnection *conn;
+       GDBusMessage *msg = NULL;
+       GDBusMessage *reply = NULL;
+       GVariant *body;
+       int ret = -1;
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn) {
+               _E("g_bus_get_sync() is failed. %s", err->message);
+               goto end;
+       }
+
+       msg = g_dbus_message_new_method_call(TEP_BUS_NAME,
+                       TEP_OBJECT_PATH,
+                       TEP_INTERFACE_NAME,
+                       TEP_IS_MOUNTED_METHOD);
+       if (!msg) {
+               _E("g_dbus_message_new_method_call() is failed. %s",
+                               err->message);
+               goto end;
+       }
+       g_dbus_message_set_body(msg, g_variant_new("(s)", tep_path));
+
+       reply = g_dbus_connection_send_message_with_reply_sync(conn,
+                       msg,
+                       G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+                       500,
+                       NULL,
+                       NULL,
+                       &err);
+       if (!reply) {
+               _E("Failed to send message with reply. %s", err->message);
+               goto end;
+       }
+
+       body = g_dbus_message_get_body(reply);
+       if (!body) {
+               _E("Failed to get message body.");
+               goto end;
+       }
+
+       g_variant_get(body, "(i)", &ret);
+
+end:
+       if (msg)
+               g_object_unref(msg);
+       if (reply)
+               g_object_unref(reply);
+       if (conn)
+               g_object_unref(conn);
+
+       g_clear_error(&err);
+
+       return ret;
+}
+
+static int __check_tep_mount(const char *tep_path)
+{
+       int r;
+       int cnt = 0;
+
+       if (!tep_path)
+               return 0;
+
+       while (cnt < MAX_TEP_IS_MOUNT_RETRY_CNT) {
+               r = __is_tep_mount_done(tep_path);
+               if (r == 1)
+                       break;
+               usleep(50 * 1000);
+               cnt++;
+       }
+
+       if (r != 1) {
+               _E("Not able to mount within 5 sec: %s", tep_path);
+               return -1;
+       }
+
+       return 0;
+}
+
+int _wait_tep_mount(bundle *b)
+{
+       int r;
+       int i;
+       int len = 0;
+       const char **tep_paths;
+
+       tep_paths = bundle_get_str_array(b, AUL_K_TEP_PATH, &len);
+       if (!tep_paths)
+               return 0;
+
+       for (i = 0; i < len; ++i) {
+               r = __check_tep_mount(tep_paths[i]);
+               if (r < 0)
+                       return -1;
+       }
+
+       _I("Mount has been done.");
+       return 0;
+}
index c476fb9..b7a910f 100644 (file)
@@ -55,7 +55,8 @@ static void __at_exit_to_release_bundle(void)
 }
 
 static int __prepare_exec(const char *appid, const char *app_path,
-                       const char *pkg_type, int type, const char* pkgid, bool global)
+                       const char *pkg_type, int type, const char* pkgid,
+                       bool global, bundle *kb)
 {
        const char *file_name = NULL;
        char process_name[AUL_PR_NAME] = { 0, };
@@ -130,6 +131,10 @@ static int __prepare_exec(const char *appid, const char *app_path,
        snprintf(process_name, AUL_PR_NAME, "%s", file_name);
        prctl(PR_SET_NAME, process_name);
 
+       ret = _wait_tep_mount(kb);
+       if (ret < 0)
+               return -1;
+
        return 0;
 }
 
@@ -138,8 +143,11 @@ static int __default_launch_cb(bundle *kb, const char *appid,
                const char *pkgid, const char *pkg_type, int loader_type, bool global)
 {
        char err_str[MAX_LOCAL_BUFSZ] = { 0, };
+       int r;
 
-       if (__prepare_exec(appid, app_path, pkg_type, loader_type, pkgid, global) < 0) {
+       r = __prepare_exec(appid, app_path, pkg_type, loader_type, pkgid,
+                       global, kb);
+       if (r < 0) {
                _E("__candidate_process_prepare_exec() failed");
                if (access(app_path, F_OK | R_OK)) {
                        SECURE_LOGE("access() failed for file: \"%s\", " \