Add launchpad_loader_get_extra() 29/57229/8
authorDaehyeon Jung <darrenh.jung@samsung.com>
Tue, 19 Jan 2016 09:22:22 +0000 (18:22 +0900)
committerDaehyeon Jung <darrenh.jung@samsung.com>
Thu, 21 Jan 2016 05:53:34 +0000 (14:53 +0900)
- Get passed bundle from aul_add_loader()

Change-Id: If4e62e16d063133b81467352bc9614d5f8470c3d
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
inc/key.h
inc/launchpad.h
src/launchpad.c
src/launchpad_lib.c
src/launchpad_loader.c

index d7e01bf..046cb48 100644 (file)
--- a/inc/key.h
+++ b/inc/key.h
@@ -36,10 +36,10 @@ extern "C" {
 #define AUL_K_CALLER_PID       "__AUL_CALLER_PID__"
 #define AUL_K_LOADER_ID                "__AUL_LOADER_ID__"
 #define AUL_K_LOADER_PATH      "__AUL_LOADER_PATH__"
+#define AUL_K_LOADER_EXTRA     "__AUL_LOADER_EXTRA__"
 #define AUL_K_WAYLAND_DISPLAY  "__AUL_WAYLAND_DISPLAY__"
 #define AUL_K_WAYLAND_WORKING_DIR "__AUL_WAYLAND_WORKING_DIR__"
 
-
 #ifdef __cplusplus
 }
 #endif
index 775c2bb..78c3e12 100644 (file)
 #ifndef __LAUNCHPAD_H__
 #define __LAUNCHPAD_H__
 
+#include <bundle.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-typedef void (*loader_create_cb)(int argc, char **argv, int type, void *user_data);
+typedef void (*loader_create_cb)(bundle *extra, int type, void *user_data);
 typedef int (*loader_launch_cb)(int argc, char **argv, const char *app_path,
                const char *appid, const char *pkgid, const char *pkg_type, void *user_data);
 typedef int (*loader_terminate_cb)(int argc, char **argv, void *user_data);
@@ -57,7 +59,6 @@ enum LAUNCHPAD_TYPE {
 
 int launchpad_loader_main(int argc, char **argv, loader_lifecycle_callback_s *callbacks, loader_adapter_s *adapter, void *user_data);
 
-
 #ifdef __cplusplus
 }
 #endif
index aaaeee6..a481a2f 100755 (executable)
@@ -59,6 +59,7 @@ typedef struct {
        guint source;
        guint timer;
        char *loader_path;
+       char *loader_extra;
 } candidate_process_context_t;
 
 typedef struct {
@@ -68,7 +69,7 @@ typedef struct {
 } loader_context_t;
 
 static GList *candidate_slot_list;
-static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path);
+static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *extra);
 static int __remove_slot(int type, int loader_id);
 static int __add_default_slots();
 
@@ -378,7 +379,7 @@ static int __prepare_candidate_process(int type, int loader_id)
        int pid;
        char type_str[2] = {0, };
        char loader_id_str[10] = {0, };
-       char *argv[] = {NULL, NULL, NULL, NULL};
+       char *argv[] = {NULL, NULL, NULL, NULL, NULL};
        candidate_process_context_t* cpt = __find_slot(type, loader_id);
 
        if (cpt == NULL)
@@ -394,6 +395,7 @@ static int __prepare_candidate_process(int type, int loader_id)
                argv[0] = cpt->loader_path;
                argv[1] = type_str;
                argv[2] = loader_id_str;
+               argv[3] = cpt->loader_extra;
                if (execv(argv[0], argv) < 0)
                        _E("Failed to prepare candidate_process");
                else
@@ -831,15 +833,17 @@ static int __dispatch_cmd_add_loader(bundle *kb)
 {
        const char *add_slot_str = NULL;
        const char *caller_pid = NULL;
+       const char *extra;
        int lid;
 
        _W("cmd add loader");
        add_slot_str = bundle_get_val(kb, AUL_K_LOADER_PATH);
        caller_pid = bundle_get_val(kb, AUL_K_CALLER_PID);
+       extra = bundle_get_val(kb, AUL_K_LOADER_EXTRA);
 
        if (add_slot_str && caller_pid) {
                lid = __make_loader_id();
-               candidate_process_context_t *cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid), add_slot_str);
+               candidate_process_context_t *cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid), add_slot_str, extra);
                if (cpc)
                        cpc->timer = g_timeout_add(2000, __handle_preparing_candidate_process, cpc);
 
@@ -1010,7 +1014,7 @@ end:
        return G_SOURCE_CONTINUE;
 }
 
