Support script file to register static loaders 43/69843/3 accepted/tizen/common/20160520.170912 accepted/tizen/ivi/20160520.002320 accepted/tizen/mobile/20160520.002331 accepted/tizen/tv/20160520.002251 accepted/tizen/wearable/20160520.002312 submit/tizen/20160519.002157 submit/tizen/20160519.045032
authorJunghoon Park <jh9216.park@samsung.com>
Tue, 17 May 2016 04:38:53 +0000 (13:38 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 17 May 2016 08:27:49 +0000 (17:27 +0900)
Change-Id: Ic518d538de87a5f1401f503dd4d4862f433008fb
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
CMakeLists.txt
inc/launchpad.h
inc/launchpad_common.h
inc/loader_info.h [new file with mode: 0644]
packaging/default.loader [new file with mode: 0644]
packaging/launchpad.spec
src/launchpad.c
src/loader_info.c [new file with mode: 0644]

index d5fbc44..e7eceb5 100755 (executable)
@@ -62,9 +62,6 @@ ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"")
 IF(_APPFW_FEATURE_PRIORITY_CHANGE)
        ADD_DEFINITIONS("-D_APPFW_FEATURE_PRIORITY_CHANGE")
 ENDIF(_APPFW_FEATURE_PRIORITY_CHANGE)
-IF(_APPFW_FEATURE_LAZY_LOADER)
-       ADD_DEFINITIONS("-D_APPFW_FEATURE_LAZY_LOADER")
-ENDIF(_APPFW_FEATURE_LAZY_LOADER)
 
 ADD_DEFINITIONS("-DLAUNCHPAD_LOG")
 ADD_DEFINITIONS("-DPRELOAD_ACTIVATE")
@@ -98,6 +95,7 @@ SET(LAUNCHPAD_PROCESS_POOL "launchpad-process-pool")
 SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES
        src/launchpad.c
        src/launchpad_common.c
+       src/loader_info.c
        )
 ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES})
 
@@ -112,6 +110,7 @@ INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin)
 CONFIGURE_FILE(packaging/preload_list.txt.in packaging/preload_list.txt @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/preload_list.txt DESTINATION share/aul)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/launchpad-process-pool-preload-list.txt DESTINATION share/aul)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul)
 
 # liblaunchpad
 SET(LAUNCHPAD_LIB "launchpad")
index aaa01a8..b8508c2 100644 (file)
@@ -54,9 +54,8 @@ enum LAUNCHPAD_TYPE {
        LAUNCHPAD_TYPE_COMMON,
        LAUNCHPAD_TYPE_SW,
        LAUNCHPAD_TYPE_HW,
-       LAUNCHPAD_TYPE_WRT,
-       LAUNCHPAD_TYPE_JS_NATIVE,
-       LAUNCHPAD_TYPE_DYNAMIC,
+       LAUNCHPAD_TYPE_USER,
+       LAUNCHPAD_TYPE_DYNAMIC = 100,
        LAUNCHPAD_TYPE_MAX
 };
 
index 6eaf630..8587052 100644 (file)
@@ -24,6 +24,7 @@
 #include <dlog.h>
 #include <bundle_internal.h>
 #include <sys/socket.h>
+#include <sys/un.h>
 
 #ifdef LAUNCHPAD_LOG
 #undef LOG_TAG
diff --git a/inc/loader_info.h b/inc/loader_info.h
new file mode 100644 (file)
index 0000000..4ee7c80
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+#include <glib.h>
+
+#define METHOD_TIMEOUT         0x1
+#define METHOD_VISIBILITY      0x2
+#define METHOD_DEMAND          0x4
+
+typedef struct _loader_info {
+       int type;
+       char *name;
+       char *exe;
+       char *app_type;
+       int detection_method;
+       int timeout_val;
+} loader_info_t;
+
+GList *_loader_info_load(const char *path);
+void _loader_info_dispose(GList *info);
+int _loader_info_find_type_by_app_type(GList *info,  const char *app_type);
+
+
+
diff --git a/packaging/default.loader b/packaging/default.loader
new file mode 100644 (file)
index 0000000..b2f2409
--- /dev/null
@@ -0,0 +1,14 @@
+[LOADER]
+NAME   wrt-loader
+EXE    /usr/bin/wrt-loader
+APP_TYPE       webapp
+DETECTION_METHOD       TIMEOUT|DEMAND
+TIMEOUT                5000
+
+[LOADER]
+NAME jsnative-loader
+EXE /usr/bin/jsnative-loader
+APP_TYPE jsapp
+DETECTION_METHOD       TIMEOUT|VISIBILITY
+TIMEOUT                5000
+
index cc14447..f5db9b8 100644 (file)
@@ -28,7 +28,6 @@ Requires(postun): /usr/bin/systemctl
 Requires(preun): /usr/bin/systemctl
 
 %define appfw_feature_priority_change 0
