From 494b322f06e7f29ea06fb6a8def8fc0435ef4674 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 31 Dec 2019 08:07:14 +0900 Subject: [PATCH 01/16] Release version 0.10.3 Changes: - Remove compile warning messages - Fix wrong implementation Change-Id: I67c9ece883875cbb7579110812ac84df1a8f145b Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 1581432..f1cc49e 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.10.2 +Version: 0.10.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 24f7e3ba66036cd1f26b9c98ca989e91fb08834a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jan 2020 09:45:28 +0900 Subject: [PATCH 02/16] Fix type The return value type of iniparser_getstring() is changed to "const char *". Change-Id: I85ad74f7019d6fdc9f861e894e29fd81263e2da6 Signed-off-by: Hwankyu Jhun --- src/launchpad_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/launchpad_config.c b/src/launchpad_config.c index 5c459e8..8c74693 100644 --- a/src/launchpad_config.c +++ b/src/launchpad_config.c @@ -84,7 +84,7 @@ int _config_get_int_value(config_type_e type) return value; } -static char *__get_string_value(dictionary *d, const char *tag, +static const char *__get_string_value(dictionary *d, const char *tag, const char *key) { char buf[128]; @@ -106,7 +106,7 @@ int _config_init(void) { dictionary *d; char *val; - char *str; + const char *str; int ret; _D("config init"); -- 2.7.4 From 96f0974c960adf8e6b0c79ac59e999fd794ee498 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jan 2020 09:51:45 +0900 Subject: [PATCH 03/16] Release version 0.10.4 Changes: - Fix type Change-Id: I20100e2f21d6b708e4199703bd9fd0764e12681c Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index f1cc49e..0077851 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.10.3 +Version: 0.10.4 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From b772f01c490f3769e00b5cd2b20af4e97965547a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jan 2020 17:13:13 +0900 Subject: [PATCH 04/16] Fix static anlysis issue Change-Id: I8672a904fae3b77f158b4955f0383b76465d468b Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 111 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 88 insertions(+), 23 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index 16dc627..e751fbb 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -105,6 +105,8 @@ typedef struct { guint live_timer; int state; bool is_hydra; + guint pollfd; + guint hydra_pollfd; } candidate_process_context_t; typedef struct { @@ -2076,7 +2078,27 @@ end: return G_SOURCE_CONTINUE; } -static candidate_process_context_t *__add_slot(int type, int loader_id, +static void __destroy_slot(candidate_process_context_t *cpc) +{ + if (!cpc) + return; + + if (cpc->hydra_pollfd) + g_source_remove(cpc->hydra_pollfd); + + if (cpc->pollfd) + g_source_remove(cpc->pollfd); + + if (cpc->loader_extra) + free(cpc->loader_extra); + + if (cpc->loader_path) + free(cpc->loader_path); + + free(cpc); +} + +static candidate_process_context_t *__create_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *loader_extra, int detection_method, int activation_method, int deactivation_method, @@ -2085,16 +2107,27 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, bool on_boot, bool app_exists, bool is_hydra) { candidate_process_context_t *cpc; - int fd = -1; - guint pollfd; - if (__find_slot(type, loader_id) != NULL) + cpc = calloc(1, sizeof(candidate_process_context_t)); + if (cpc == NULL) { + _E("Out of memory"); return NULL; + } - cpc = (candidate_process_context_t *)malloc( - sizeof(candidate_process_context_t)); - if (cpc == NULL) + cpc->loader_path = strdup(loader_path); + if (cpc->loader_path == NULL) { + _E("Failed to duplicate loader path(%s)", loader_path); + __destroy_slot(cpc); return NULL; + } + + cpc->loader_extra = loader_extra ? strdup(loader_extra) : strdup(""); + if (cpc->loader_extra == NULL) { + _E("Failed to duplicate loader extra(%s)", + loader_extra ? loader_extra : "null"); + __destroy_slot(cpc); + return NULL; + } cpc->type = type; cpc->prepared = false; @@ -2107,8 +2140,6 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, cpc->last_exec_time = 0; cpc->source = 0; cpc->timer = 0; - cpc->loader_path = strdup(loader_path); - cpc->loader_extra = loader_extra ? strdup(loader_extra) : strdup(""); cpc->detection_method = detection_method; cpc->timeout_val = timeout_val; cpc->cpu_total_time = 0; @@ -2132,12 +2163,42 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, else cpc->state = CANDIDATE_PROCESS_STATE_RUNNING; + return cpc; +} + +static candidate_process_context_t *__add_slot(int type, int loader_id, + int caller_pid, const char *loader_path, + const char *loader_extra, int detection_method, + int activation_method, int deactivation_method, + unsigned int ttl, int timeout_val, + int threshold_max, int threshold_min, + bool on_boot, bool app_exists, bool is_hydra) +{ + candidate_process_context_t *cpc; + int fd; + guint pollfd; + int hydra_fd; + guint hydra_pollfd; + + if (__find_slot(type, loader_id) != NULL) + return NULL; + + cpc = __create_slot(type, loader_id, + caller_pid, loader_path, + loader_extra, detection_method, + activation_method, deactivation_method, + ttl, timeout_val, + threshold_max, threshold_min, + on_boot, app_exists, is_hydra); + if (cpc == NULL) + return NULL; + fd = __listen_candidate_process(cpc->type, cpc->loader_id); if (fd == -1) { _E("[launchpad] Listening the socket to " \ "the type %d candidate process failed.", cpc->type); - free(cpc); + __destroy_slot(cpc); return NULL; } @@ -2145,29 +2206,37 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, cpc->type, cpc->loader_id); if (pollfd == 0) { close(fd); - free(cpc); + __destroy_slot(cpc); return NULL; } + cpc->pollfd = pollfd; + if (is_hydra) { - fd = __listen_hydra_process(cpc->type, cpc->loader_id); - if (fd == -1) { + hydra_fd = __listen_hydra_process(cpc->type, cpc->loader_id); + if (hydra_fd == -1) { _E("[launchpad] Listening the socket to " \ "the type %d hydra process failed.", cpc->type); - free(cpc); + close(fd); + __destroy_slot(cpc); return NULL; } - pollfd = __poll_fd(fd, G_IO_IN, (GSourceFunc)__handle_hydra_event, - cpc->type, cpc->loader_id); - if (pollfd == 0) { + hydra_pollfd = __poll_fd(hydra_fd, G_IO_IN, + (GSourceFunc)__handle_hydra_event, + cpc->type, cpc->loader_id); + if (hydra_pollfd == 0) { + close(hydra_fd); close(fd); - free(cpc); + __destroy_slot(cpc); return NULL; } + + cpc->hydra_pollfd = hydra_pollfd; } + candidate_slot_list = g_list_append(candidate_slot_list, cpc); return cpc; @@ -2185,11 +2254,7 @@ static int __remove_slot(int type, int loader_id) __dispose_candidate_process(cpc); candidate_slot_list = g_list_delete_link( candidate_slot_list, iter); - free(cpc->loader_path); - if (cpc->loader_extra) - free(cpc->loader_extra); - - free(cpc); + __destroy_slot(cpc); return 0; } -- 2.7.4 From 479332d45c45dd5057ca94fd98e42e3358713447 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 23 Jan 2020 11:04:14 +0900 Subject: [PATCH 05/16] Fix fd event handling - Uses GIOChannel instead of GSource Change-Id: Iaf999693e8da5b0830f015435d0ebf37accab91a Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 1 + inc/launchpad_io_channel.h | 38 ++++++ src/launchpad.c | 315 ++++++++++++++------------------------------- src/launchpad_io_channel.c | 159 +++++++++++++++++++++++ src/log_private.h | 17 ++- 5 files changed, 314 insertions(+), 216 deletions(-) create mode 100644 inc/launchpad_io_channel.h create mode 100644 src/launchpad_io_channel.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ad32426..5239b49 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,7 @@ SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES src/launchpad_debug.c src/launchpad_signal.c src/launchpad_config.c + src/launchpad_io_channel.c ) ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES}) diff --git a/inc/launchpad_io_channel.h b/inc/launchpad_io_channel.h new file mode 100644 index 0000000..6498fb3 --- /dev/null +++ b/inc/launchpad_io_channel.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 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 + +typedef enum { + IO_IN = 0x01, + IO_OUT = 0x02, + IO_PRI = 0x04, + IO_ERR = 0x08, + IO_HUP = 0x10, + IO_NVAL = 0x20, +} io_condition_e; + +typedef bool (*io_channel_event_cb)(int fd, io_condition_e condition, + void *user_data); + +typedef struct io_channel_s *io_channel_h; + +io_channel_h _io_channel_create(int fd, io_condition_e condition, + io_channel_event_cb, void *user_data); + +void _io_channel_destroy(io_channel_h channel); diff --git a/src/launchpad.c b/src/launchpad.c index e751fbb..b847c2c 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -44,6 +44,7 @@ #include "launchpad_common.h" #include "launchpad_config.h" #include "launchpad_debug.h" +#include "launchpad_io_channel.h" #include "launchpad_signal.h" #include "launchpad_types.h" #include "loader_info.h" @@ -84,7 +85,6 @@ typedef struct { int send_fd; int hydra_fd; int last_exec_time; - guint source; guint timer; char *loader_path; char *loader_extra; @@ -105,8 +105,9 @@ typedef struct { guint live_timer; int state; bool is_hydra; - guint pollfd; - guint hydra_pollfd; + io_channel_h client_channel; + io_channel_h channel; + io_channel_h hydra_channel; } candidate_process_context_t; typedef struct { @@ -152,6 +153,11 @@ static sequencer __sequencer; static int MEMORY_STATUS_LOW; static int MEMORY_STATUS_NORMAL; +static io_channel_h __logger_channel; +static io_channel_h __label_monitor_channel; +static io_channel_h __sigchild_channel; +static io_channel_h __launchpad_channel; + static candidate_process_context_t *__add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *extra, int detection_method, int activation_method, @@ -787,7 +793,7 @@ static void __reset_slot(candidate_process_context_t *cpc) cpc->send_fd = -1; cpc->prepared = false; cpc->pid = CANDIDATE_NONE; - cpc->source = 0; + cpc->client_channel = NULL; cpc->timer = 0; cpc->live_timer = 0; } @@ -804,8 +810,8 @@ static void __dispose_candidate_process(candidate_process_context_t *cpc) } if (cpc->live_timer > 0) g_source_remove(cpc->live_timer); - if (cpc->source > 0) - g_source_remove(cpc->source); + if (cpc->client_channel) + _io_channel_destroy(cpc->client_channel); if (cpc->timer > 0) g_source_remove(cpc->timer); if (cpc->send_fd > 0) @@ -1216,172 +1222,57 @@ static int __launchpad_pre_init(int argc, char **argv) return fd; } -static void __destroy_poll_data(gpointer data) -{ - free(data); -} - -static gboolean __glib_check(GSource *src) -{ - GSList *fd_list; - GPollFD *tmp; - - fd_list = src->poll_fds; - do { - tmp = (GPollFD *) fd_list->data; - if ((tmp->revents & (G_IO_IN | G_IO_PRI | G_IO_HUP | - G_IO_NVAL))) - return TRUE; - fd_list = fd_list->next; - } while (fd_list); - - return FALSE; -} - -static gboolean __glib_dispatch(GSource *src, GSourceFunc callback, - gpointer data) -{ - return callback(data); -} - -static gboolean __glib_prepare(GSource *src, gint *timeout) -{ - return FALSE; -} - -static void __glib_finalize(GSource *src) -{ - GSList *fd_list; - GPollFD *gpollfd; - - fd_list = src->poll_fds; - do { - gpollfd = (GPollFD *)fd_list->data; - close(gpollfd->fd); - g_free(gpollfd); - - fd_list = fd_list->next; - } while (fd_list); -} - -static GSourceFuncs funcs = { - .prepare = __glib_prepare, - .check = __glib_check, - .dispatch = __glib_dispatch, - .finalize = __glib_finalize -}; - -static guint __poll_fd(int fd, gushort events, GSourceFunc func, int type, - int loader_id) +static bool __handle_loader_client_event(int fd, io_condition_e cond, + void *data) { - int r; - GPollFD *gpollfd; - GSource *src; - loader_context_t *lc; - - src = g_source_new(&funcs, sizeof(GSource)); - if (!src) { - _E("out of memory"); - return 0; - } - - gpollfd = (GPollFD *)g_malloc(sizeof(GPollFD)); - if (!gpollfd) { - _E("out of memory"); - g_source_destroy(src); - return 0; - } - - gpollfd->events = events; - gpollfd->fd = fd; - - lc = malloc(sizeof(loader_context_t)); - if (lc == NULL) { - g_free(gpollfd); - g_source_destroy(src); - return 0; - } - - lc->gpollfd = gpollfd; - lc->type = type; - lc->loader_id = loader_id; - - g_source_add_poll(src, gpollfd); - g_source_set_callback(src, func, - (gpointer) lc, __destroy_poll_data); - g_source_set_priority(src, G_PRIORITY_DEFAULT); - - r = g_source_attach(src, NULL); - if (r == 0) { - g_free(gpollfd); - g_source_destroy(src); - return 0; - } - - return r; -} - -static gboolean __handle_loader_client_event(gpointer data) -{ - loader_context_t *lc = (loader_context_t *) data; - int type = lc->type; - int loader_id = lc->loader_id; - gushort revents = lc->gpollfd->revents; - candidate_process_context_t *cpc = __find_slot(type, loader_id); + candidate_process_context_t *cpc = data; if (cpc == NULL) - return G_SOURCE_REMOVE; + return false; - if (revents & (G_IO_HUP | G_IO_NVAL)) { - SECURE_LOGE("Type %d candidate process was " \ + if (cond & (IO_HUP | IO_NVAL)) { + SECURE_LOGE("Type %d candidate process was " "(POLLHUP|POLLNVAL), pid: %d", cpc->type, cpc->pid); cpc->pid = CANDIDATE_NONE; __dispose_candidate_process(cpc); __prepare_candidate_process(cpc->type, cpc->loader_id); - return G_SOURCE_REMOVE; + return false; } - return G_SOURCE_CONTINUE; + return true; + } -static gboolean __handle_hydra_client_event(gpointer data) +static bool __handle_hydra_client_event(int fd, io_condition_e cond, + void *data) { - loader_context_t *lc = (loader_context_t *)data; - int type = lc->type; - int loader_id = lc->loader_id; - gushort revents = lc->gpollfd->revents; - candidate_process_context_t *cpc = __find_slot(type, loader_id); + candidate_process_context_t *cpc = data; if (cpc == NULL) - return G_SOURCE_REMOVE; + return false; - if (revents & (G_IO_HUP | G_IO_NVAL)) { - SECURE_LOGE("Type %d hydra process was " \ + if (cond & (IO_HUP | IO_NVAL)) { + SECURE_LOGE("Type %d hydra process was " "(POLLHUP|POLLNVAL), pid: %d", cpc->type, cpc->hydra_pid); __dispose_hydra_process(cpc); __prepare_candidate_process(cpc->type, cpc->loader_id); - return G_SOURCE_REMOVE; + return false; } - return G_SOURCE_CONTINUE; + return true; } -static gboolean __handle_loader_event(gpointer data) +static bool __handle_loader_event(int fd, io_condition_e cond, void *data) { - loader_context_t *lc = (loader_context_t *) data; - int fd = lc->gpollfd->fd; - int type = lc->type; - int loader_id = lc->loader_id; + candidate_process_context_t *cpc = data; int client_fd; int client_pid; int ret; - candidate_process_context_t *cpc = __find_slot(type, loader_id); - if (cpc == NULL) - return G_SOURCE_REMOVE; + return false; if (!cpc->prepared) { ret = __accept_candidate_process(fd, &client_fd, &client_pid); @@ -1394,12 +1285,13 @@ static gboolean __handle_loader_event(gpointer data) cpc->prepared = true; cpc->send_fd = client_fd; - SECURE_LOGD("Type %d candidate process was connected," \ - " pid: %d", type, cpc->pid); - cpc->source = __poll_fd(client_fd, G_IO_IN | G_IO_HUP, - __handle_loader_client_event, type, - loader_id); - if (cpc->source == 0) + SECURE_LOGD("Type %d candidate process was connected, " + "pid: %d", cpc->type, cpc->pid); + cpc->client_channel = _io_channel_create(client_fd, + IO_IN | IO_HUP, + __handle_loader_client_event, + cpc); + if (!cpc->client_channel) close(client_fd); } } else { @@ -1407,36 +1299,32 @@ static gboolean __handle_loader_event(gpointer data) _E("Refused candidate process connection"); } - return G_SOURCE_CONTINUE; + return true; } -static gboolean __handle_hydra_event(gpointer data) +static bool __handle_hydra_event(int fd, io_condition_e cond, void *data) { - loader_context_t *lc = (loader_context_t *) data; - int fd = lc->gpollfd->fd; - int type = lc->type; - int loader_id = lc->loader_id; + candidate_process_context_t *cpc = data; int client_fd; int client_pid; int ret; - candidate_process_context_t *cpc = __find_slot(type, loader_id); - if (cpc == NULL) - return G_SOURCE_REMOVE; + return false; if (!cpc->prepared) { ret = __accept_candidate_process(fd, &client_fd, &client_pid); if (ret >= 0) { cpc->hydra_fd = client_fd; - SECURE_LOGD("Type %d hydra process was connected," \ - " pid: %d", type, cpc->hydra_pid); + SECURE_LOGD("Type %d hydra process was connected," + " pid: %d", cpc->type, cpc->hydra_pid); - cpc->source = __poll_fd(client_fd, G_IO_IN | G_IO_HUP, - __handle_hydra_client_event, type, - loader_id); - if (cpc->source == 0) + cpc->client_channel = _io_channel_create(client_fd, + IO_IN | IO_HUP, + __handle_hydra_client_event, + cpc); + if (!cpc->client_channel) close(client_fd); } } else { @@ -1444,14 +1332,12 @@ static gboolean __handle_hydra_event(gpointer data) _E("Refused hydra process connection"); } - return G_SOURCE_CONTINUE; + return true; } -static gboolean __handle_sigchild(gpointer data) +static bool __handle_sigchild(int fd, io_condition_e cond, void *data) { candidate_process_context_t *cpc; - loader_context_t *lc = (loader_context_t *) data; - int fd = lc->gpollfd->fd; struct signalfd_siginfo siginfo; ssize_t s; char *appid; @@ -1498,15 +1384,15 @@ static gboolean __handle_sigchild(gpointer data) } } while (s > 0); - return G_SOURCE_CONTINUE; + return true; } -static gboolean __handle_label_monitor(gpointer data) +static bool __handle_label_monitor(int fd, io_condition_e cond, void *data) { candidate_process_context_t *cpc; GList *iter = candidate_slot_list; - _D("__handle_label_monitor()"); + _D("%s()", __FUNCTION__); security_manager_app_labels_monitor_process(label_monitor); while (iter) { @@ -1525,7 +1411,7 @@ static gboolean __handle_label_monitor(gpointer data) iter = g_list_next(iter); } - return G_SOURCE_CONTINUE; + return true; } static float __interpolator(float input, int cpu_max, int cpu_min) @@ -1894,10 +1780,8 @@ static void __update_slot_state(candidate_process_context_t *cpc, int method) } } -static gboolean __handle_launch_event(gpointer data) +static bool __handle_launch_event(int fd, io_condition_e cond, void *data) { - loader_context_t *lc = (loader_context_t *) data; - int fd = lc->gpollfd->fd; bundle *kb = NULL; app_pkt_t *pkt = NULL; appinfo_t *menu_info = NULL; @@ -2075,7 +1959,7 @@ end: traceEnd(TTRACE_TAG_APPLICATION_MANAGER); - return G_SOURCE_CONTINUE; + return true; } static void __destroy_slot(candidate_process_context_t *cpc) @@ -2083,11 +1967,11 @@ static void __destroy_slot(candidate_process_context_t *cpc) if (!cpc) return; - if (cpc->hydra_pollfd) - g_source_remove(cpc->hydra_pollfd); + if (cpc->hydra_channel) + _io_channel_destroy(cpc->hydra_channel); - if (cpc->pollfd) - g_source_remove(cpc->pollfd); + if (cpc->channel) + _io_channel_destroy(cpc->channel); if (cpc->loader_extra) free(cpc->loader_extra); @@ -2138,7 +2022,6 @@ static candidate_process_context_t *__create_slot(int type, int loader_id, cpc->send_fd = -1; cpc->hydra_fd = -1; cpc->last_exec_time = 0; - cpc->source = 0; cpc->timer = 0; cpc->detection_method = detection_method; cpc->timeout_val = timeout_val; @@ -2176,9 +2059,9 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, { candidate_process_context_t *cpc; int fd; - guint pollfd; + io_channel_h channel; int hydra_fd; - guint hydra_pollfd; + io_channel_h hydra_channel; if (__find_slot(type, loader_id) != NULL) return NULL; @@ -2202,15 +2085,14 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, return NULL; } - pollfd = __poll_fd(fd, G_IO_IN, (GSourceFunc)__handle_loader_event, - cpc->type, cpc->loader_id); - if (pollfd == 0) { + channel = _io_channel_create(fd, IO_IN, __handle_loader_event, cpc); + if (!channel) { close(fd); __destroy_slot(cpc); return NULL; } - cpc->pollfd = pollfd; + cpc->channel = channel; if (is_hydra) { hydra_fd = __listen_hydra_process(cpc->type, cpc->loader_id); @@ -2218,22 +2100,19 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, _E("[launchpad] Listening the socket to " \ "the type %d hydra process failed.", cpc->type); - close(fd); __destroy_slot(cpc); return NULL; } - hydra_pollfd = __poll_fd(hydra_fd, G_IO_IN, - (GSourceFunc)__handle_hydra_event, - cpc->type, cpc->loader_id); - if (hydra_pollfd == 0) { + hydra_channel = _io_channel_create(hydra_fd, IO_IN, + __handle_hydra_event, cpc); + if (!hydra_channel) { close(hydra_fd); - close(fd); __destroy_slot(cpc); return NULL; } - cpc->hydra_pollfd = hydra_pollfd; + cpc->hydra_channel = hydra_channel; } @@ -2267,7 +2146,6 @@ static int __remove_slot(int type, int loader_id) static int __init_launchpad_fd(int argc, char **argv) { int fd = -1; - guint pollfd; fd = __launchpad_pre_init(argc, argv); if (fd < 0) { @@ -2275,9 +2153,9 @@ static int __init_launchpad_fd(int argc, char **argv) return -1; } - pollfd = __poll_fd(fd, G_IO_IN, (GSourceFunc)__handle_launch_event, 0, - 0); - if (pollfd == 0) { + __launchpad_channel = _io_channel_create(fd, IO_IN, + __handle_launch_event, NULL); + if (!__launchpad_channel) { close(fd); return -1; } @@ -2288,7 +2166,6 @@ static int __init_launchpad_fd(int argc, char **argv) static int __init_sigchild_fd(void) { int fd = -1; - guint pollfd; fd = _signal_get_sigchld_fd(); if (fd < 0) { @@ -2296,8 +2173,9 @@ static int __init_sigchild_fd(void) return -1; } - pollfd = __poll_fd(fd, G_IO_IN, (GSourceFunc)__handle_sigchild, 0, 0); - if (pollfd == 0) { + __sigchild_channel = _io_channel_create(fd, IO_IN, + __handle_sigchild, NULL); + if (!__sigchild_channel) { close(fd); return -1; } @@ -2309,7 +2187,6 @@ static int __init_label_monitor_fd(void) { int r; int fd = -1; - guint pollfd; r = security_manager_app_labels_monitor_init(&label_monitor); if (r != SECURITY_MANAGER_SUCCESS) @@ -2325,9 +2202,9 @@ static int __init_label_monitor_fd(void) goto err; } - pollfd = __poll_fd(fd, G_IO_IN, - (GSourceFunc)__handle_label_monitor, 0, 0); - if (pollfd == 0) + __label_monitor_channel = _io_channel_create(fd, IO_IN, + __handle_label_monitor, NULL); + if (!__label_monitor_channel) goto err; return 0; @@ -2590,18 +2467,16 @@ static int __register_vconf_events(void) return 0; } -static gboolean __handle_logger(gpointer data) +static bool __handle_logger(int fd, io_condition_e cond, void *data) { - loader_context_t *lc = (loader_context_t *)data; - int fd = lc->gpollfd->fd; - app_pkt_t *pkt = NULL; + app_pkt_t *pkt; struct ucred cr; int clifd = -1; pkt = _accept_recv_pkt_raw(fd, &clifd, &cr); if (!pkt) { _E("Failed to receive the packet"); - return G_SOURCE_CONTINUE; + return true; } if (getuid() != cr.uid) { @@ -2615,20 +2490,18 @@ static gboolean __handle_logger(gpointer data) } SECURE_LOGE("[%d] %s", cr.pid, (const char *)pkt->data); - end: if (clifd != -1) close(clifd); - if (pkt) - free(pkt); - return G_SOURCE_CONTINUE; + free(pkt); + + return true; } static int __init_logger_fd(void) { int fd; - guint pollfd; fd = _create_server_sock(LAUNCHPAD_LOGGER_SOCK); if (fd < 0) { @@ -2636,8 +2509,8 @@ static int __init_logger_fd(void) return -1; } - pollfd = __poll_fd(fd, G_IO_IN, (GSourceFunc)__handle_logger, 0, 0); - if (pollfd == 0) { + __logger_channel = _io_channel_create(fd, IO_IN, __handle_logger, NULL); + if (!__logger_channel) { close(fd); return -1; } @@ -2713,9 +2586,21 @@ static void __after_loop(void) _launcher_info_unload(launcher_info_list); _config_fini(); + if (__label_monitor_channel) + _io_channel_destroy(__label_monitor_channel); + if (label_monitor) security_manager_app_labels_monitor_finish(label_monitor); + if (__logger_channel) + _io_channel_destroy(__logger_channel); + + if (__launchpad_channel) + _io_channel_destroy(__launchpad_channel); + + if (__sigchild_channel) + _io_channel_destroy(__sigchild_channel); + __sequencer_fini(); } diff --git a/src/launchpad_io_channel.c b/src/launchpad_io_channel.c new file mode 100644 index 0000000..f20cb92 --- /dev/null +++ b/src/launchpad_io_channel.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2020 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 +#include +#include +#include + +#include "launchpad_io_channel.h" +#include "log_private.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + +struct io_channel_s { + GIOChannel *io; + guint tag; + int fd; + io_channel_event_cb callback; + void *user_data; +}; + +struct io_condition_s { + io_condition_e io_cond; + GIOCondition g_io_cond; +}; + +static struct io_condition_s __cond_map[] = { + { + .io_cond = IO_IN, + .g_io_cond = G_IO_IN + }, + { + .io_cond = IO_OUT, + .g_io_cond = G_IO_OUT + }, + { + .io_cond = IO_PRI, + .g_io_cond = G_IO_PRI + }, + { + .io_cond = IO_ERR, + .g_io_cond = G_IO_ERR + }, + { + .io_cond = IO_HUP, + .g_io_cond = G_IO_HUP + }, + { + .io_cond = IO_NVAL, + .g_io_cond = G_IO_NVAL, + } +}; + +static io_condition_e __convert_g_io_condition(GIOCondition cond) +{ + io_condition_e condition = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(__cond_map); i++) { + if (__cond_map[i].g_io_cond & cond) + condition |= __cond_map[i].io_cond; + } + + return condition; +} + +static GIOCondition __convert_io_condition(io_condition_e cond) +{ + GIOCondition condition = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(__cond_map); i++) { + if (__cond_map[i].io_cond & cond) + condition |= __cond_map[i].g_io_cond; + } + + return condition; +} + +static gboolean __io_event_cb(GIOChannel *source, GIOCondition condition, + gpointer data) +{ + io_channel_h channel = (io_channel_h)data; + io_condition_e cond = __convert_g_io_condition(condition); + + if (!channel->callback(channel->fd, cond, channel->user_data)) + return G_SOURCE_REMOVE; + + return G_SOURCE_CONTINUE; +} + +io_channel_h _io_channel_create(int fd, io_condition_e cond, + io_channel_event_cb callback, void *user_data) +{ + struct io_channel_s *channel; + + if (fd < 3 || !callback) { + _E("Invalid parameter"); + return NULL; + } + + channel = calloc(1, sizeof(struct io_channel_s)); + if (!channel) { + _E("Out of memory"); + return NULL; + } + + channel->io = g_io_channel_unix_new(fd); + if (!channel->io) { + _E("Failed to create GIOChannel"); + _io_channel_destroy(channel); + return NULL; + } + + channel->tag = g_io_add_watch(channel->io, __convert_io_condition(cond), + __io_event_cb, channel); + if (!channel->tag) { + _E("Failed to add GIO watch"); + _io_channel_destroy(channel); + return NULL; + } + + channel->fd = fd; + channel->callback = callback; + channel->user_data = user_data; + + return channel; +} + +void _io_channel_destroy(io_channel_h channel) +{ + if (!channel) + return; + + if (channel->tag) + g_source_remove(channel->tag); + + if (channel->io) + g_io_channel_unref(channel->io); + + if (channel->fd) + close(channel->fd); + + free(channel); +} diff --git a/src/log_private.h b/src/log_private.h index f214b78..c3b0662 100644 --- a/src/log_private.h +++ b/src/log_private.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2019 - 2020 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. @@ -24,9 +24,24 @@ #endif #define LOG_TAG "LAUNCHPAD" +#ifdef _E +#undef _E +#endif #define _E(fmt, arg...) LOGE(fmt, ##arg) + +#ifdef _D +#undef _D +#endif #define _D(fmt, arg...) LOGD(fmt, ##arg) + +#ifdef _W +#undef _W +#endif #define _W(fmt, arg...) LOGW(fmt, ##arg) + +#ifdef _I +#undef _I +#endif #define _I(fmt, arg...) LOGI(fmt, ##arg) #endif /* __LOG_PRIVATE_H__ */ -- 2.7.4 From 580f80d74fcb4141abecfaa49e412dde51e2222f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 30 Jan 2020 07:39:28 +0900 Subject: [PATCH 06/16] Release version 0.10.5 Changes: - Fix static anlysis issue - Fix fd event handling Change-Id: I9e0900116218b2a46bd3bc7ea4dbf43d50b9181e Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 0077851..b89d29a 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.10.4 +Version: 0.10.5 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 643f4aea6eb710e2430b61b3f6e95228cd69a7f3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jan 2020 15:02:40 +0900 Subject: [PATCH 07/16] Support launching service app with dynamic loader Change-Id: If385128a84a89e2e75d038ef5abe7ab6181c7402 Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/launchpad.c b/src/launchpad.c index b847c2c..ecd3f61 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -1890,7 +1890,15 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) if (menu_info->comp_type && strcmp(menu_info->comp_type, "svcapp") == 0) { - loader_id = PAD_LOADER_ID_DIRECT; + loader_id = __get_loader_id(kb); + if (loader_id > PAD_LOADER_ID_DYNAMIC_BASE) { + type = LAUNCHPAD_TYPE_DYNAMIC; + cpc = __find_slot(type, loader_id); + if (cpc && !cpc->prepared) + cpc = NULL; + } else { + loader_id = PAD_LOADER_ID_DIRECT; + } } else if (menu_info->comp_type && menu_info->app_type && strcmp(menu_info->comp_type, "widgetapp") == 0 && strcmp(menu_info->app_type, "webapp") == 0) { -- 2.7.4 From 1b870b7bc75c1f616d1058d2f9e06fab01b66cf5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 31 Jan 2020 08:50:07 +0900 Subject: [PATCH 08/16] Release version 0.11.0 Changes: - Support launching service app with dynamic loader Change-Id: I568521232e4d1fcaf6797f67bd40f961bbdc4b79 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index b89d29a..76464ea 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.10.5 +Version: 0.11.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 0c3dace9197251b325a77a22dc0d9726b168dc0d Mon Sep 17 00:00:00 2001 From: hyunho Date: Mon, 3 Feb 2020 11:29:49 +0900 Subject: [PATCH 09/16] Add a plugin for app-defined loader Change-Id: I73f527421a98bc619266171553280acd9029c61d Signed-off-by: hyunho --- CMakeLists.txt | 3 + packaging/launchpad.spec | 4 + parser/CMakeLists.txt | 39 ++++++ parser/common.hh | 25 ++++ parser/launchpad_parser_plugin.cc | 146 +++++++++++++++++++++ parser/launchpad_parser_plugin.hh | 45 +++++++ parser/launchpad_parser_plugin_pkgmgr_interface.cc | 68 ++++++++++ parser/launchpad_plugins.txt | 1 + parser/loader_info.cc | 44 +++++++ parser/loader_info.hh | 43 ++++++ parser/log_private.hh | 47 +++++++ 11 files changed, 465 insertions(+) create mode 100644 parser/CMakeLists.txt create mode 100644 parser/common.hh create mode 100644 parser/launchpad_parser_plugin.cc create mode 100644 parser/launchpad_parser_plugin.hh create mode 100644 parser/launchpad_parser_plugin_pkgmgr_interface.cc create mode 100644 parser/launchpad_plugins.txt create mode 100644 parser/loader_info.cc create mode 100644 parser/loader_info.hh create mode 100644 parser/log_private.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 5239b49..20d8f0f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,3 +203,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad_hydra.h DESTINATION incl CONFIGURE_FILE(liblaunchpad-hydra.pc.in liblaunchpad-hydra.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad-hydra.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +# parser +ADD_SUBDIRECTORY(parser) \ No newline at end of file diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 76464ea..babb8b4 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -26,6 +26,7 @@ BuildRequires: pkgconfig(libcap) BuildRequires: pkgconfig(tanchor) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(iniparser) +BuildRequires: pkgconfig(libxml-2.0) Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl @@ -119,6 +120,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %install rm -rf %{buildroot} + %make_install mkdir -p %{buildroot}%{_unitdir_user}/basic.target.wants mkdir -p %{buildroot}%{_unitdir_user}/sockets.target.wants @@ -139,6 +141,8 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %{_unitdir_user}/basic.target.wants/launchpad-process-pool.service %{_bindir}/launchpad-process-pool %{_prefix}/share/aul/launchpad.conf +%{_sysconfdir}/package-manager/parserlib/liblaunchpad-parser.so +%{_datadir}/parser-plugins/* %files devel %{_includedir}/launchpad/*.h diff --git a/parser/CMakeLists.txt b/parser/CMakeLists.txt new file mode 100644 index 0000000..f98579f --- /dev/null +++ b/parser/CMakeLists.txt @@ -0,0 +1,39 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(launchpad-parser CXX) + +INCLUDE(FindPkgConfig) +pkg_check_modules(PKGS REQUIRED + dlog + libxml-2.0 +) + +FOREACH(FLAGS ${PKGS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${FLAGS}") +ENDFOREACH(FLAGS) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -std=c++11") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +ADD_LIBRARY(${PROJECT_NAME} SHARED + launchpad_parser_plugin.cc + loader_info.cc + launchpad_parser_plugin_pkgmgr_interface.cc +) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) + +SET(PLUGINS_LIST_FILE_NAME launchpad_plugins.txt) +SET(PLUGINS_LIST_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGINS_LIST_FILE_NAME}) + +SET(PLUGINS_LIST_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/share/parser-plugins) + +ADD_DEFINITIONS("-DPLUGINS_LIST_INSTALL_PATH=\"${PLUGINS_LIST_INSTALL_PATH}\"") + +INSTALL(FILES ${PLUGINS_LIST_FILE_PATH} DESTINATION ${PLUGINS_LIST_INSTALL_PATH}/) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib) diff --git a/parser/common.hh b/parser/common.hh new file mode 100644 index 0000000..910caa5 --- /dev/null +++ b/parser/common.hh @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_ + +#ifdef EXPORT_API +#undef EXPORT_API +#endif +#define EXPORT_API __attribute__((visibility("default"))) + +#endif // LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_ diff --git a/parser/launchpad_parser_plugin.cc b/parser/launchpad_parser_plugin.cc new file mode 100644 index 0000000..a880a6e --- /dev/null +++ b/parser/launchpad_parser_plugin.cc @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include +#include + +#include +#include + +#include "launchpad_parser_plugin.hh" +#include "log_private.hh" + +#define LOADERS_DIRECTORY_PATH "/opt/share/loaders/" + +using namespace std; +namespace launchpad_parser_plugin { + +string LaunchpadParser::GetFilePath(string id) { + return "/opt/share/loaders/" + id + ".loader"; +} + +int LaunchpadParser::WriteToFile(string pkgid) { + if (access(LOADERS_DIRECTORY_PATH, F_OK) != 0) + mkdir(LOADERS_DIRECTORY_PATH, 0644); + + LOGI("write to file (%d)", loader_list_.size()); + for (auto& i : loader_list_) { + std::ofstream out_file; + LOGI("write ID (%s)", i->GetId().c_str()); + out_file.open(GetFilePath(i->GetId())); + out_file << "[LOADER]\n"; + out_file << "NAME " + i->GetId() + "\n"; + out_file << "EXE /usr/bin/launchpad-loader \n"; + out_file << "APP_TYPE capp|c++app \n"; + out_file << "DETECTION_METHOD TIMEOUT|VISIBILITY \n"; + out_file << "TIMEOUT 5000 \n"; + out_file << "TTL " + to_string(i->GetTimeToLive()) + "\n"; + out_file << "OWNER " + pkgid + "\n"; + out_file << "EXTRA loader_type common-loader \n"; + if (i->GetPreloadLib().size() > 0) { + out_file << "EXTRA_ARRAY preload \n"; + for (auto& lib : i->GetPreloadLib()) { + out_file << "EXTRA_ARRAY_VAL /usr/lib/" + lib + "\n"; + } + } + out_file.close(); + } + return 0; +} + +bool LaunchpadParser::IsValidId(string loader_id, string pkgid) { + ifstream in_file(GetFilePath(loader_id).c_str()); + if (!in_file.good()) + return true; + string key, val; + in_file >> key; + while (in_file >> key >> val) { + if (key == "OWNER") { + LOGI("key (%s), val (%s)", key.c_str(), val.c_str()); + if (val == pkgid) + return true; + } + } + return false; +} + +int LaunchpadParser::Install(xmlDocPtr doc, string pkgid) { + xmlNode* root = xmlDocGetRootElement(doc); + for (xmlNode* node = root->children; node; node = node->next) { + if (!node->name) + continue; + + string name = string((char*)node->name); + if (name != "provides-appdefined-loader") + continue; + + xmlChar* val = xmlGetProp(node, (const xmlChar *)"id"); + shared_ptr info = make_shared(string((char*)val)); + if (!IsValidId(info->GetId(), pkgid)) + return -1; + + xmlChar* ttl = xmlGetProp(node, (const xmlChar *)"time-to-live"); + if (ttl) + info->SetTimeToLive(stoi(string((char*)ttl))); + + for (xmlNode* iter = node->children; iter; iter = iter->next) { + if (!iter->name) + continue; + string child_name = string((char*)iter->name); + if (child_name == "preload-library") { + xmlChar* libname = xmlGetProp(iter, (const xmlChar *)"name"); + if (!libname) + continue; + info->AddPreloadLib(string((char*)libname)); + } + } + loader_list_.push_back(info); + } + WriteToFile(pkgid); + + return 0; +} + +int LaunchpadParser::Upgrade(xmlDocPtr doc, std::string pkgid) { + if (UnInstall(doc, pkgid) != 0) + return -1; + + return Install(doc, pkgid); +} + +int LaunchpadParser::UnInstall(xmlDocPtr doc, std::string pkgid) { + xmlNode* root = xmlDocGetRootElement(doc); + for (xmlNode* node = root->children; node; node = node->next) { + if (!node->name) + continue; + + string name = string((char*)node->name); + if (name != "provides-appdefined-loader") + continue; + + xmlChar* val = xmlGetProp(node, (const xmlChar *)"id"); + if (!val) + return -1; + + string id = string((char*)val); + if (!IsValidId(id, pkgid)) + return -1; + remove(GetFilePath(id).c_str()); + } + return 0; +} + +} // namspace launchpad_parser_plugin diff --git a/parser/launchpad_parser_plugin.hh b/parser/launchpad_parser_plugin.hh new file mode 100644 index 0000000..091e50c --- /dev/null +++ b/parser/launchpad_parser_plugin.hh @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_ + +#include +#include +#include +#include + +#include "loader_info.hh" + +namespace launchpad_parser_plugin { + +class LaunchpadParser { + public: + std::string GetFilePath(std::string id); + int WriteToFile(std::string pkgid); + int Install(xmlDocPtr doc, std::string pkgid); + int Upgrade(xmlDocPtr doc, std::string pkgid); + int UnInstall(xmlDocPtr doc, std::string pkgid); + bool IsValidId(std::string loader_id, std::string pkgid); + + private: + std::list> loader_list_; +}; + +} // namespace launchpad_parser_plugin + +#endif // LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_ + diff --git a/parser/launchpad_parser_plugin_pkgmgr_interface.cc b/parser/launchpad_parser_plugin_pkgmgr_interface.cc new file mode 100644 index 0000000..34d16ba --- /dev/null +++ b/parser/launchpad_parser_plugin_pkgmgr_interface.cc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019 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. + */ + +#include + +#include "launchpad_parser_plugin.hh" +#include "log_private.hh" +#include "common.hh" + +using namespace launchpad_parser_plugin; + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char *package) +{ + LaunchpadParser parser; + LOGI("install"); + return parser.Install(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char *package) +{ + LOGI("uninstall"); + LaunchpadParser parser; + return parser.UnInstall(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char *package) +{ + LOGI("upgrade"); + LaunchpadParser parser; + return parser.Upgrade(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc, + const char *package) +{ + LOGW("recover install"); + LaunchpadParser parser; + return parser.UnInstall(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL(xmlDocPtr doc, + const char *package) +{ + LOGW("recover uninstall"); + LaunchpadParser parser; + return parser.UnInstall(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc, + const char *package) +{ + LOGW("recover upgrade"); + LaunchpadParser parser; + return parser.Upgrade(doc, package); +} diff --git a/parser/launchpad_plugins.txt b/parser/launchpad_plugins.txt new file mode 100644 index 0000000..75a63d0 --- /dev/null +++ b/parser/launchpad_plugins.txt @@ -0,0 +1 @@ +type="tag";name="provides-appdefined-loader";path="/etc/package-manager/parserlib/liblaunchpad-parser.so";vitalness="true" diff --git a/parser/loader_info.cc b/parser/loader_info.cc new file mode 100644 index 0000000..1f6a2f5 --- /dev/null +++ b/parser/loader_info.cc @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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. + */ +#include "loader_info.hh" + +using namespace std; +namespace launchpad_parser_plugin { + +LoaderInfo::LoaderInfo(std::string id) : id_(id), time_to_live_(0) { +} + +string LoaderInfo::GetId() { + return id_; +} + +int LoaderInfo::GetTimeToLive() { + return time_to_live_; +} + +void LoaderInfo::SetTimeToLive(int time) { + time_to_live_ = time; +} + +list LoaderInfo::GetPreloadLib() { + return preload_lib_list_; +} + +void LoaderInfo::AddPreloadLib(string lib_name) { + preload_lib_list_.push_back(lib_name); +} + +} // namspace launchpad_parser_plugin diff --git a/parser/loader_info.hh b/parser/loader_info.hh new file mode 100644 index 0000000..c4ab4f3 --- /dev/null +++ b/parser/loader_info.hh @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_ + +#include +#include + +namespace launchpad_parser_plugin { + +class LoaderInfo { + public: + LoaderInfo(std::string id); + std::string GetId(); + int GetTimeToLive(); + void SetTimeToLive(int time); + std::list GetPreloadLib(); + void AddPreloadLib(std::string lib_name); + + private: + std::string id_; + int time_to_live_; + std::list preload_lib_list_; +}; + +} // namespace launchpad_parser_plugin + +#endif // LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_ + diff --git a/parser/log_private.hh b/parser/log_private.hh new file mode 100644 index 0000000..80e244b --- /dev/null +++ b/parser/log_private.hh @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 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. + */ + +#ifndef LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_ + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "LAUNCHPAD_PARSER_PLUGIN" + +#ifdef _E +#undef _E +#endif +#define _E(fmt, arg...) LOGE(fmt, ##arg) + +#ifdef _D +#undef _D +#endif +#define _D(fmt, arg...) LOGD(fmt, ##arg) + +#ifdef _W +#undef _W +#endif +#define _W(fmt, arg...) LOGW(fmt, ##arg) + +#ifdef _I +#undef _I +#endif +#define _I(fmt, arg...) LOGI(fmt, ##arg) + +#endif /* LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_ */ -- 2.7.4 From f345f214eb2a04895dd91479e89c69a440ca7592 Mon Sep 17 00:00:00 2001 From: Jusung Son Date: Fri, 7 Feb 2020 09:10:57 +0900 Subject: [PATCH 10/16] Add app-defined loader Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/224466/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/224634/ - https://review.tizen.org/gerrit/#/c/platform/core/api/app-control/+/224798/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/launchpad/+/224161/ Change-Id: I66ea0abec98fd387e91cf67a7f5db94e5d0234d0 Signed-off-by: Jusung Son --- CMakeLists.txt | 1 + inc/launchpad_common.h | 1 + inc/launchpad_inotify.h | 34 +++++++++ inc/loader_info.h | 6 +- inc/preexec.h | 0 src/launchpad.c | 152 +++++++++++++++++++++++++++++++++++++- src/launchpad_inotify.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++ src/loader_info.c | 55 +++++++++++++- 8 files changed, 437 insertions(+), 3 deletions(-) mode change 100755 => 100644 CMakeLists.txt create mode 100644 inc/launchpad_inotify.h mode change 100755 => 100644 inc/preexec.h mode change 100755 => 100644 src/launchpad.c create mode 100644 src/launchpad_inotify.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 20d8f0f..6197582 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,6 +147,7 @@ SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES src/launchpad_signal.c src/launchpad_config.c src/launchpad_io_channel.c + src/launchpad_inotify.c ) ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES}) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index c5859e2..dc60559 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -46,6 +46,7 @@ #define PAD_CMD_DEMAND 14 #define PAD_CMD_PING 15 #define PAD_CMD_UPDATE_APP_TYPE 16 +#define PAD_CMD_PREPARE_APP_DEFINED_LOADER 17 #define LAUNCHPAD_LAUNCH_SIGNAL 83 #define LAUNCHPAD_DEAD_SIGNAL 61 diff --git a/inc/launchpad_inotify.h b/inc/launchpad_inotify.h new file mode 100644 index 0000000..4db903e --- /dev/null +++ b/inc/launchpad_inotify.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 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 +#include + +typedef struct inotify_watch_info_s *inotify_watch_info_h; + +typedef bool (*inotify_watch_cb)(const char *event_name, uint32_t mask, + void *data); + +int _inotify_add_watch(const char *path, uint32_t mask, + inotify_watch_cb callback, void *data); + +void _inotify_rm_watch(inotify_watch_info_h handle); + +int _inotify_init(void); + +void _inotify_fini(void); diff --git a/inc/loader_info.h b/inc/loader_info.h index 8714198..2e703b5 100644 --- a/inc/loader_info.h +++ b/inc/loader_info.h @@ -57,10 +57,14 @@ typedef struct _loader_info { typedef void (*loader_info_foreach_cb)(loader_info_t *info, void *data); -GList *_loader_info_load(const char *path); +GList *_loader_info_load_dir(const char *path); +GList *_loader_info_load_file(GList *list, const char *path); +GList *_loader_info_unload(GList *list, const char *loader_name); void _loader_info_dispose(GList *info); int _loader_info_find_type(GList *info, const char *app_type, bool hwacc); int _loader_info_find_type_by_loader_name(GList *info, const char *loader_name); +const char* _loader_info_find_loader_path_by_loader_name(GList *info, const char *loader_name); +const loader_info_t* _loader_info_find_loader_by_loader_name(GList *info, const char *loader_name); int *_loader_get_alternative_types(GList *info, int type, int *len); int _loader_info_foreach(GList *info, loader_info_foreach_cb callback, void *data); diff --git a/inc/preexec.h b/inc/preexec.h old mode 100755 new mode 100644 diff --git a/src/launchpad.c b/src/launchpad.c old mode 100755 new mode 100644 index ecd3f61..af409f5 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -49,6 +49,7 @@ #include "launchpad_types.h" #include "loader_info.h" #include "perf.h" +#include "launchpad_inotify.h" #define AUL_PR_NAME 16 #define EXEC_CANDIDATE_EXPIRED 5 @@ -60,6 +61,11 @@ #define LAUNCHPAD_LOGGER_SOCK ".launchpad-logger-sock" #define LOADER_PATH_DEFAULT "/usr/bin/launchpad-loader" #define LOADER_INFO_PATH "/usr/share/aul" +#define OPT_SHARE_PATH "/opt/share" +#define LOADERS_PATH "loaders" +#define APP_DEFINED_LOADER_INFO_PATH OPT_SHARE_PATH "/" LOADERS_PATH +#define COMMON_LOADER_NAME "common-loader1" + #define LAUNCHER_INFO_PATH LOADER_INFO_PATH #define REGULAR_UID_MIN 5000 #define PAD_ERR_FAILED -1 @@ -142,6 +148,7 @@ struct app_info { static int __sys_hwacc; static GList *loader_info_list; +static GList *app_defined_loader_info_list; static int user_slot_offset; static GList *candidate_slot_list; static app_labels_monitor *label_monitor; @@ -171,6 +178,7 @@ static int __add_idle_checker(int detection_method, GList *cur); static void __dispose_candidate_process(candidate_process_context_t *cpc); static bool __is_low_memory(void); static void __update_slot_state(candidate_process_context_t *cpc, int method); +static void __init_app_defined_loader_monitor(void); static gboolean __handle_queuing_slots(gpointer data) { @@ -1588,6 +1596,60 @@ static int __dispatch_cmd_add_loader(bundle *kb) return -1; } +static int __dispatch_cmd_add_app_defined_loader(bundle *kb) +{ + const char *loader_name; + const char *loader_path; + int lid, len; + candidate_process_context_t *cpc; + const loader_info_t *info; + bundle_raw *extra; + + _W("cmd add defined loader"); + loader_name = bundle_get_val(kb, AUL_K_LOADER_NAME); + + if (loader_name == NULL) { + _E("loader_name is NULL"); + return -1; + } + + loader_path = _loader_info_find_loader_path_by_loader_name( + loader_info_list, COMMON_LOADER_NAME); + info = _loader_info_find_loader_by_loader_name( + app_defined_loader_info_list, loader_name); + + if (loader_path == NULL || info == NULL || info->extra == NULL) { + _E("loader_name %s, loader_path %d, info %d", + loader_name, loader_path != NULL, info != NULL); + return -1; + } + + bundle_encode(info->extra, &extra, &len); + + lid = __make_loader_id(); + cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, 0, + loader_path, (const char *)extra, + METHOD_TIMEOUT | METHOD_VISIBILITY, + METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, + METHOD_TTL | METHOD_OUT_OF_MEMORY, + info->ttl, + 2000, + DEFAULT_CPU_THRESHOLD_MAX, + DEFAULT_CPU_THRESHOLD_MIN, + false, + true, 0); + + if (cpc == NULL) { + _E("cpc is NULL"); + bundle_free_encoded_rawdata(&extra); + return -1; + } + + __prepare_candidate_process(LAUNCHPAD_TYPE_DYNAMIC, lid); + + return lid; +} + static int __dispatch_cmd_remove_loader(bundle *kb) { const char *id = bundle_get_val(kb, AUL_K_LOADER_ID); @@ -1841,6 +1903,11 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) __real_send(clifd, ret); clifd = -1; goto end; + case PAD_CMD_PREPARE_APP_DEFINED_LOADER: + ret = __dispatch_cmd_add_app_defined_loader(kb); + __real_send(clifd, ret); + clifd = -1; + goto end; case PAD_CMD_DEMAND: ret = __dispatch_cmd_hint(kb, METHOD_DEMAND); __real_send(clifd, ret); @@ -2191,6 +2258,77 @@ static int __init_sigchild_fd(void) return 0; } +static bool __on_directory_create(const char *event_name, uint32_t mask, + void *user_data) +{ + if (!event_name) { + _E("Invalid parameter"); + return true; + } + + if (!strcmp(event_name, LOADERS_PATH)) { + __init_app_defined_loader_monitor(); + return false; + } + + return true; +} + +static bool __on_file_change(const char *event_name, uint32_t mask, + void *user_data) +{ + char buf[PATH_MAX]; + char *ext; + if (!event_name) { + _E("Invalid parameter"); + return true; + } + + ext = strrchr(event_name, '.'); + if (ext == NULL || strcmp(ext, ".loader") != 0) + return true; + + if (mask & IN_CREATE) { + snprintf(buf, sizeof(buf), "%s/%s", + APP_DEFINED_LOADER_INFO_PATH, event_name); + app_defined_loader_info_list = _loader_info_load_file( + app_defined_loader_info_list, buf); + } else if (mask & IN_DELETE) { + snprintf(buf, ext - event_name, "%s", event_name); + app_defined_loader_info_list = _loader_info_unload( + app_defined_loader_info_list, buf); + } + + return true; +} + +static void __init_app_defined_loader_monitor(void) +{ + int ret; + + ret = access(APP_DEFINED_LOADER_INFO_PATH, F_OK); + if (ret < 0) { + _W("Failed to access %s", APP_DEFINED_LOADER_INFO_PATH); + ret = _inotify_add_watch(OPT_SHARE_PATH, + IN_CREATE, __on_directory_create, NULL); + if (ret != 0) + _E("Failed to add inotify watch %s", OPT_SHARE_PATH); + + return; + } + + ret = _inotify_add_watch(APP_DEFINED_LOADER_INFO_PATH, + IN_CREATE | IN_DELETE, __on_file_change, NULL); + + if (ret < 0) { + _E("Failed to add inotify watch %s", + APP_DEFINED_LOADER_INFO_PATH); + } + + return; + +} + static int __init_label_monitor_fd(void) { int r; @@ -2331,7 +2469,7 @@ static int __add_default_slots(void) if (loader_info_list) _loader_info_dispose(loader_info_list); - loader_info_list = _loader_info_load(LOADER_INFO_PATH); + loader_info_list = _loader_info_load_dir(LOADER_INFO_PATH); if (loader_info_list == NULL) return -1; @@ -2342,6 +2480,11 @@ static int __add_default_slots(void) return 0; } +static void __add_app_defined_loaders(void) +{ + app_defined_loader_info_list = _loader_info_load_dir(APP_DEFINED_LOADER_INFO_PATH); +} + static bool __is_low_memory(void) { if (__memory_status_low >= MEMORY_STATUS_LOW) @@ -2562,9 +2705,13 @@ static int __before_loop(int argc, char **argv) if (ret != 0) _W("Failed to initialize config"); + _inotify_init(); + __add_default_slots(); launcher_info_list = _launcher_info_load(LAUNCHER_INFO_PATH); + __add_app_defined_loaders(); + ret = _send_cmd_to_amd(LAUNCHPAD_LAUNCH_SIGNAL); if (ret < 0) _W("Failed to send cmd(%d) to amd", LAUNCHPAD_LAUNCH_SIGNAL); @@ -2577,6 +2724,7 @@ static int __before_loop(int argc, char **argv) } __register_vconf_events(); + __init_app_defined_loader_monitor(); return 0; } @@ -2593,6 +2741,8 @@ static void __after_loop(void) _debug_fini(); _launcher_info_unload(launcher_info_list); _config_fini(); + _inotify_fini(); + _loader_info_dispose(app_defined_loader_info_list); if (__label_monitor_channel) _io_channel_destroy(__label_monitor_channel); diff --git a/src/launchpad_inotify.c b/src/launchpad_inotify.c new file mode 100644 index 0000000..9130fa2 --- /dev/null +++ b/src/launchpad_inotify.c @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2020 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 +#include +#include +#include +#include +#include + +#include "launchpad_inotify.h" +#include "log_private.h" + +struct inotify_watch_info_s { + int fd; + int wd; + GIOChannel *io; + guint tag; + uint32_t mask; + inotify_watch_cb cb; + void *data; +}; + +static GList *__watch_list; + +static gboolean __inotify_cb(GIOChannel *source, GIOCondition condition, + gpointer data) +{ +#define ALIGN_INOTIFY_EVENT \ + __attribute__ ((aligned(__alignof__(struct inotify_event)))) +#define SIZE_INOTIFY_EVENT (sizeof(struct inotify_event)) + int fd = g_io_channel_unix_get_fd(source); + char buf[4096] ALIGN_INOTIFY_EVENT; + const struct inotify_event *event; + struct inotify_watch_info_s *info = data; + ssize_t len; + char *ptr; + char *nptr; + + while ((len = read(fd, buf, sizeof(buf))) > 0) { + for (ptr = buf; ptr < buf + len; + ptr += sizeof(struct inotify_event) + event->len) { + if ((ptr + SIZE_INOTIFY_EVENT) > (buf + len)) + break; + + event = (const struct inotify_event *)ptr; + nptr = ptr + sizeof(struct inotify_event) + event->len; + if (nptr > buf + len) + break; + + if (event->mask & info->mask) { + if (!info->cb(event->name, event->mask, + info->data)) { + _inotify_rm_watch(info); + return G_SOURCE_CONTINUE; + } + } + } + } + + return G_SOURCE_CONTINUE; +} + +static void __destroy_inotify_watch_info(gpointer data) +{ + struct inotify_watch_info_s *info = (struct inotify_watch_info_s *)data; + + if (info == NULL) + return; + + if (info->tag > 0) + g_source_remove(info->tag); + + if (info->io) + g_io_channel_unref(info->io); + + if (info->wd > 0) + inotify_rm_watch(info->fd, info->wd); + + if (info->fd > 0) + close(info->fd); + + free(info); +} + +static struct inotify_watch_info_s *__create_inotify_watch_info( + const char *path, uint32_t mask, inotify_watch_cb cb, + void *data) +{ + GIOCondition cond = G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP; + struct inotify_watch_info_s *info; + + info = calloc(1, sizeof(struct inotify_watch_info_s)); + if (info == NULL) { + _E("Out of memory"); + return NULL; + } + + info->fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); + if (info->fd < 0) { + _E("inotify_init1() is failed. errno(%d)", errno); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->wd = inotify_add_watch(info->fd, path, mask); + if (info->wd < 0) { + _E("inotify_add_watch() is failed. path(%s), errno(%d)", + path, errno); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->io = g_io_channel_unix_new(info->fd); + if (!info->io) { + _E("g_io_channel_unix_new() is failed"); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->tag = g_io_add_watch(info->io, cond, + __inotify_cb, info); + if (!info->tag) { + _E("g_io_add_watch() is failed"); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->mask = mask; + info->cb = cb; + info->data = data; + + return info; +} + +int _inotify_add_watch(const char *path, uint32_t mask, + inotify_watch_cb callback, void *data) +{ + struct inotify_watch_info_s *info; + + if (path == NULL || callback == NULL) { + _E("Invalid parameter"); + return -1; + } + + info = __create_inotify_watch_info(path, mask, callback, data); + if (info == NULL) + return -1; + + __watch_list = g_list_append(__watch_list, info); + + return 0; +} + +void _inotify_rm_watch(inotify_watch_info_h handle) +{ + if (handle == NULL) + return; + + __watch_list = g_list_remove(__watch_list, handle); + __destroy_inotify_watch_info(handle); +} + +int _inotify_init(void) +{ + _D("inotify init"); + + return 0; +} + +void _inotify_fini(void) +{ + _D("inotify fini"); + + if (__watch_list) + g_list_free_full(__watch_list, __destroy_inotify_watch_info); +} diff --git a/src/loader_info.c b/src/loader_info.c index 39e9f21..375c1fd 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -53,6 +53,9 @@ #define VAL_METHOD_TTL "TTL" #define VAL_METHOD_OUT_OF_MEMORY "OUT_OF_MEMORY" +static int __comp_name(gconstpointer a, gconstpointer b); +static void __free_info(gpointer data); + static loader_info_t *__create_loader_info() { loader_info_t *info; @@ -320,7 +323,7 @@ static GList *__parse_file(GList *list, const char *path) return list; } -GList *_loader_info_load(const char *path) +GList *_loader_info_load_dir(const char *path) { DIR *dir_info; struct dirent *entry = NULL; @@ -346,6 +349,56 @@ GList *_loader_info_load(const char *path) return list; } +GList *_loader_info_load_file(GList *list, const char *path) +{ + return __parse_file(list, path); +} + +GList *_loader_info_unload(GList *list, const char *loader_name) +{ + GList *cur; + loader_info_t *info; + + cur = g_list_find_custom(list, loader_name, __comp_name); + if (cur == NULL) + return list; + + info = cur->data; + + list = g_list_remove(list, info); + __free_info(info); + + return list; +} + +const char* _loader_info_find_loader_path_by_loader_name(GList *list, const char *loader_name) +{ + GList *cur; + loader_info_t *info; + + cur = g_list_find_custom(list, loader_name, __comp_name); + if (cur == NULL) + return NULL; + + info = cur->data; + + return info->exe; +} + +const loader_info_t* _loader_info_find_loader_by_loader_name(GList *list, const char *loader_name) +{ + GList *cur; + loader_info_t *info; + + cur = g_list_find_custom(list, loader_name, __comp_name); + if (cur == NULL) + return NULL; + + info = cur->data; + + return info; +} + static void __free_info(gpointer data) { loader_info_t *info; -- 2.7.4 From 69414338722e64a6df6fe8ab4edc4c86a56bde85 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 18 Feb 2020 10:47:14 +0900 Subject: [PATCH 11/16] Fix return values of __dispatch_cmd_add_app_defined_loader() Change-Id: Ia7504d0a4b4078cc932af2094dddc174d82df123 Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index af409f5..b1a3ef1 100644 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -15,6 +15,7 @@ */ #define _GNU_SOURCE +#include #include #include #include @@ -1610,18 +1611,19 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) if (loader_name == NULL) { _E("loader_name is NULL"); - return -1; + return -EINVAL; } + /* TODO: use app-defined-loader */ loader_path = _loader_info_find_loader_path_by_loader_name( loader_info_list, COMMON_LOADER_NAME); - info = _loader_info_find_loader_by_loader_name( - app_defined_loader_info_list, loader_name); + info = _loader_info_find_loader_by_loader_name( + app_defined_loader_info_list, loader_name); if (loader_path == NULL || info == NULL || info->extra == NULL) { _E("loader_name %s, loader_path %d, info %d", loader_name, loader_path != NULL, info != NULL); - return -1; + return -EINVAL; } bundle_encode(info->extra, &extra, &len); @@ -1638,11 +1640,10 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) DEFAULT_CPU_THRESHOLD_MIN, false, true, 0); - if (cpc == NULL) { _E("cpc is NULL"); bundle_free_encoded_rawdata(&extra); - return -1; + return -ENOMEM; } __prepare_candidate_process(LAUNCHPAD_TYPE_DYNAMIC, lid); -- 2.7.4 From 878706d59193174a36be0085aa7205877790327a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 18 Feb 2020 17:22:08 +0900 Subject: [PATCH 12/16] Separate codes into directories Change-Id: I497213884beecebe3d532f4d4ece55dbcf5fd329 Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 197 +------------------ .../launchpad-loader.manifest | 0 launchpad.manifest => packaging/launchpad.manifest | 0 packaging/launchpad.spec | 7 +- .../liblaunchpad.manifest | 0 src/CMakeLists.txt | 9 + {inc => src/common/inc}/key.h | 0 {inc => src/common/inc}/launchpad_common.h | 0 {inc => src/common/inc}/launchpad_types.h | 7 + src/{ => common/inc}/log_private.h | 0 {inc => src/common/inc}/perf.h | 0 {inc => src/common/inc}/preexec.h | 0 src/{ => common/src}/launchpad_common.c | 0 src/hydra/CMakeLists.txt | 41 ++++ {inc => src/hydra/inc}/launchpad_hydra.h | 0 .../hydra/pkgconfig/liblaunchpad-hydra.pc.in | 0 src/{ => hydra/src}/launchpad_hydra.c | 0 src/launchpad/CMakeLists.txt | 71 +++++++ {conf => src/launchpad/conf}/launchpad.conf.in | 0 {inc => src/launchpad/inc}/debugger_info.h | 0 {inc => src/launchpad/inc}/launcher_info.h | 0 {inc => src/launchpad/inc}/launchpad_config.h | 0 {inc => src/launchpad/inc}/launchpad_debug.h | 0 {inc => src/launchpad/inc}/launchpad_inotify.h | 0 {inc => src/launchpad/inc}/launchpad_io_channel.h | 0 {inc => src/launchpad/inc}/launchpad_signal.h | 0 {inc => src/launchpad/inc}/loader_info.h | 0 src/launchpad/src/CMakeLists.txt | 209 +++++++++++++++++++++ src/{ => launchpad/src}/debugger_info.c | 0 src/{ => launchpad/src}/launcher_info.c | 0 src/{ => launchpad/src}/launchpad.c | 30 +-- src/{ => launchpad/src}/launchpad_config.c | 0 src/{ => launchpad/src}/launchpad_debug.c | 0 src/{ => launchpad/src}/launchpad_inotify.c | 0 src/{ => launchpad/src}/launchpad_io_channel.c | 0 src/{ => launchpad/src}/launchpad_signal.c | 0 src/{ => launchpad/src}/loader_info.c | 0 src/lib/CMakeLists.txt | 53 ++++++ {inc => src/lib/inc}/launchpad.h | 2 + .../lib/pkgconfig/launchpad.pc.in | 0 src/{ => lib/src}/launchpad_lib.c | 2 +- src/loader/CMakeLists.txt | 74 ++++++++ src/{ => loader/src}/launchpad_loader.c | 0 {parser => src/parser}/CMakeLists.txt | 0 {parser => src/parser}/common.hh | 0 {parser => src/parser}/launchpad_parser_plugin.cc | 0 {parser => src/parser}/launchpad_parser_plugin.hh | 0 .../launchpad_parser_plugin_pkgmgr_interface.cc | 0 {parser => src/parser}/launchpad_plugins.txt | 0 {parser => src/parser}/loader_info.cc | 0 {parser => src/parser}/loader_info.hh | 0 {parser => src/parser}/log_private.hh | 0 52 files changed, 492 insertions(+), 210 deletions(-) rename launchpad-loader.manifest => packaging/launchpad-loader.manifest (100%) rename launchpad.manifest => packaging/launchpad.manifest (100%) rename liblaunchpad.manifest => packaging/liblaunchpad.manifest (100%) create mode 100644 src/CMakeLists.txt rename {inc => src/common/inc}/key.h (100%) rename {inc => src/common/inc}/launchpad_common.h (100%) rename {inc => src/common/inc}/launchpad_types.h (85%) rename src/{ => common/inc}/log_private.h (100%) rename {inc => src/common/inc}/perf.h (100%) rename {inc => src/common/inc}/preexec.h (100%) rename src/{ => common/src}/launchpad_common.c (100%) create mode 100644 src/hydra/CMakeLists.txt rename {inc => src/hydra/inc}/launchpad_hydra.h (100%) rename liblaunchpad-hydra.pc.in => src/hydra/pkgconfig/liblaunchpad-hydra.pc.in (100%) rename src/{ => hydra/src}/launchpad_hydra.c (100%) create mode 100644 src/launchpad/CMakeLists.txt rename {conf => src/launchpad/conf}/launchpad.conf.in (100%) rename {inc => src/launchpad/inc}/debugger_info.h (100%) rename {inc => src/launchpad/inc}/launcher_info.h (100%) rename {inc => src/launchpad/inc}/launchpad_config.h (100%) rename {inc => src/launchpad/inc}/launchpad_debug.h (100%) rename {inc => src/launchpad/inc}/launchpad_inotify.h (100%) rename {inc => src/launchpad/inc}/launchpad_io_channel.h (100%) rename {inc => src/launchpad/inc}/launchpad_signal.h (100%) rename {inc => src/launchpad/inc}/loader_info.h (100%) create mode 100644 src/launchpad/src/CMakeLists.txt rename src/{ => launchpad/src}/debugger_info.c (100%) rename src/{ => launchpad/src}/launcher_info.c (100%) rename src/{ => launchpad/src}/launchpad.c (98%) rename src/{ => launchpad/src}/launchpad_config.c (100%) rename src/{ => launchpad/src}/launchpad_debug.c (100%) rename src/{ => launchpad/src}/launchpad_inotify.c (100%) rename src/{ => launchpad/src}/launchpad_io_channel.c (100%) rename src/{ => launchpad/src}/launchpad_signal.c (100%) rename src/{ => launchpad/src}/loader_info.c (100%) create mode 100644 src/lib/CMakeLists.txt rename {inc => src/lib/inc}/launchpad.h (98%) rename launchpad.pc.in => src/lib/pkgconfig/launchpad.pc.in (100%) rename src/{ => lib/src}/launchpad_lib.c (99%) create mode 100644 src/loader/CMakeLists.txt rename src/{ => loader/src}/launchpad_loader.c (100%) rename {parser => src/parser}/CMakeLists.txt (100%) rename {parser => src/parser}/common.hh (100%) rename {parser => src/parser}/launchpad_parser_plugin.cc (100%) rename {parser => src/parser}/launchpad_parser_plugin.hh (100%) rename {parser => src/parser}/launchpad_parser_plugin_pkgmgr_interface.cc (100%) rename {parser => src/parser}/launchpad_plugins.txt (100%) rename {parser => src/parser}/loader_info.cc (100%) rename {parser => src/parser}/loader_info.hh (100%) rename {parser => src/parser}/log_private.hh (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6197582..e7d515c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,95 +1,5 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET (this_target_pool launchpad_pool) -SET (this_target_loader launchpad_loader) -SET (this_target_lib launchpad) -SET (this_target_hydra launchpad_hydra) - -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(${this_target_pool} REQUIRED - dlog - libsystemd - security-manager - tanchor - bundle - gio-2.0 - ttrace - vconf - libtzplatform-config - libcap - dbus-1 - iniparser - ) - -FOREACH(flag ${${this_target_pool}_CFLAGS}) - SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${flag}") -ENDFOREACH(flag) - -PKG_CHECK_MODULES(${this_target_loader} REQUIRED - dlog - ecore - elementary - security-manager - libtzplatform-config - tanchor - bundle - aul - vconf - buxton2 - libsystemd - gio-2.0 - dbus-1 - libcap - ) - -FOREACH(flag ${${this_target_loader}_CFLAGS}) - SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${flag}") -ENDFOREACH(flag) - -PKG_CHECK_MODULES(${this_target_lib} REQUIRED - dlog - bundle - aul - security-manager - libtzplatform-config - tanchor - dbus-1 - libcap - ) - -FOREACH(flag ${${this_target_lib}_CFLAGS}) - SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${flag}") -ENDFOREACH(flag) - -PKG_CHECK_MODULES(${this_target_hydra} REQUIRED - dlog - libsystemd) - -FOREACH(flag ${${this_target_hydra}_CFLAGS}) - SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${flag}") -ENDFOREACH(flag) - -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") - -IF(_TIZEN_FEATURE_PRELINK) -MESSAGE(STATUS "[__PRELINK__] Enable") -SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common}") -SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common}") -ELSE(_TIZEN_FEATURE_PRELINK) -MESSAGE(STATUS "[__PRELINK__] Disable") -SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common} -fPIE") -SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common} -fPIE") -ENDIF(_TIZEN_FEATURE_PRELINK) - -SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${EXTRA_CFLAGS_common}") -SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${EXTRA_CFLAGS_common}") - -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad C CXX) ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") IF(_TIZEN_FEATURE_PRIORITY_CHANGE) @@ -102,108 +12,9 @@ IF(_TIZEN_FEATURE_SET_PERSONALITY_32) ADD_DEFINITIONS("-DTIZEN_FEATURE_SET_PERSONALITY_32") ENDIF(_TIZEN_FEATURE_SET_PERSONALITY_32) +ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") ADD_DEFINITIONS("-DLAUNCHPAD_LOG") ADD_DEFINITIONS("-DPRELOAD_ACTIVATE") ADD_DEFINITIONS("-DPREEXEC_ACTIVATE") -#ADD_DEFINITIONS("-DPERF_ACTIVATE") - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) - -# launchpad-loader -SET(LAUNCHPAD_LOADER "launchpad-loader") -SET(${LAUNCHPAD_LOADER}_SOURCE_FILES - src/launchpad_loader.c - src/launchpad_common.c - src/launchpad_lib.c - ) -ADD_EXECUTABLE(${LAUNCHPAD_LOADER} ${${LAUNCHPAD_LOADER}_SOURCE_FILES}) - -# To support 2.x applications which use their own shared libraries. -# Since we cannot set LD_LIBRARY_PATH directly by security issue, we make the -# dynamic linker looks in the CWD forcely. -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} "-ldl -Wl,-rpath,: -Wl,--disable-new-dtags") - -IF(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${${this_target_loader}_LDFLAGS}) -ELSE(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${${this_target_loader}_LDFLAGS} "-pie") -ENDIF(_TIZEN_FEATURE_PRELINK) - -SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_loader}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} - PROPERTIES SKIP_BUILD_RPATH TRUE - ) # remove rpath option that is automatically generated by cmake. -INSTALL(TARGETS ${LAUNCHPAD_LOADER} DESTINATION bin) - -# launchpad-process-pool -SET(LAUNCHPAD_PROCESS_POOL "launchpad-process-pool") -SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES - src/launchpad.c - src/launchpad_common.c - src/loader_info.c - src/launcher_info.c - src/debugger_info.c - src/launchpad_debug.c - src/launchpad_signal.c - src/launchpad_config.c - src/launchpad_io_channel.c - src/launchpad_inotify.c - ) -ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES}) - -IF(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-lm") -ELSE(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-pie -lm") -ENDIF(_TIZEN_FEATURE_PRELINK) -SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} - PROPERTIES SKIP_BUILD_RPATH TRUE - ) # remove rpath option that is automatically generated by cmake. - -CONFIGURE_FILE(packaging/default.debugger.in packaging/default.debugger @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.debugger DESTINATION share/aul) -INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin) - -CONFIGURE_FILE(packaging/default.loader.in packaging/default.loader @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul) - -CONFIGURE_FILE(conf/launchpad.conf.in conf/launchpad.conf @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf DESTINATION share/aul) - -# liblaunchpad -SET(LAUNCHPAD_LIB "launchpad") -ADD_LIBRARY(${LAUNCHPAD_LIB} SHARED - src/launchpad_lib.c - src/launchpad_common.c - ) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES VERSION ${VERSION}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_lib}) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LIB} ${${this_target_lib}_LDFLAGS} "-ldl") - -INSTALL(TARGETS ${LAUNCHPAD_LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad.h DESTINATION include/launchpad) -CONFIGURE_FILE(launchpad.pc.in launchpad.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/launchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -CONFIGURE_FILE(launchpad.pc.in liblaunchpad.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -# liblaunchpad_hydra -SET(LAUNCHPAD_HYDRA "launchpad-hydra") -ADD_LIBRARY(${LAUNCHPAD_HYDRA} SHARED - src/launchpad_hydra.c - ) -SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES VERSION ${VERSION}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_hydra}) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_HYDRA} ${${this_target_hydra}_LDFLAGS} "-ldl") - -INSTALL(TARGETS ${LAUNCHPAD_HYDRA} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad_hydra.h DESTINATION include/launchpad) - -CONFIGURE_FILE(liblaunchpad-hydra.pc.in liblaunchpad-hydra.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad-hydra.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -# parser -ADD_SUBDIRECTORY(parser) \ No newline at end of file +ADD_SUBDIRECTORY(src) diff --git a/launchpad-loader.manifest b/packaging/launchpad-loader.manifest similarity index 100% rename from launchpad-loader.manifest rename to packaging/launchpad-loader.manifest diff --git a/launchpad.manifest b/packaging/launchpad.manifest similarity index 100% rename from launchpad.manifest rename to packaging/launchpad.manifest diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index babb8b4..4250709 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -7,7 +7,9 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source101: launchpad-process-pool.service Source102: launchpad-process-pool.socket - +Source1001: %{name}.manifest +Source1002: lib%{name}.manifest +Source1003: %{name}-loader.manifest BuildRequires: cmake BuildRequires: pkgconfig(bundle) @@ -87,6 +89,9 @@ Launchpad library (devel) %prep %setup -q +cp %{SOURCE1001} . +cp %{SOURCE1002} . +cp %{SOURCE1003} . %build %if 0%{?sec_build_binary_debug_enable} diff --git a/liblaunchpad.manifest b/packaging/liblaunchpad.manifest similarity index 100% rename from liblaunchpad.manifest rename to packaging/liblaunchpad.manifest diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..3a0a104 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,9 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +ADD_SUBDIRECTORY(launchpad) +ADD_SUBDIRECTORY(lib) +ADD_SUBDIRECTORY(loader) +ADD_SUBDIRECTORY(hydra) +ADD_SUBDIRECTORY(parser) + +ADD_DEPENDENCIES(launchpad-loader launchpad-lib) diff --git a/inc/key.h b/src/common/inc/key.h similarity index 100% rename from inc/key.h rename to src/common/inc/key.h diff --git a/inc/launchpad_common.h b/src/common/inc/launchpad_common.h similarity index 100% rename from inc/launchpad_common.h rename to src/common/inc/launchpad_common.h diff --git a/inc/launchpad_types.h b/src/common/inc/launchpad_types.h similarity index 85% rename from inc/launchpad_types.h rename to src/common/inc/launchpad_types.h index 22ae867..fc822d7 100644 --- a/inc/launchpad_types.h +++ b/src/common/inc/launchpad_types.h @@ -40,6 +40,13 @@ typedef enum hydra_cmd { LAUNCH_CANDIDATE, } hydra_cmd_e; +typedef enum launchpad_loader_type { + LAUNCHPAD_LOADER_TYPE_UNSUPPORTED = -1, + LAUNCHPAD_LOADER_TYPE_USER = 1, + LAUNCHPAD_LOADER_TYPE_DYNAMIC = 100, + LAUNCHPAD_LOADER_TYPE_MAX +} launchpad_loader_type_e; + #ifdef __cplusplus } #endif diff --git a/src/log_private.h b/src/common/inc/log_private.h similarity index 100% rename from src/log_private.h rename to src/common/inc/log_private.h diff --git a/inc/perf.h b/src/common/inc/perf.h similarity index 100% rename from inc/perf.h rename to src/common/inc/perf.h diff --git a/inc/preexec.h b/src/common/inc/preexec.h similarity index 100% rename from inc/preexec.h rename to src/common/inc/preexec.h diff --git a/src/launchpad_common.c b/src/common/src/launchpad_common.c similarity index 100% rename from src/launchpad_common.c rename to src/common/src/launchpad_common.c diff --git a/src/hydra/CMakeLists.txt b/src/hydra/CMakeLists.txt new file mode 100644 index 0000000..0ff9ebe --- /dev/null +++ b/src/hydra/CMakeLists.txt @@ -0,0 +1,41 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-hydra C) +SET(LAUNCHPAD_HYDRA "launchpad-hydra") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_HYDRA_PKGS REQUIRED + dlog + libsystemd) + +FOREACH(flag ${LAUNCHPAD_HYDRA_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") + +SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${EXTRA_CFLAGS_common}") + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) + +ADD_LIBRARY(${LAUNCHPAD_HYDRA} SHARED ${SOURCES}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES VERSION ${VERSION}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_hydra}) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_HYDRA} ${LAUNCHPAD_HYDRA_PKGS_LDFLAGS} "-ldl") + +INSTALL(TARGETS ${LAUNCHPAD_HYDRA} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad_hydra.h DESTINATION include/launchpad) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad-hydra.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad-hydra.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad-hydra.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/inc/launchpad_hydra.h b/src/hydra/inc/launchpad_hydra.h similarity index 100% rename from inc/launchpad_hydra.h rename to src/hydra/inc/launchpad_hydra.h diff --git a/liblaunchpad-hydra.pc.in b/src/hydra/pkgconfig/liblaunchpad-hydra.pc.in similarity index 100% rename from liblaunchpad-hydra.pc.in rename to src/hydra/pkgconfig/liblaunchpad-hydra.pc.in diff --git a/src/launchpad_hydra.c b/src/hydra/src/launchpad_hydra.c similarity index 100% rename from src/launchpad_hydra.c rename to src/hydra/src/launchpad_hydra.c diff --git a/src/launchpad/CMakeLists.txt b/src/launchpad/CMakeLists.txt new file mode 100644 index 0000000..a51f395 --- /dev/null +++ b/src/launchpad/CMakeLists.txt @@ -0,0 +1,71 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-process-pool C) +SET(LAUNCHPAD_PROCESS_POOL "launchpad-process-pool") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_PROCESS_POOL_PKGS REQUIRED + bundle + dbus-1 + dlog + gio-2.0 + iniparser + libcap + libsystemd + libtzplatform-config + security-manager + tanchor + ttrace + vconf + ) + +FOREACH(flag ${LAUNCHPAD_PROCESS_POOL_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") + +IF(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Enable") +SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common}") +ELSE(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Disable") +SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common} -fPIE") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +SET(LAUNCHPAD_PROCESS_POOL_SOURCE_FILES + ${COMMON_SOURCES} + ${SOURCES}) + +ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_SOURCE_FILES}) + +IF(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm") +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-pie -lm") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} + PROPERTIES SKIP_BUILD_RPATH TRUE + ) # remove rpath option that is automatically generated by cmake. + +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/packaging/default.debugger.in ${CMAKE_SOURCE_DIR}/packaging/default.debugger @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/default.debugger DESTINATION share/aul) +INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf.in ${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf DESTINATION share/aul) diff --git a/conf/launchpad.conf.in b/src/launchpad/conf/launchpad.conf.in similarity index 100% rename from conf/launchpad.conf.in rename to src/launchpad/conf/launchpad.conf.in diff --git a/inc/debugger_info.h b/src/launchpad/inc/debugger_info.h similarity index 100% rename from inc/debugger_info.h rename to src/launchpad/inc/debugger_info.h diff --git a/inc/launcher_info.h b/src/launchpad/inc/launcher_info.h similarity index 100% rename from inc/launcher_info.h rename to src/launchpad/inc/launcher_info.h diff --git a/inc/launchpad_config.h b/src/launchpad/inc/launchpad_config.h similarity index 100% rename from inc/launchpad_config.h rename to src/launchpad/inc/launchpad_config.h diff --git a/inc/launchpad_debug.h b/src/launchpad/inc/launchpad_debug.h similarity index 100% rename from inc/launchpad_debug.h rename to src/launchpad/inc/launchpad_debug.h diff --git a/inc/launchpad_inotify.h b/src/launchpad/inc/launchpad_inotify.h similarity index 100% rename from inc/launchpad_inotify.h rename to src/launchpad/inc/launchpad_inotify.h diff --git a/inc/launchpad_io_channel.h b/src/launchpad/inc/launchpad_io_channel.h similarity index 100% rename from inc/launchpad_io_channel.h rename to src/launchpad/inc/launchpad_io_channel.h diff --git a/inc/launchpad_signal.h b/src/launchpad/inc/launchpad_signal.h similarity index 100% rename from inc/launchpad_signal.h rename to src/launchpad/inc/launchpad_signal.h diff --git a/inc/loader_info.h b/src/launchpad/inc/loader_info.h similarity index 100% rename from inc/loader_info.h rename to src/launchpad/inc/loader_info.h diff --git a/src/launchpad/src/CMakeLists.txt b/src/launchpad/src/CMakeLists.txt new file mode 100644 index 0000000..6197582 --- /dev/null +++ b/src/launchpad/src/CMakeLists.txt @@ -0,0 +1,209 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET (this_target_pool launchpad_pool) +SET (this_target_loader launchpad_loader) +SET (this_target_lib launchpad) +SET (this_target_hydra launchpad_hydra) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(${this_target_pool} REQUIRED + dlog + libsystemd + security-manager + tanchor + bundle + gio-2.0 + ttrace + vconf + libtzplatform-config + libcap + dbus-1 + iniparser + ) + +FOREACH(flag ${${this_target_pool}_CFLAGS}) + SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${flag}") +ENDFOREACH(flag) + +PKG_CHECK_MODULES(${this_target_loader} REQUIRED + dlog + ecore + elementary + security-manager + libtzplatform-config + tanchor + bundle + aul + vconf + buxton2 + libsystemd + gio-2.0 + dbus-1 + libcap + ) + +FOREACH(flag ${${this_target_loader}_CFLAGS}) + SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${flag}") +ENDFOREACH(flag) + +PKG_CHECK_MODULES(${this_target_lib} REQUIRED + dlog + bundle + aul + security-manager + libtzplatform-config + tanchor + dbus-1 + libcap + ) + +FOREACH(flag ${${this_target_lib}_CFLAGS}) + SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${flag}") +ENDFOREACH(flag) + +PKG_CHECK_MODULES(${this_target_hydra} REQUIRED + dlog + libsystemd) + +FOREACH(flag ${${this_target_hydra}_CFLAGS}) + SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") + +IF(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Enable") +SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common}") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common}") +ELSE(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Disable") +SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common} -fPIE") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common} -fPIE") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${EXTRA_CFLAGS_common}") +SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${EXTRA_CFLAGS_common}") + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") +IF(_TIZEN_FEATURE_PRIORITY_CHANGE) + ADD_DEFINITIONS("-DTIZEN_FEATURE_PRIORITY_CHANGE") +ENDIF(_TIZEN_FEATURE_PRIORITY_CHANGE) +IF(_TIZEN_FEATURE_LOADER_PRIORITY) + ADD_DEFINITIONS("-DTIZEN_FEATURE_LOADER_PRIORITY") +ENDIF(_TIZEN_FEATURE_LOADER_PRIORITY) +IF(_TIZEN_FEATURE_SET_PERSONALITY_32) + ADD_DEFINITIONS("-DTIZEN_FEATURE_SET_PERSONALITY_32") +ENDIF(_TIZEN_FEATURE_SET_PERSONALITY_32) + +ADD_DEFINITIONS("-DLAUNCHPAD_LOG") +ADD_DEFINITIONS("-DPRELOAD_ACTIVATE") +ADD_DEFINITIONS("-DPREEXEC_ACTIVATE") +#ADD_DEFINITIONS("-DPERF_ACTIVATE") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) + +# launchpad-loader +SET(LAUNCHPAD_LOADER "launchpad-loader") +SET(${LAUNCHPAD_LOADER}_SOURCE_FILES + src/launchpad_loader.c + src/launchpad_common.c + src/launchpad_lib.c + ) +ADD_EXECUTABLE(${LAUNCHPAD_LOADER} ${${LAUNCHPAD_LOADER}_SOURCE_FILES}) + +# To support 2.x applications which use their own shared libraries. +# Since we cannot set LD_LIBRARY_PATH directly by security issue, we make the +# dynamic linker looks in the CWD forcely. +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} "-ldl -Wl,-rpath,: -Wl,--disable-new-dtags") + +IF(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${${this_target_loader}_LDFLAGS}) +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${${this_target_loader}_LDFLAGS} "-pie") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_loader}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} + PROPERTIES SKIP_BUILD_RPATH TRUE + ) # remove rpath option that is automatically generated by cmake. +INSTALL(TARGETS ${LAUNCHPAD_LOADER} DESTINATION bin) + +# launchpad-process-pool +SET(LAUNCHPAD_PROCESS_POOL "launchpad-process-pool") +SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES + src/launchpad.c + src/launchpad_common.c + src/loader_info.c + src/launcher_info.c + src/debugger_info.c + src/launchpad_debug.c + src/launchpad_signal.c + src/launchpad_config.c + src/launchpad_io_channel.c + src/launchpad_inotify.c + ) +ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES}) + +IF(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-lm") +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-pie -lm") +ENDIF(_TIZEN_FEATURE_PRELINK) +SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} + PROPERTIES SKIP_BUILD_RPATH TRUE + ) # remove rpath option that is automatically generated by cmake. + +CONFIGURE_FILE(packaging/default.debugger.in packaging/default.debugger @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.debugger DESTINATION share/aul) +INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin) + +CONFIGURE_FILE(packaging/default.loader.in packaging/default.loader @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul) + +CONFIGURE_FILE(conf/launchpad.conf.in conf/launchpad.conf @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf DESTINATION share/aul) + +# liblaunchpad +SET(LAUNCHPAD_LIB "launchpad") +ADD_LIBRARY(${LAUNCHPAD_LIB} SHARED + src/launchpad_lib.c + src/launchpad_common.c + ) +SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES VERSION ${VERSION}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_lib}) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LIB} ${${this_target_lib}_LDFLAGS} "-ldl") + +INSTALL(TARGETS ${LAUNCHPAD_LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad.h DESTINATION include/launchpad) +CONFIGURE_FILE(launchpad.pc.in launchpad.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/launchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +CONFIGURE_FILE(launchpad.pc.in liblaunchpad.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +# liblaunchpad_hydra +SET(LAUNCHPAD_HYDRA "launchpad-hydra") +ADD_LIBRARY(${LAUNCHPAD_HYDRA} SHARED + src/launchpad_hydra.c + ) +SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES VERSION ${VERSION}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_hydra}) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_HYDRA} ${${this_target_hydra}_LDFLAGS} "-ldl") + +INSTALL(TARGETS ${LAUNCHPAD_HYDRA} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad_hydra.h DESTINATION include/launchpad) + +CONFIGURE_FILE(liblaunchpad-hydra.pc.in liblaunchpad-hydra.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad-hydra.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +# parser +ADD_SUBDIRECTORY(parser) \ No newline at end of file diff --git a/src/debugger_info.c b/src/launchpad/src/debugger_info.c similarity index 100% rename from src/debugger_info.c rename to src/launchpad/src/debugger_info.c diff --git a/src/launcher_info.c b/src/launchpad/src/launcher_info.c similarity index 100% rename from src/launcher_info.c rename to src/launchpad/src/launcher_info.c diff --git a/src/launchpad.c b/src/launchpad/src/launchpad.c similarity index 98% rename from src/launchpad.c rename to src/launchpad/src/launchpad.c index b1a3ef1..6d7b43b 100644 --- a/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -41,7 +41,6 @@ #include "key.h" #include "launcher_info.h" -#include "launchpad.h" #include "launchpad_common.h" #include "launchpad_config.h" #include "launchpad_debug.h" @@ -338,8 +337,8 @@ static candidate_process_context_t *__find_slot_from_static_type(int type) candidate_process_context_t *cpc; GList *iter = candidate_slot_list; - if (type == LAUNCHPAD_TYPE_DYNAMIC || - type == LAUNCHPAD_TYPE_UNSUPPORTED) + if (type == LAUNCHPAD_LOADER_TYPE_DYNAMIC || + type == LAUNCHPAD_LOADER_TYPE_UNSUPPORTED) return NULL; while (iter) { @@ -419,7 +418,7 @@ static candidate_process_context_t *__find_slot_from_loader_id(int id) static candidate_process_context_t *__find_slot(int type, int loader_id) { - if (type == LAUNCHPAD_TYPE_DYNAMIC) + if (type == LAUNCHPAD_LOADER_TYPE_DYNAMIC) return __find_slot_from_loader_id(loader_id); return __find_slot_from_static_type(type); @@ -1388,7 +1387,7 @@ static bool __handle_sigchild(int fd, io_condition_e cond, void *data) cpc = __find_slot_from_caller_pid(pid); while (cpc) { - __remove_slot(LAUNCHPAD_TYPE_DYNAMIC, cpc->loader_id); + __remove_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, cpc->loader_id); cpc = __find_slot_from_caller_pid(pid); } } while (s > 0); @@ -1579,7 +1578,8 @@ 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), + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, + atoi(caller_pid), add_slot_str, extra, METHOD_TIMEOUT | METHOD_VISIBILITY, METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, @@ -1629,7 +1629,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) bundle_encode(info->extra, &extra, &len); lid = __make_loader_id(); - cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, 0, + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, 0, loader_path, (const char *)extra, METHOD_TIMEOUT | METHOD_VISIBILITY, METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, @@ -1646,7 +1646,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) return -ENOMEM; } - __prepare_candidate_process(LAUNCHPAD_TYPE_DYNAMIC, lid); + __prepare_candidate_process(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid); return lid; } @@ -1659,7 +1659,7 @@ static int __dispatch_cmd_remove_loader(bundle *kb) _W("cmd remove loader"); if (id) { lid = atoi(id); - if (__remove_slot(LAUNCHPAD_TYPE_DYNAMIC, lid) == 0) + if (__remove_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid) == 0) return 0; } @@ -1960,7 +1960,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) strcmp(menu_info->comp_type, "svcapp") == 0) { loader_id = __get_loader_id(kb); if (loader_id > PAD_LOADER_ID_DYNAMIC_BASE) { - type = LAUNCHPAD_TYPE_DYNAMIC; + type = LAUNCHPAD_LOADER_TYPE_DYNAMIC; cpc = __find_slot(type, loader_id); if (cpc && !cpc->prepared) cpc = NULL; @@ -1978,7 +1978,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) menu_info->app_type, menu_info->loader_name, &org_cpc); } else { - type = LAUNCHPAD_TYPE_DYNAMIC; + type = LAUNCHPAD_LOADER_TYPE_DYNAMIC; cpc = __find_slot(type, loader_id); if (cpc && !cpc->prepared) cpc = NULL; @@ -2422,7 +2422,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) int len; if (!strcmp(info->exe, "null")) { - cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset, PAD_LOADER_ID_DIRECT, 0, info->exe, NULL, 0, 0, 0, 0, 0, @@ -2433,7 +2433,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) if (cpc == NULL) return; - info->type = LAUNCHPAD_TYPE_USER + user_slot_offset; + info->type = LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset; user_slot_offset++; return; } @@ -2445,7 +2445,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) if (info->extra) bundle_encode(info->extra, &extra, &len); - cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset, PAD_LOADER_ID_STATIC, 0, info->exe, (char *)extra, info->detection_method, @@ -2460,7 +2460,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) if (cpc == NULL) return; - info->type = LAUNCHPAD_TYPE_USER + user_slot_offset; + info->type = LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset; user_slot_offset++; } } diff --git a/src/launchpad_config.c b/src/launchpad/src/launchpad_config.c similarity index 100% rename from src/launchpad_config.c rename to src/launchpad/src/launchpad_config.c diff --git a/src/launchpad_debug.c b/src/launchpad/src/launchpad_debug.c similarity index 100% rename from src/launchpad_debug.c rename to src/launchpad/src/launchpad_debug.c diff --git a/src/launchpad_inotify.c b/src/launchpad/src/launchpad_inotify.c similarity index 100% rename from src/launchpad_inotify.c rename to src/launchpad/src/launchpad_inotify.c diff --git a/src/launchpad_io_channel.c b/src/launchpad/src/launchpad_io_channel.c similarity index 100% rename from src/launchpad_io_channel.c rename to src/launchpad/src/launchpad_io_channel.c diff --git a/src/launchpad_signal.c b/src/launchpad/src/launchpad_signal.c similarity index 100% rename from src/launchpad_signal.c rename to src/launchpad/src/launchpad_signal.c diff --git a/src/loader_info.c b/src/launchpad/src/loader_info.c similarity index 100% rename from src/loader_info.c rename to src/launchpad/src/loader_info.c diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt new file mode 100644 index 0000000..d5a2ecd --- /dev/null +++ b/src/lib/CMakeLists.txt @@ -0,0 +1,53 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-lib C) +SET(LAUNCHPAD_LIB "launchpad") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_LIB_PKGS REQUIRED + aul + bundle + dbus-1 + dlog + libcap + libtzplatform-config + security-manager + tanchor + ) + +FOREACH(flag ${LAUNCHPAD_LIB_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") + +SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${EXTRA_CFLAGS_common}") + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +ADD_LIBRARY(${LAUNCHPAD_LIB} SHARED + ${COMMON_SOURCES} + ${SOURCES}) + +SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES VERSION ${VERSION}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_lib}) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LIB} ${LAUNCHPAD_LIB_PKGS_LDFLAGS} "-ldl") + +INSTALL(TARGETS ${LAUNCHPAD_LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad.h DESTINATION include/launchpad) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/inc/launchpad.h b/src/lib/inc/launchpad.h similarity index 98% rename from inc/launchpad.h rename to src/lib/inc/launchpad.h index b5a11db..7d20175 100644 --- a/inc/launchpad.h +++ b/src/lib/inc/launchpad.h @@ -75,6 +75,8 @@ int launchpad_loader_main(int argc, char **argv, */ int launchpad_loader_set_priority(int prio); +bundle *launchpad_loader_get_bundle(void); + #ifdef __cplusplus } #endif diff --git a/launchpad.pc.in b/src/lib/pkgconfig/launchpad.pc.in similarity index 100% rename from launchpad.pc.in rename to src/lib/pkgconfig/launchpad.pc.in diff --git a/src/launchpad_lib.c b/src/lib/src/launchpad_lib.c similarity index 99% rename from src/launchpad_lib.c rename to src/lib/src/launchpad_lib.c index 118f561..e2a75bc 100644 --- a/src/launchpad_lib.c +++ b/src/lib/src/launchpad_lib.c @@ -382,7 +382,7 @@ static int __after_loop(void) return -1; } -bundle *launchpad_loader_get_bundle() +API bundle *launchpad_loader_get_bundle(void) { return __bundle; } diff --git a/src/loader/CMakeLists.txt b/src/loader/CMakeLists.txt new file mode 100644 index 0000000..997f034 --- /dev/null +++ b/src/loader/CMakeLists.txt @@ -0,0 +1,74 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-loader C) +SET(LAUNCHPAD_LOADER "launchpad-loader") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_LOADER_PKGS REQUIRED + dlog + ecore + elementary + security-manager + libtzplatform-config + tanchor + bundle + aul + vconf + buxton2 + libsystemd + gio-2.0 + dbus-1 + libcap + ) + +FOREACH(flag ${LAUNCHPAD_LOADER_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") + +IF(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Enable") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common}") +ELSE(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Disable") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common} -fPIE") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +SET(LAUNCHPAD_LOADER_SOURCE_FILES + ${COMMON_SOURCES} + ${SOURCES}) +ADD_EXECUTABLE(${LAUNCHPAD_LOADER} ${LAUNCHPAD_LOADER_SOURCE_FILES}) + +# To support 2.x applications which use their own shared libraries. +# Since we cannot set LD_LIBRARY_PATH directly by security issue, we make the +# dynamic linker looks in the CWD forcely. +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} "-ldl -Wl,-rpath,: -Wl,--disable-new-dtags") + +IF(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${LAUNCHPAD_LOADER_PKGS_LDFLAGS} launchpad) +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${LAUNCHPAD_LOADER_PKGS_LDFLAGS} launchpad "-pie") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_loader}) +SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} + PROPERTIES SKIP_BUILD_RPATH TRUE + ) # remove rpath option that is automatically generated by cmake. +INSTALL(TARGETS ${LAUNCHPAD_LOADER} DESTINATION bin) + +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/packaging/default.loader.in ${CMAKE_SOURCE_DIR}/packaging/default.loader @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul) diff --git a/src/launchpad_loader.c b/src/loader/src/launchpad_loader.c similarity index 100% rename from src/launchpad_loader.c rename to src/loader/src/launchpad_loader.c diff --git a/parser/CMakeLists.txt b/src/parser/CMakeLists.txt similarity index 100% rename from parser/CMakeLists.txt rename to src/parser/CMakeLists.txt diff --git a/parser/common.hh b/src/parser/common.hh similarity index 100% rename from parser/common.hh rename to src/parser/common.hh diff --git a/parser/launchpad_parser_plugin.cc b/src/parser/launchpad_parser_plugin.cc similarity index 100% rename from parser/launchpad_parser_plugin.cc rename to src/parser/launchpad_parser_plugin.cc diff --git a/parser/launchpad_parser_plugin.hh b/src/parser/launchpad_parser_plugin.hh similarity index 100% rename from parser/launchpad_parser_plugin.hh rename to src/parser/launchpad_parser_plugin.hh diff --git a/parser/launchpad_parser_plugin_pkgmgr_interface.cc b/src/parser/launchpad_parser_plugin_pkgmgr_interface.cc similarity index 100% rename from parser/launchpad_parser_plugin_pkgmgr_interface.cc rename to src/parser/launchpad_parser_plugin_pkgmgr_interface.cc diff --git a/parser/launchpad_plugins.txt b/src/parser/launchpad_plugins.txt similarity index 100% rename from parser/launchpad_plugins.txt rename to src/parser/launchpad_plugins.txt diff --git a/parser/loader_info.cc b/src/parser/loader_info.cc similarity index 100% rename from parser/loader_info.cc rename to src/parser/loader_info.cc diff --git a/parser/loader_info.hh b/src/parser/loader_info.hh similarity index 100% rename from parser/loader_info.hh rename to src/parser/loader_info.hh diff --git a/parser/log_private.hh b/src/parser/log_private.hh similarity index 100% rename from parser/log_private.hh rename to src/parser/log_private.hh -- 2.7.4 From 207abc7fb457773d1caf2c7033e7a31602baefeb Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Feb 2020 08:14:35 +0900 Subject: [PATCH 13/16] Release version 0.12.0 Changes: - Add a plugin for app-defined loader - Add app-defined loader - Fix return values of __dispatch_cmd_add_app_defined_loader() - Separate codes into directories Change-Id: I0e76ec5d9493acc58e41b88dc0b7559de79ef81f Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 4250709..3cd3478 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.11.0 +Version: 0.12.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From aea787b684bc5fdc3fa1fb1b64bc95d5211866cf Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Feb 2020 09:32:19 +0900 Subject: [PATCH 14/16] Fix log format Change-Id: I7105f7057dc81bb6d40b3bfd5c7ad62f14a57058 Signed-off-by: Hwankyu Jhun --- src/parser/launchpad_parser_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/launchpad_parser_plugin.cc b/src/parser/launchpad_parser_plugin.cc index a880a6e..95deccb 100644 --- a/src/parser/launchpad_parser_plugin.cc +++ b/src/parser/launchpad_parser_plugin.cc @@ -36,7 +36,7 @@ int LaunchpadParser::WriteToFile(string pkgid) { if (access(LOADERS_DIRECTORY_PATH, F_OK) != 0) mkdir(LOADERS_DIRECTORY_PATH, 0644); - LOGI("write to file (%d)", loader_list_.size()); + LOGI("write to file (%zu)", loader_list_.size()); for (auto& i : loader_list_) { std::ofstream out_file; LOGI("write ID (%s)", i->GetId().c_str()); -- 2.7.4 From c8420009b043419336926914312b675e925646be Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Feb 2020 09:32:33 +0900 Subject: [PATCH 15/16] Release version 0.12.1 Changes: - Fix log format Change-Id: I7fdd6ddf39a2b876d53312ba8e4e5ef26b4c6a59 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 3cd3478..db73636 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.12.0 +Version: 0.12.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 1c9a87dca5fb04388284b35f41106dd7111d9e29 Mon Sep 17 00:00:00 2001 From: hyunho Date: Thu, 20 Feb 2020 11:11:36 +0900 Subject: [PATCH 16/16] Add app_defined_loader Change-Id: I9ec6d2202ec3e6596a19b787a204703771996669 Signed-off-by: hyunho --- packaging/app-defined-loader.manifest | 8 + packaging/launchpad.spec | 14 + src/CMakeLists.txt | 2 + src/app_defined_loader/CMakeLists.txt | 69 +++++ src/app_defined_loader/src/app_defined_loader.cc | 330 +++++++++++++++++++++++ src/common/inc/launchpad_common.h | 14 + src/launchpad/src/launchpad.c | 12 +- src/loader/src/launchpad_loader.c | 5 - 8 files changed, 440 insertions(+), 14 deletions(-) create mode 100644 packaging/app-defined-loader.manifest create mode 100644 src/app_defined_loader/CMakeLists.txt create mode 100644 src/app_defined_loader/src/app_defined_loader.cc diff --git a/packaging/app-defined-loader.manifest b/packaging/app-defined-loader.manifest new file mode 100644 index 0000000..bd30b8b --- /dev/null +++ b/packaging/app-defined-loader.manifest @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index db73636..5935833 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -10,6 +10,7 @@ Source102: launchpad-process-pool.socket Source1001: %{name}.manifest Source1002: lib%{name}.manifest Source1003: %{name}-loader.manifest +Source1004: app-defined-loader.manifest BuildRequires: cmake BuildRequires: pkgconfig(bundle) @@ -72,6 +73,13 @@ Group: Application Framework/Application Launcher %description -n launchpad-loader Launchpad-Loader for launching applications +%package -n app-defined-loader +Summary: App-Defined-Loader for launching applications +Group: Application Framework/Application Launcher + +%description -n app-defined-loader +App-Defined-Loader for launching applications + %package -n liblaunchpad Summary: Launchpad library Group: Development/Libraries @@ -92,6 +100,7 @@ Launchpad library (devel) cp %{SOURCE1001} . cp %{SOURCE1002} . cp %{SOURCE1003} . +cp %{SOURCE1004} . %build %if 0%{?sec_build_binary_debug_enable} @@ -160,6 +169,11 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %{_prefix}/share/aul/default.loader %{_bindir}/launchpad-loader +%files -n app-defined-loader +%manifest app-defined-loader.manifest +%license LICENSE +%{_bindir}/app-defined-loader + %files -n liblaunchpad %manifest liblaunchpad.manifest %license LICENSE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a0a104..dbab7f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) ADD_SUBDIRECTORY(launchpad) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(loader) +ADD_SUBDIRECTORY(app_defined_loader) ADD_SUBDIRECTORY(hydra) ADD_SUBDIRECTORY(parser) ADD_DEPENDENCIES(launchpad-loader launchpad-lib) +ADD_DEPENDENCIES(app-defined-loader launchpad-lib) diff --git a/src/app_defined_loader/CMakeLists.txt b/src/app_defined_loader/CMakeLists.txt new file mode 100644 index 0000000..b0f869e --- /dev/null +++ b/src/app_defined_loader/CMakeLists.txt @@ -0,0 +1,69 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(app-defined-loader) +SET(APP_DEFINED_LOADER "app-defined-loader") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(APP_DEFINED_LOADER_PKGS REQUIRED + dlog + ecore + ecore-core + bundle + aul + gio-2.0 + dbus-1 + libsystemd + ) + +FOREACH(flag ${APP_DEFINED_LOADER_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") +SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") + +IF(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Enable") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common}") +ELSE(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Disable") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common} -fPIE") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +SET(APP_DEFINED_LOADER_SOURCE_FILES + ${COMMON_SOURCES} + ${SOURCES}) +ADD_EXECUTABLE(${APP_DEFINED_LOADER} ${APP_DEFINED_LOADER_SOURCE_FILES}) + +# To support 2.x applications which use their own shared libraries. +# Since we cannot set LD_LIBRARY_PATH directly by security issue, we make the +# dynamic linker looks in the CWD forcely. +TARGET_LINK_LIBRARIES(${APP_DEFINED_LOADER} "-ldl -Wl,-rpath,: -Wl,--disable-new-dtags") + +IF(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${APP_DEFINED_LOADER} ${APP_DEFINED_LOADER_PKGS_LDFLAGS} launchpad) +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${APP_DEFINED_LOADER} ${APP_DEFINED_LOADER_PKGS_LDFLAGS} launchpad "-pie") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET_TARGET_PROPERTIES(${APP_DEFINED_LOADER} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_loader}) +SET_TARGET_PROPERTIES(${APP_DEFINED_LOADER} + PROPERTIES SKIP_BUILD_RPATH TRUE + ) # remove rpath option that is automatically generated by cmake. +INSTALL(TARGETS ${APP_DEFINED_LOADER} DESTINATION bin) \ No newline at end of file diff --git a/src/app_defined_loader/src/app_defined_loader.cc b/src/app_defined_loader/src/app_defined_loader.cc new file mode 100644 index 0000000..39ba7d1 --- /dev/null +++ b/src/app_defined_loader/src/app_defined_loader.cc @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2020 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. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "launchpad_common.h" +#include "launchpad_types.h" +#include "launchpad.h" +#include "key.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "APP_DEFINED_LOADER" + +#ifndef PR_TASK_PERF_USER_TRACE +#define PR_TASK_PERF_USER_TRACE 666 +#endif + +#ifndef C_EXPORT +#define C_EXPORT extern "C" __attribute__((visibility("default"))) +#endif + +using namespace tizen_base; +using namespace std; +namespace launchpad { + +class AppDefinedLoader { + public: + AppDefinedLoader(int argc, char** argv) + : argc_(argc), argv_(argv) { + lifecycle_cb_ = shared_ptr(new loader_lifecycle_callback_s()); + lifecycle_cb_->create = OnCreate; + lifecycle_cb_->launch = OnLaunch; + lifecycle_cb_->terminate = OnTerminate; + + adapter_ = shared_ptr(new loader_adapter_s()); + adapter_->loop_begin = OnLoopBegin; + adapter_->loop_quit = OnLoopQuit; + adapter_->add_fd = OnAddFd; + adapter_->remove_fd = OnRemoveFd; + } + + ~AppDefinedLoader() { + _W("app defined loader destroyed"); + } + + shared_ptr GetLifeCycle() { + return lifecycle_cb_; + } + + shared_ptr GetAdapter() { + return adapter_; + } + + void SetLoaderPriority(bool enable) { + loader_priority_enabled_ = enable; + } + + void SetPriorityChanged(bool enable) { + priority_change_enabled_ = enable; + } + + bool IsLoaderPriorityEnabled() { + return loader_priority_enabled_; + } + + bool IsPriorityChangeEnabled() { + return priority_change_enabled_; + } + + void SetFdHandler(Ecore_Fd_Handler* fd_handler) { + fd_handler_ = fd_handler; + } + + Ecore_Fd_Handler* GetFdHandler() { + return fd_handler_; + } + + void SetReceiver(loader_receiver_cb receiver) { + receiver_cb_ = receiver; + } + + loader_receiver_cb GetReceiver() { + return receiver_cb_; + } + + private: + static void PreloadLib(Bundle data) { + vector so_array = data.GetStringArray("preload"); + if (so_array.size() == 0) + return; + for (auto& i : so_array) { + if (i.empty()) + continue; + void* handle = dlopen(i.c_str(), RTLD_NOW | RTLD_NODELETE); + if (handle == nullptr) + _E("fail to load : %s, err : %s", i.c_str(), dlerror()); + else + _D("preload %s# - handle : %p", i.c_str(), handle); + } + } + + static void OnCreate(bundle *extra, int type, void *user_data) { + _I("on create"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + Bundle ex = Bundle(extra, false, false); + string loader_type = ex.GetString(KEY_LOADER_TYPE); + if (loader_type.empty()) { + _E("No loader type"); + return; + } + + if (loader->IsLoaderPriorityEnabled()) + launchpad_loader_set_priority(19); + loader->PreloadLib(ex); + ecore_init(); + setenv("AUL_LOADER_INIT", "1", 1); + + if (loader_type == LOADER_TYPE_SW) + setenv("AUL_HWACC", "none", 1); + else if (loader_type == LOADER_TYPE_HW) + setenv("AUL_HWACC", "hw", 1); + } + + static int OnLaunch(int argc, char **argv, const char *app_path, + const char *appid, const char *pkgid, const char *pkg_type, void *user_data) { + _I("on launch"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + if (!loader->IsPriorityChangeEnabled()) + return 0; + + bundle *kb = launchpad_loader_get_bundle(); + if (kb == nullptr) + return 0; + + Bundle data(kb, false, false); + string high_priority = data.GetString(AUL_K_HIGHPRIORITY); + if (high_priority == "true") + launchpad_loader_set_priority(-12); + data.Delete(AUL_K_HIGHPRIORITY); + return 0; + } + + void DoExec(string libdir) { + _I("do exec"); + char err_str[MAX_LOCAL_BUFSZ]; + if (access(argv_[LOADER_ARG_PATH], F_OK | R_OK)) { + SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)", argv_[LOADER_ARG_PATH], errno, + strerror_r(errno, err_str, sizeof(err_str))); + } else { + SECURE_LOGD("[candidate] Exec application (%s)", + argv_[LOADER_ARG_PATH]); + _close_all_fds(); + if (!libdir.empty()) + setenv("LD_LIBRARY_PATH", libdir.c_str(), 1); + unsetenv("AUL_LOADER_INIT"); + unsetenv("AUL_HWACC"); + if (execv(argv_[LOADER_ARG_PATH], argv_) < 0) { + _send_message_to_logger(argv_[LOADER_ARG_PATH], + "Failed to execute a file. error(%d:%s)", errno, + strerror_r(errno, err_str, sizeof(err_str))); + } + } + } + + int DoDlOpen(bool restore, string old_cwd, string libdir) { + _I("do dlopen"); + string hwc_message = "" + to_string(getpid()) + "|lib loading start"; + prctl(PR_TASK_PERF_USER_TRACE, hwc_message.c_str(), hwc_message.size()); + void* handle = dlopen(argv_[LOADER_ARG_PATH], + RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE); + if (handle == nullptr) { + _E("dlopen(%s) is failed. error(%s)", argv_[LOADER_ARG_PATH], dlerror()); + DoExec(libdir); + return -1; + } + + hwc_message = "" + to_string(getpid()) + "|lib loading end"; + prctl(PR_TASK_PERF_USER_TRACE, hwc_message.c_str(), hwc_message.size()); + + if (restore && chdir(old_cwd.c_str())) + _E("failed to chdir: %d", errno); + + void* dl_main = dlsym(handle, "main"); + if (dl_main == nullptr) { + _E("dlsym not founded(%s). Please export 'main' function", dlerror()); + dlclose(handle); + DoExec(libdir); + return -1; + } + + _I("call main"); + return ((int (*)(int, char**))dl_main)(argc_, argv_); + } + + static int OnTerminate(int argc, char **argv, void *user_data) { + SECURE_LOGD("[candidate] Launch real application (%s)", argv[LOADER_ARG_PATH]); + char old_cwd[PATH_MAX] = {0, }; + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + if (getcwd(old_cwd, sizeof(old_cwd)) == nullptr) { + loader->DoDlOpen(false, old_cwd, ""); + } else { + char* libdir = _get_libdir(argv[LOADER_ARG_PATH]); + if (libdir == NULL) { + return loader->DoDlOpen(false, old_cwd, ""); + } else { + /* To support 2.x applications which use their own shared libraries. + * We set '-rpath' to make the dynamic linker looks in the CWD forcely, + * so here we change working directory to find shared libraries well. + */ + bool restore = false; + if (chdir(libdir)) + _E("failed to chdir: %d", errno); + else + restore = true; + string libdir_str = string(libdir); + free(libdir); + return loader->DoDlOpen(restore, old_cwd, libdir_str); + } + } + return -1; + } + + static void OnLoopBegin(void* user_data) { + _I("on loop begin"); + ecore_main_loop_begin(); + } + + static void OnLoopQuit(void* user_data) { + _I("on loop quit"); + ecore_main_loop_quit(); + } + + static void OnAddFd(void* user_data, int fd, + loader_receiver_cb receiver) { + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd, + (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR), + FdHandler, loader, nullptr, nullptr); + if (handler == nullptr) { + _E("fd_handler is NULL"); + close(fd); + exit(-1); + } + _I("set handler done (%d)", fd); + loader->SetFdHandler(handler); + loader->SetReceiver(receiver); + } + + static Eina_Bool FdHandler(void *user_data, Ecore_Fd_Handler *handler) { + _I("fd handler"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + int fd = ecore_main_fd_handler_fd_get(handler); + if (fd == -1) { + _E("[candidate] ECORE_FD_GET"); + exit(-1); + } + if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) { + if (loader->GetReceiver()) + loader->GetReceiver()(fd); + } else if (ecore_main_fd_handler_active_get( + handler, ECORE_FD_ERROR)) { + _E("[candidate] ECORE_FD_ERROR"); + close(fd); + exit(-1); + } + return ECORE_CALLBACK_CANCEL; + } + + static void OnRemoveFd(void *user_data, int fd) { + _I("remove fd"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + if (loader->GetFdHandler() == nullptr) + return; + ecore_main_fd_handler_del(loader->GetFdHandler()); + loader->SetFdHandler(nullptr); + loader->SetReceiver(nullptr); + } + + private: + shared_ptr lifecycle_cb_ = nullptr; + shared_ptr adapter_ = nullptr; + bool loader_priority_enabled_ = false; + bool priority_change_enabled_ = false; + loader_receiver_cb receiver_cb_; + Ecore_Fd_Handler* fd_handler_ = nullptr; + int argc_; + char** argv_; +}; + +} + +C_EXPORT int main(int argc, char **argv) +{ + launchpad::AppDefinedLoader loader(argc, argv); + +#ifdef TIZEN_FEATURE_LOADER_PRIORITY + loader->SetLoaderPriority(true); +#endif +#ifdef TIZEN_FEATURE_PRIORITY_CHANGE + loader->SetPriorityChanged(true); +#endif + + return launchpad_loader_main(argc, argv, + loader.GetLifeCycle().get(), loader.GetAdapter().get(), &loader); +} \ No newline at end of file diff --git a/src/common/inc/launchpad_common.h b/src/common/inc/launchpad_common.h index dc60559..5d97b77 100644 --- a/src/common/inc/launchpad_common.h +++ b/src/common/inc/launchpad_common.h @@ -17,7 +17,9 @@ #ifndef __LAUNCHPAD_COMMON_H__ #define __LAUNCHPAD_COMMON_H__ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include #include @@ -57,6 +59,11 @@ #define PAD_LOADER_ID_DIRECT 1 #define PAD_LOADER_ID_DYNAMIC_BASE 10 +#define KEY_LOADER_TYPE "loader_type" +#define LOADER_TYPE_COMMON "common-loader" +#define LOADER_TYPE_HW "hw-loader" +#define LOADER_TYPE_SW "sw-loader" + #define _E(fmt, arg...) LOGE(fmt, ##arg) #define _D(fmt, arg...) LOGD(fmt, ##arg) #define _W(fmt, arg...) LOGW(fmt, ##arg) @@ -72,6 +79,10 @@ #define ARRAY_SIZE(x) ((sizeof(x)) / sizeof(x[0])) #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) +#ifdef __cplusplus +extern "C" { +#endif + typedef struct _app_pkt_t { int cmd; int len; @@ -125,5 +136,8 @@ int _verify_proc_caps(void); int _prepare_id_file(void); void _print_hwc_log(const char *format, ...); +#ifdef __cplusplus +} +#endif #endif /* __LAUNCHPAD_COMMON_H__ */ diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 6d7b43b..f1a7d09 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -1600,7 +1600,6 @@ static int __dispatch_cmd_add_loader(bundle *kb) static int __dispatch_cmd_add_app_defined_loader(bundle *kb) { const char *loader_name; - const char *loader_path; int lid, len; candidate_process_context_t *cpc; const loader_info_t *info; @@ -1614,15 +1613,10 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) return -EINVAL; } - /* TODO: use app-defined-loader */ - loader_path = _loader_info_find_loader_path_by_loader_name( - loader_info_list, COMMON_LOADER_NAME); - info = _loader_info_find_loader_by_loader_name( app_defined_loader_info_list, loader_name); - if (loader_path == NULL || info == NULL || info->extra == NULL) { - _E("loader_name %s, loader_path %d, info %d", - loader_name, loader_path != NULL, info != NULL); + if (info == NULL || info->extra == NULL) { + _E("loader_name %s, info %d", loader_name, info != NULL); return -EINVAL; } @@ -1630,7 +1624,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) lid = __make_loader_id(); cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, 0, - loader_path, (const char *)extra, + "/usr/bin/app-defined-loader", (const char *)extra, METHOD_TIMEOUT | METHOD_VISIBILITY, METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, METHOD_TTL | METHOD_OUT_OF_MEMORY, diff --git a/src/loader/src/launchpad_loader.c b/src/loader/src/launchpad_loader.c index 4dc371e..fee50e6 100644 --- a/src/loader/src/launchpad_loader.c +++ b/src/loader/src/launchpad_loader.c @@ -37,11 +37,6 @@ #define PR_TASK_PERF_USER_TRACE 666 #endif -#define KEY_LOADER_TYPE "loader_type" -#define LOADER_TYPE_COMMON "common-loader" -#define LOADER_TYPE_HW "hw-loader" -#define LOADER_TYPE_SW "sw-loader" - #define PATH_LIB_VC_ELM "/usr/lib/libvc-elm.so.0" extern bundle *launchpad_loader_get_bundle(void); -- 2.7.4