-static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path)
+static candidate_process_context_t* __add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *loader_extra)
 {
        candidate_process_context_t *cpc;
        int fd = -1;
@@ -1032,6 +1036,7 @@ static candidate_process_context_t* __add_slot(int type, int loader_id, int call
        cpc->source = 0;
        cpc->timer = 0;
        cpc->loader_path = strdup(loader_path);
+       cpc->loader_extra = loader_extra ? strdup(loader_extra) : NULL;
 
        fd = __listen_candidate_process(cpc->type, cpc->loader_id);
        if (fd == -1) {
@@ -1070,6 +1075,9 @@ static int __remove_slot(int type, int loader_id)
 
                        candidate_slot_list = g_list_remove_link(candidate_slot_list, iter);
                        free(cpc->loader_path);
+                       if (cpc->loader_extra)
+                               free(cpc->loader_extra);
+
                        free(cpc);
                        return 0;
                }
@@ -1118,23 +1126,23 @@ static int __init_sigchild_fd(void)
 
 static int __add_default_slots()
 {
-       if (__add_slot(LAUNCHPAD_TYPE_COMMON, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT) == NULL)
+       if (__add_slot(LAUNCHPAD_TYPE_COMMON, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL) == NULL)
                return -1;
        if (__prepare_candidate_process(LAUNCHPAD_TYPE_COMMON, PAD_LOADER_ID_STATIC) != 0)
                return -1;
 
-       if (__add_slot(LAUNCHPAD_TYPE_SW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT) == NULL)
+       if (__add_slot(LAUNCHPAD_TYPE_SW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL) == NULL)
                return -1;
        if (__prepare_candidate_process(LAUNCHPAD_TYPE_SW, PAD_LOADER_ID_STATIC) != 0)
                return -1;
 
-       if (__add_slot(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT) == NULL)
+       if (__add_slot(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_DEFAULT, NULL) == NULL)
                return -1;
        if (__prepare_candidate_process(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC) != 0)
                return -1;
 
        if (access(LOADER_PATH_WRT, F_OK | X_OK) == 0) {
-               if (__add_slot(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_WRT) == NULL)
+               if (__add_slot(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC, 0, LOADER_PATH_WRT, NULL) == NULL)
                        return -1;
                if (__prepare_candidate_process(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC) != 0)
                        return -1;
index 8cd52c5..28ecb52 100644 (file)
@@ -37,10 +37,8 @@ static int __loader_id;
 
 static void __at_exit_to_release_bundle()
 {
-       if (__bundle) {
+       if (__bundle)
                bundle_free(__bundle);
-               __bundle = NULL;
-       }
 }
 
 static void __release_appid_at_exit(void)
@@ -232,6 +230,11 @@ static int __candidate_process_launchpad_main_loop(app_pkt_t* pkt,
        if (menu_info != NULL)
                _appinfo_free(menu_info);
 
+       if (__bundle) {
+               bundle_free(__bundle);
+               __bundle = NULL;
+       }
+
        return ret;
 }
 
@@ -276,6 +279,7 @@ static int __before_loop(int argc, char **argv)
 {
        int client_fd;
        int ret = -1;
+       bundle *extra = NULL;
 #ifdef _APPFW_FEATURE_LOADER_PRIORITY
        char err_str[MAX_LOCAL_BUFSZ] = { 0, };
        int res = setpriority(PRIO_PROCESS, 0, LOWEST_PRIO);
@@ -291,11 +295,17 @@ static int __before_loop(int argc, char **argv)
        /* TODO : should be add to check permission in the kernel*/
        setsid();
 
+       if (argc > 3)
+               extra = bundle_decode((const bundle_raw *)argv[3], strlen(argv[3]));
+
        if (__loader_callbacks->create) {
-               __loader_callbacks->create(argc, argv, __loader_type, __loader_user_data);
+               __loader_callbacks->create(extra, __loader_type, __loader_user_data);
                ret = 0;
        }
 
+       if (extra)
+               bundle_free(extra);
+
 #ifdef _APPFW_FEATURE_LOADER_PRIORITY
        res = setpriority(PRIO_PGRP, 0, 0);
        if (res == -1)
index 1dd13c1..0320baa 100644 (file)
@@ -32,6 +32,9 @@
 static Ecore_Fd_Handler *__fd_handler;
 static loader_receiver_cb __receiver;
 
+static int __argc;
+static char** __argv;
+
 static void __init_window(void)
 {
        Evas_Object *win = elm_win_add(NULL, "package_name", ELM_WIN_BASIC);
@@ -72,14 +75,14 @@ static void __init_theme(void)
                free(theme);
 }
 
-static void __loader_create_cb(int argc, char **argv, int type, void *user_data)
+static void __loader_create_cb(bundle *extra, int type, void *user_data)
 {
        int elm_init_cnt = 0;
 
-       __preload_init(argc, argv);
+       __preload_init(__argc, __argv);
        __preload_init_for_process_pool();
 
-       elm_init_cnt = elm_init(g_argc, g_argv);
+       elm_init_cnt = elm_init(__argc, __argv);
        _D("[candidate] elm init, returned: %d", elm_init_cnt);
 
        switch (type) {
@@ -137,7 +140,7 @@ do_exec:
                SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)",
                        argv[0], errno, strerror_r(errno, err_str, sizeof(err_str)));
        else {
-               SECURE_LOGD("[candidate] Exec application (%s)", g_argv[0]);
+               SECURE_LOGD("[candidate] Exec application (%s)", __argv[0]);
                if (execv(argv[0], argv) < 0)
                        SECURE_LOGE("execv() failed for file: \"%s\", error: %d (%s)",
                                argv[0], errno, strerror_r(errno, err_str, sizeof(err_str)));
@@ -217,5 +220,8 @@ int main(int argc, char **argv)
                .remove_fd = __adapter_remove_fd
        };
 
+       __argc = argc;
+       __argv = argv;
+
        return launchpad_loader_main(argc, argv, &callbacks, &adapter, NULL);
 }