-%define appfw_feature_lazy_loader 0
 
 %description
 Launchpad for launching applications
@@ -53,13 +52,9 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 %if 0%{?appfw_feature_priority_change}
 _APPFW_FEATURE_PRIORITY_CHANGE=ON
 %endif
-%if 0%{?appfw_feature_lazy_loader}
-_APPFW_FEATURE_LAZY_LOADER=ON
-%endif
 
 %cmake -DVERSION=%{version} \
        -D_APPFW_FEATURE_PRIORITY_CHANGE:BOOL=${_APPFW_FEATURE_PRIORITY_CHANGE} \
-       -D_APPFW_FEATURE_LAZY_LOADER:BOOL=${_APPFW_FEATURE_LAZY_LOADER} \
        .
 %__make %{?_smp_mflags}
 
@@ -84,6 +79,7 @@ cp %{_builddir}/%{name}-%{version}/LICENSE  %{buildroot}/usr/share/license/%{nam
 %{_prefix}/share/license/%{name}
 %{_prefix}/share/aul/preload_list.txt
 %{_prefix}/share/aul/launchpad-process-pool-preload-list.txt
+%{_prefix}/share/aul/default.loader
 %{_unitdir_user}/launchpad-process-pool.service
 %{_unitdir_user}/launchpad-process-pool.socket
 %{_unitdir_user}/sockets.target.wants/launchpad-process-pool.socket
index 665f2ec..5e13b94 100755 (executable)
@@ -39,6 +39,7 @@
 #include "sigchild.h"
 #include "key.h"
 #include "launchpad.h"
+#include "loader_info.h"
 
 #define AUL_PR_NAME         16
 #define EXEC_CANDIDATE_EXPIRED 5
 #define CANDIDATE_NONE 0
 #define PROCESS_POOL_LAUNCHPAD_SOCK ".launchpad-process-pool-sock"
 #define LOADER_PATH_DEFAULT "/usr/bin/launchpad-loader"
-#define LOADER_PATH_WRT                "/usr/bin/wrt-loader"
-#define LOADER_PATH_JS_NATIVE  "/usr/bin/jsnative-loader"
-
-#define METHOD_TIMEOUT         0x1
-#define METHOD_VISIBILITY      0x2
-#define METHOD_DEMAND          0x4
+#define LOADER_INFO_PATH       "/usr/share/aul"
 
 typedef struct {
        int type;
@@ -66,7 +62,6 @@ typedef struct {
        guint timer;
        char *loader_path;
        char *loader_extra;
-       bool enabled;
        int detection_method;
        int timeout_val;
 } candidate_process_context_t;
@@ -77,11 +72,13 @@ typedef struct {
        int loader_id;
 } loader_context_t;
 
+static GList *loader_info_list;
+static int user_slot_offset;
 static GList *candidate_slot_list;
 static int sys_hwacc = -1;
 static candidate_process_context_t *__add_slot(int type, int loader_id,
                int caller_pid, const char *loader_path, const char *extra,
-               bool enabled, int detection_method, int timeout_val);
+               int detection_method, int timeout_val);
 static int __remove_slot(int type, int loader_id);
 static int __add_default_slots();
 
@@ -297,13 +294,11 @@ static int __set_access(const char *appid)
 static int __get_launchpad_type(const char *internal_pool, const char *hwacc,
                const char *app_type)
 {
-       if (app_type && strcmp(app_type, "webapp") == 0) {
-               _D("[launchpad] launchpad type: wrt");
-               return LAUNCHPAD_TYPE_WRT;
-       } else if (app_type && strcmp(app_type, "jsapp") == 0) {
-               _D("[launchpad] launchpad type: js_native");
-               return LAUNCHPAD_TYPE_JS_NATIVE;
-       }
+       int type;
+
+       type = _loader_info_find_type_by_app_type(loader_info_list,  app_type);
+       if (type >= LAUNCHPAD_TYPE_USER)
+               return type;
 
        if (internal_pool && strcmp(internal_pool, "true") == 0 && hwacc) {
                if (strcmp(hwacc, "NOT_USE") == 0) {
@@ -405,9 +400,6 @@ static int __prepare_candidate_process(int type, int loader_id)
        if (cpt == NULL)
                return -1;
 
-       if (!cpt->enabled)
-               return -1;
-
        memset(argbuf, ' ', LOADER_ARG_LEN);
        argbuf[LOADER_ARG_LEN-1] = '\0';
        argv[4] = argbuf;
@@ -624,13 +616,6 @@ static int __launch_directly(const char *appid, const char *app_path, int clifd,
        }
        SECURE_LOGD("==> real launch pid : %d %s\n", pid, app_path);
 
-#ifdef _APPFW_FEATURE_LAZY_LOADER
-       if (cpc && !cpc->enabled) {
-               cpc->enabled = true;
-               __set_timer(cpc);
-       }
-#endif
-
        return pid;
 }
 
@@ -914,7 +899,7 @@ static int __dispatch_cmd_add_loader(bundle *kb)
        if (add_slot_str && caller_pid) {
                lid = __make_loader_id();
                cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid),
-                               add_slot_str, extra, true,
+                               add_slot_str, extra,
                                METHOD_TIMEOUT | METHOD_VISIBILITY, 2000);
                __set_timer(cpc);
                return lid;
@@ -1128,7 +1113,7 @@ end:
 
 static candidate_process_context_t *__add_slot(int type, int loader_id,
                int caller_pid, const char *loader_path,
-               const char *loader_extra, bool enabled, int detection_method,
+               const char *loader_extra, int detection_method,
                int timeout_val)
 {
        candidate_process_context_t *cpc;
@@ -1154,7 +1139,6 @@ static candidate_process_context_t *__add_slot(int type, int loader_id,
        cpc->timer = 0;
        cpc->loader_path = strdup(loader_path);
        cpc->loader_extra = loader_extra ? strdup(loader_extra) : NULL;
-       cpc->enabled = enabled;
        cpc->detection_method = detection_method;
        cpc->timeout_val = timeout_val;
 
@@ -1253,13 +1237,47 @@ static int __init_sigchild_fd(void)
        return 0;
 }
 
+static void __add_slot_from_info(gpointer data, gpointer user_data)
+{
+       loader_info_t *info = (loader_info_t *)data;
+       candidate_process_context_t *cpc;
+
+       if (access(info->exe, F_OK | X_OK) == 0) {
+               cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, PAD_LOADER_ID_STATIC,
+                               0, info->exe, NULL, info->detection_method, info->timeout_val);
+               if (cpc == NULL)
+                       return;
+
+               if (__prepare_candidate_process(LAUNCHPAD_TYPE_USER + user_slot_offset,
+                               PAD_LOADER_ID_STATIC) != 0)
+                       return;
+
+               info->type = LAUNCHPAD_TYPE_USER + user_slot_offset;
+               user_slot_offset++;
+       }
+}
+
+static void __add_default_slots_from_file(void)
+{
+       if (loader_info_list)
+               _loader_info_dispose(loader_info_list);
+
+       loader_info_list = _loader_info_load(LOADER_INFO_PATH);
+
+       if (loader_info_list == NULL)
+               return;
+
+       user_slot_offset = 0;
+       g_list_foreach(loader_info_list, __add_slot_from_info, NULL);
+}
+
 static int __add_default_slots(void)
 {
        candidate_process_context_t *cpc;
        int ret;
 
        cpc = __add_slot(LAUNCHPAD_TYPE_COMMON, PAD_LOADER_ID_STATIC, 0,
-                       LOADER_PATH_DEFAULT, NULL, true,
+                       LOADER_PATH_DEFAULT, NULL,
                        METHOD_TIMEOUT | METHOD_VISIBILITY, 5000);
        if (cpc == NULL)
                return -1;
@@ -1270,7 +1288,7 @@ static int __add_default_slots(void)
                return -1;
 
        cpc = __add_slot(LAUNCHPAD_TYPE_SW, PAD_LOADER_ID_STATIC, 0,
-                       LOADER_PATH_DEFAULT, NULL, true,
+                       LOADER_PATH_DEFAULT, NULL,
                        METHOD_TIMEOUT | METHOD_VISIBILITY, 5000);
        if (cpc == NULL)
                return -1;
@@ -1281,7 +1299,7 @@ static int __add_default_slots(void)
                return -1;
 
        cpc = __add_slot(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC, 0,
-                       LOADER_PATH_DEFAULT, NULL, true,
+                       LOADER_PATH_DEFAULT, NULL,
                        METHOD_TIMEOUT | METHOD_VISIBILITY, 5000);
        if (cpc == NULL)
                return -1;
@@ -1291,40 +1309,7 @@ static int __add_default_slots(void)
        if (ret != 0)
                return -1;
 
-       if (access(LOADER_PATH_WRT, F_OK | X_OK) == 0) {
-#ifdef _APPFW_FEATURE_LAZY_LOADER
-               cpc = __add_slot(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC, 0,
-                               LOADER_PATH_WRT, NULL, false,
-                               METHOD_TIMEOUT | METHOD_DEMAND, 5000);
-               if (cpc == NULL)
-                       return -1;
-#else
-               cpc = __add_slot(LAUNCHPAD_TYPE_WRT, PAD_LOADER_ID_STATIC, 0,
-                               LOADER_PATH_WRT, NULL, true,
-                               METHOD_TIMEOUT | METHOD_DEMAND, 5000);
-               if (cpc == NULL)
-                       return -1;
-
-               ret = __prepare_candidate_process(LAUNCHPAD_TYPE_WRT,
-                               PAD_LOADER_ID_STATIC);
-               if (ret != 0)
-                       return -1;
-#endif
-       }
-
-       if (access(LOADER_PATH_JS_NATIVE, F_OK | X_OK) == 0) {
-               cpc = __add_slot(LAUNCHPAD_TYPE_JS_NATIVE, PAD_LOADER_ID_STATIC,
-                               0, LOADER_PATH_JS_NATIVE, NULL, true,
-                               METHOD_TIMEOUT | METHOD_VISIBILITY, 5000);
-               if (cpc == NULL)
-                       return -1;
-
-               ret = __prepare_candidate_process(LAUNCHPAD_TYPE_JS_NATIVE,
-                               PAD_LOADER_ID_STATIC);
-               if (ret != 0)
-                       return -1;
-       }
-
+       __add_default_slots_from_file();
        return 0;
 }
 
diff --git a/src/loader_info.c b/src/loader_info.c
new file mode 100644 (file)
index 0000000..cfcab66
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <malloc.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <string.h>
+
+#include "loader_info.h"
+#include "launchpad_common.h"
+
+#define TAG_LOADER     "[LOADER]"
+#define TAG_NAME       "NAME"
+#define TAG_EXE                "EXE"
+#define TAG_APP_TYPE   "APP_TYPE"
+#define TAG_DETECTION_METHOD   "DETECTION_METHOD"
+#define TAG_TIMEOUT    "TIMEOUT"
+#define VAL_METHOD_TIMEOUT     "TIMEOUT"
+#define VAL_METHOD_DEMAND      "DEMAND"
+#define VAL_METHOD_VISIBILITY  "VISIBILITY"
+
+static loader_info_t *__create_loader_info()
+{
+       loader_info_t *info = malloc(sizeof(loader_info_t));
+
+       info->type = 0;
+       info->name = NULL;
+       info->exe = NULL;
+       info->app_type = NULL;
+       info->detection_method = METHOD_TIMEOUT | METHOD_VISIBILITY;
+       info->timeout_val = 5000;
+
+       return info;
+}
+
+static void __parse_detection_method(loader_info_t *info, char *line)
+{
+       char *token;
+       char *savedptr;
+       char refined_tok[MAX_LOCAL_BUFSZ];
+
+       token = strtok_r(line, "|", &savedptr);
+       info->detection_method = 0;
+       while (token) {
+               sscanf(token, "%s", refined_tok);
+               if (!strcmp(refined_tok, VAL_METHOD_TIMEOUT))
+                       info->detection_method |= METHOD_TIMEOUT;
+               if (!strcmp(refined_tok, VAL_METHOD_VISIBILITY))
+                       info->detection_method |= METHOD_VISIBILITY;
+               if (!strcmp(refined_tok, VAL_METHOD_DEMAND))
+                       info->detection_method |= METHOD_DEMAND;
+
+               token = strtok_r(NULL, "|", &savedptr);
+       }
+
+       _D("detection_method:%d", info->detection_method);
+}
+
+static GList *__parse_file(GList *list, const char *path)
+{
+       FILE *fp;
+       char buf[MAX_LOCAL_BUFSZ];
+       char tok1[MAX_LOCAL_BUFSZ];
+       char tok2[MAX_LOCAL_BUFSZ];
+       loader_info_t *cur_info = NULL;
+
+       fp = fopen(path, "rt");
+
+       if (fp == NULL)
+               return list;
+
+       while (fgets(buf, MAX_LOCAL_BUFSZ, fp) != NULL) {
+               tok1[0] = '\0';
+               tok2[0] = '\0';
+               sscanf(buf, "%s %s", tok1, tok2);
+
+               if (strcasecmp(TAG_LOADER,  tok1) == 0) {
+                       if (cur_info != NULL)
+                               list = g_list_append(list, cur_info);
+                       cur_info = __create_loader_info();
+                       continue;
+               }
+
+               if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#')
+                       continue;
+
+               if (strcasecmp(TAG_NAME,  tok1) == 0)
+                       cur_info->name = strdup(tok2);
+               else if (strcasecmp(TAG_EXE, tok1) == 0)
+                       cur_info->exe = strdup(tok2);
+               else if (strcasecmp(TAG_APP_TYPE, tok1) == 0)
+                       cur_info->app_type = strdup(tok2);
+               else if (strcasecmp(TAG_DETECTION_METHOD, tok1) == 0)
+                       __parse_detection_method(cur_info, &buf[strlen(tok1)]);
+               else if (strcasecmp(TAG_TIMEOUT,  tok1) == 0)
+                       cur_info->timeout_val = atoi(tok2);
+       }
+
+       if (cur_info != NULL)
+               list = g_list_append(list, cur_info);
+
+       fclose(fp);
+
+       return list;
+}
+
+GList *_loader_info_load(const char *path)
+{
+       DIR *dir_info;
+       struct dirent entry;
+       struct dirent *result = NULL;
+       GList *list = NULL;
+       char buf[MAX_LOCAL_BUFSZ];
+       char *ext;
+
+       dir_info = opendir(path);
+       if (dir_info == NULL)
+               return  NULL;
+
+       while (readdir_r(dir_info, &entry, &result) == 0 && result != NULL) {
+               if (entry.d_name[0] == '.')
+                       continue;
+               ext = strrchr(entry.d_name, '.');
+               if (ext && !strcmp(ext, ".loader")) {
+                       snprintf(buf, sizeof(buf), "%s/%s", path, entry.d_name);
+                       list = __parse_file(list, buf);
+               }
+       }
+       closedir(dir_info);
+
+       return list;
+}
+
+static void __free_info(gpointer data)
+{
+       loader_info_t *info;
+
+       if (data == NULL)
+               return;
+
+       info = (loader_info_t *)data;
+
+       free(info->name);
+       free(info->exe);
+       free(info->app_type);
+
+       free(info);
+}
+
+void _loader_info_dispose(GList *info)
+{
+       g_list_free_full(info, __free_info);
+}
+
+static int __comp_app_type(gconstpointer a, gconstpointer b)
+{
+       loader_info_t *info = (loader_info_t *)a;
+
+       if (info == NULL || info->app_type == NULL || b == NULL)
+               return -1;
+
+       return strcmp(info->app_type, b);
+}
+
+int _loader_info_find_type_by_app_type(GList *info,  const char *app_type)
+{
+       GList *cur = g_list_find_custom(info, app_type, __comp_app_type);
+
+       if (cur == NULL)
+               return -1;
+
+       loader_info_t *cur_info = (loader_info_t *)cur->data;
+
+       return cur_info->type;
+}
+
+
+
+