From 13fe83911cd9f9d12eb0826c9e32ac36a77a237a Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 11 Mar 2016 16:39:47 +0900 Subject: [PATCH 01/16] fix launch_on_event failure. And, remove gathering appinfo for globalappuser (it's not needed) Change-Id: I9752e8b8b47ea3dc28258b96b7e64f443b74321c Signed-off-by: jongmyeongko --- CMakeLists.txt | 2 +- src/esd_main.c | 21 ++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d620f0..6d1c5e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ ENDFOREACH(flag) ## Additional flag SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") ## Linker flags diff --git a/src/esd_main.c b/src/esd_main.c index 1632334..9d9af13 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -729,9 +729,10 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) char event_uri[1024]; bundle *b; - _D("launch_on_event: app_id(%s), event_name(%s)", app_id, eep->event_name); + _D("launch_on_event: app_id(%s), event_name(%s), uid(%d)", + app_id, eep->event_name, uid); - if (aul_app_is_running_for_uid(app_id, uid)) { + if (!aul_app_is_running_for_uid(app_id, uid)) { snprintf(event_uri, sizeof(event_uri), "event://%s", eep->event_name); b = bundle_dup(eep->event_data); appsvc_set_operation(b, APPSVC_OPERATION_LAUNCH_ON_EVENT); @@ -743,7 +744,7 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) bundle_free(b); } else { - _D("already is running"); + _D("already is running or launch failed"); } } @@ -1529,7 +1530,6 @@ static void __esd_on_name_lost(GDBusConnection *connection, static int __esd_before_loop(void) { int ret = 0; - uid_t uid = 0; GError *error = NULL; guint owner_id = 0; @@ -1656,19 +1656,6 @@ static int __esd_before_loop(void) #endif event_launch_table = g_hash_table_new(g_str_hash, g_str_equal); - - _I("get event launch list"); - - /* get global user info */ - uid = GLOBAL_USER; - ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, uid, &uid); - if (ret < 0) { - _E("failed to get global-app list (%d)", ret); - return ES_R_ERROR; - } - - __esd_launch_table_print_items(); - trusted_busname_table = g_hash_table_new(g_str_hash, g_str_equal); /* gdbus setup for method call */ -- 2.7.4 From ed605f806fc5ab5a5dc118e8fb6e6909f8dae995 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 16 Mar 2016 21:25:10 +0900 Subject: [PATCH 02/16] support new system-event (outgoing msg) Change-Id: Ic423795ff9a39b5eb34bb97662cdb7d30841c103 Signed-off-by: jongmyeongko --- src/esd_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index 9d9af13..b3c7732 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -30,7 +30,8 @@ static const char *event_launch_support_list[] = { SYS_EVENT_BATTERY_CHARGER_STATUS, SYS_EVENT_USB_STATUS, SYS_EVENT_EARJACK_STATUS, - SYS_EVENT_INCOMMING_MSG + SYS_EVENT_INCOMMING_MSG, + SYS_EVENT_OUTGOING_MSG }; struct privilege_info { @@ -41,7 +42,8 @@ struct privilege_info { static const struct privilege_info privilege_check_list[] = { {SYS_EVENT_DISPLAY_STATE, "http://tizen.org/privilege/display"}, {SYS_EVENT_WIFI_STATE, "http://tizen.org/privilege/network.get"}, - {SYS_EVENT_INCOMMING_MSG, "http://tizen.org/privilege/message.read"} + {SYS_EVENT_INCOMMING_MSG, "http://tizen.org/privilege/message.read"}, + {SYS_EVENT_OUTGOING_MSG, "http://tizen.org/privilege/message.read"} }; static int privilege_check_size = sizeof(privilege_check_list)/sizeof(struct privilege_info); -- 2.7.4 From 7e4d97529e754ad247ac568920793529e2e631e0 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 14 Mar 2016 20:11:46 +0900 Subject: [PATCH 03/16] check return value of bundle_get_val Change-Id: I4791f876766867ecf6cedf29c899a93fa114ae26 Signed-off-by: Jiwoong Im --- src/esd_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index b3c7732..f627068 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -779,17 +779,17 @@ static void __esd_launch_event_handler(char *event_name, bundle *data, void *use if (strcmp(SYS_EVENT_BATTERY_CHARGER_STATUS, event_name) == 0) { val = bundle_get_val(data, EVT_KEY_BATTERY_CHARGER_STATUS); _D("charger val(%s)", val); - if (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0) + if (val && (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0)) return; } else if (strcmp(SYS_EVENT_USB_STATUS, event_name) == 0) { val = bundle_get_val(data, EVT_KEY_USB_STATUS); _D("usb val(%s)", val); - if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) + if (val && (strcmp(EVT_VAL_USB_CONNECTED, val) != 0)) return; } else if (strcmp(SYS_EVENT_EARJACK_STATUS, event_name) == 0) { val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); _D("earjack val(%s)", val); - if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) + if (val && (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0)) return; } else if (strcmp(SYS_EVENT_INCOMMING_MSG, event_name) == 0) { msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); -- 2.7.4 From 4103413a84971a457eb5cafa7eaef6fbfbc27f0f Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 7 Mar 2016 17:23:38 +0900 Subject: [PATCH 04/16] reduce memroy usage - getting svcapp list by using pkgmgr_info_filter api - fix g_varient_get related leak Change-Id: Iddabaade6efbd16fc8228b083ef5fc9a98e40be1 Signed-off-by: Jiwoong Im --- include/eventsystem_daemon.h | 16 ++++-- src/esd_main.c | 117 ++++++++++++++++++++++++------------------- 2 files changed, 76 insertions(+), 57 deletions(-) diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h index a06821d..773c315 100644 --- a/include/eventsystem_daemon.h +++ b/include/eventsystem_daemon.h @@ -25,11 +25,6 @@ extern "C" { #endif - -#ifdef __cplusplus -} -#endif - #undef LOG_TAG #define LOG_TAG "ESD" @@ -38,9 +33,20 @@ extern "C" { #define _W(fmt, arg...) LOGW(fmt, ##arg) #define _I(fmt, arg...) LOGI(fmt, ##arg) +#define FREE_AND_NULL(ptr) do { \ + if (ptr) { \ + free((void *)ptr); \ + ptr = NULL; \ + } \ +} while (0) + #define ESD_BOOT_COMPLETED "/tmp/esd_ready" int __esd_register_vconf_callbacks(void); +#ifdef __cplusplus +} +#endif + #endif /* __EVENTSYSTEM_DAEMONE_H__ */ diff --git a/src/esd_main.c b/src/esd_main.c index f627068..89b9ebd 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -935,7 +935,7 @@ static void __esd_filter_name_owner_changed(GDBusConnection *connection, int old_len = 0; int new_len = 0; - g_variant_get(parameters, "(sss)", &name, &old_owner, &new_owner); + g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner); if (strstr(name, "event.busname.session")) { old_len = strlen(old_owner); @@ -973,6 +973,7 @@ static int __esd_get_user_items(void) int i = 0; uid_t *uids = NULL; uid_t cur_uid = 0; + pkgmgrinfo_appinfo_filter_h handle = NULL; ret = sd_get_uids(&uids); if (ret < 0) { @@ -989,9 +990,30 @@ static int __esd_get_user_items(void) cur_uid = uids[i]; _I("found uid(%d)", cur_uid); - ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, cur_uid, &cur_uid); - if (ret < 0) - _E("failed to get user(%d)-app list (%d)", cur_uid, ret); + ret = pkgmgrinfo_appinfo_filter_create(&handle); + if (ret < 0) { + _E("failed to create appinfo filter"); + return ES_R_ERROR; + } + ret = pkgmgrinfo_appinfo_filter_add_string(handle, + PMINFO_APPINFO_PROP_APP_COMPONENT, "svcapp"); + if (ret < 0) { + _E("failed to add appinfo filter string"); + return ES_R_ERROR; + } + ret = pkgmgrinfo_appinfo_filter_add_string(handle, + PMINFO_APPINFO_PROP_APP_OPERATION, APPSVC_OPERATION_LAUNCH_ON_EVENT); + if (ret < 0) { + _E("failed to add appinfo filter string"); + return ES_R_ERROR; + } + ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, + __esd_add_appinfo_handler, &cur_uid, cur_uid); + if (ret < 0) { + _E("appinfo filter foreach error"); + return ES_R_ERROR; + } + pkgmgrinfo_appinfo_filter_destroy(handle); } } @@ -1202,7 +1224,7 @@ static void check_sender_valid_method_call(GDBusConnection *connection, const gc int event_sender_pid = 0; uid_t sender_uid = 0; - g_variant_get(parameters, "(is)", &event_sender_pid, &event_name); + g_variant_get(parameters, "(i&s)", &event_sender_pid, &event_name); _D("event_sender_pid(%d), event_name(%s)", event_sender_pid, event_name); sender_uid = (uid_t)__get_sender_uid(connection, sender); @@ -1232,7 +1254,7 @@ static void check_send_event_valid_method_call(GDBusConnection *connection, cons int sender_pid = 0; uid_t sender_uid = 0; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); @@ -1271,7 +1293,7 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha char *_busname = NULL; trusted_item *item; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); @@ -1318,7 +1340,7 @@ static void setup_trusted_peer_method_call(GDBusConnection *connection, const gc uid_t sender_uid = 0; int ret = 0; - g_variant_get(parameters, "(ss)", &event_name, &destination_name); + g_variant_get(parameters, "(&s&s)", &event_name, &destination_name); _D("event_name(%s), destination_name(%s)", event_name, destination_name); if (destination_name && destination_name[0] != '\0') { @@ -1361,7 +1383,7 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const char *user = NULL; int ret = 0; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); __esd_check_privilege_name(event_name, &privilege_name); _D("event_name(%s), privilege_name(%s)", event_name, privilege_name); @@ -1422,7 +1444,7 @@ static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvoca int len = 0; earlier_item *item; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); if (event_name && strlen(event_name) > 0) { _D("event_name(%s)", event_name); @@ -1745,7 +1767,6 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da { char *appid = NULL; char *pkgid = NULL; - pkgmgrinfo_app_component component_type; int ret = 0; uid_t *p_uid = NULL; @@ -1756,65 +1777,57 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da p_uid = (uid_t *)data; - ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); + ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); if (ret < 0) { _E("failed to get appid"); return ES_R_ERROR; } - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); + ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); if (ret < 0) { - _E("failed to get pkgid"); + _E("failed to get appid"); return ES_R_ERROR; } - ret = pkgmgrinfo_appinfo_get_component(handle, &component_type); - if (ret != PMINFO_R_OK) { - _E("fail to get component type"); - return ES_R_ERROR; - } + esd_appctrl_cb_data *cb_data = calloc(1, sizeof(esd_appctrl_cb_data)); - _D("uid(%d), appid(%s), component_type(%d)", *p_uid, appid, component_type); - if (component_type == PMINFO_SVC_APP) { - esd_appctrl_cb_data *cb_data = calloc(1, sizeof(esd_appctrl_cb_data)); - if (cb_data == NULL) { - _E("memory alloc failed"); - return ES_R_ENOMEM; - } - cb_data->appid = strdup(appid); - if (cb_data->appid == NULL) { - _E("out_of_memory"); - FREE_AND_NULL(cb_data); - return ES_R_ENOMEM; - } - cb_data->pkgid = strdup(pkgid); - if (cb_data->pkgid == NULL) { - _E("out_of_memory"); - FREE_AND_NULL(cb_data->appid); - FREE_AND_NULL(cb_data); - return ES_R_ENOMEM; - } - cb_data->uid = *p_uid; - ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, - (pkgmgrinfo_app_control_list_cb)__esd_appcontrol_cb, cb_data); - - FREE_AND_NULL(cb_data->pkgid); + if (cb_data == NULL) { + _E("memory alloc failed"); + return ES_R_ENOMEM; + } + cb_data->appid = strdup(appid); + if (cb_data->appid == NULL) { + _E("out_of_memory"); + FREE_AND_NULL(cb_data); + return ES_R_ENOMEM; + } + cb_data->pkgid = strdup(pkgid); + if (cb_data->pkgid == NULL) { + _E("out_of_memory"); FREE_AND_NULL(cb_data->appid); FREE_AND_NULL(cb_data); + return ES_R_ENOMEM; + } + cb_data->uid = *p_uid; - if (ret < 0) { - _E("failed to get appcontrol info"); - return ES_R_ERROR; - } - __esd_launch_table_print_items(); + ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, + (pkgmgrinfo_app_control_list_cb)__esd_appcontrol_cb, cb_data); + + FREE_AND_NULL(cb_data->pkgid); + FREE_AND_NULL(cb_data->appid); + FREE_AND_NULL(cb_data); + + if (ret < 0) { + _E("failed to get appcontrol info"); + return ES_R_ERROR; } return ES_R_OK; } -static int __esd_pkgmgr_event_callback(uid_t target_uid, int req_id, const char *pkg_type, - const char *pkgid, const char *key, const char *val, - const void *pmsg, void *data) +static int __esd_pkgmgr_event_callback(uid_t target_uid, int req_id, + const char *pkg_type, const char *pkgid, const char *key, + const char *val, const void *pmsg, void *data) { esd_pkgmgr_event *pkg_event = (esd_pkgmgr_event *)data; pkgmgrinfo_pkginfo_h handle = NULL; -- 2.7.4 From 3bed6a84a0b988d8473b7f8f4981dfb164dda7c1 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 8 Apr 2016 10:40:31 +0900 Subject: [PATCH 05/16] move esd.service to graphical.taget.wants Change-Id: I70676579edef6c9d22553145ccdde6310d6758d3 Signed-off-by: Jiwoong Im --- packaging/esd.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/esd.spec b/packaging/esd.spec index 74fd236..06fb481 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -55,9 +55,9 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}%{_unitdir}/default.target.wants +mkdir -p %{buildroot}%{_unitdir}/graphical.target.wants install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/esd.service -ln -sf ../esd.service %{buildroot}%{_unitdir}/default.target.wants/esd.service +ln -sf ../esd.service %{buildroot}%{_unitdir}/graphical.target.wants/esd.service mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} @@ -71,7 +71,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %defattr(-,root,root,-) %{_bindir}/esd %{_unitdir}/esd.service -%{_unitdir}/default.target.wants/esd.service +%{_unitdir}/graphical.target.wants/esd.service /usr/share/license/%{name} %files devel -- 2.7.4 From c05da81c51d3493cfbaad1d5d781faa47ae9cb87 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 19 Feb 2016 11:16:54 +0900 Subject: [PATCH 06/16] change uid from 'root' to 'app_fw' Change-Id: I48ccf659800a64af893b084cf8bb089cfcb5272e Signed-off-by: jongmyeongko --- packaging/esd.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/esd.service b/packaging/esd.service index 763da0a..78bda75 100644 --- a/packaging/esd.service +++ b/packaging/esd.service @@ -3,6 +3,8 @@ Description=Start the Event System Daemon After=dbus.service [Service] +User=app_fw +Group=app_fw ExecStart=/usr/bin/esd Restart=always RestartSec=0 -- 2.7.4 From c34684a9fbbebca2b66e0c4dccf72b16ab227027 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 6 Jul 2016 13:47:09 +0900 Subject: [PATCH 07/16] add user which sends system event in dbus conf file Change-Id: I3a8c17139f27f3762cc0c01fc194c7895a100afe Signed-off-by: Jiwoong Im --- eventsystem.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eventsystem.conf b/eventsystem.conf index 2773b2f..48953d2 100644 --- a/eventsystem.conf +++ b/eventsystem.conf @@ -13,7 +13,7 @@ - + -- 2.7.4 From dfe05dc31d2605642d9f58b12731f247568414e0 Mon Sep 17 00:00:00 2001 From: jooseong lee Date: Wed, 20 Jul 2016 20:23:43 +0900 Subject: [PATCH 08/16] Set the SMACK security label to run given executable file in systemd services Change-Id: Iff87dff3c7ce6732d49dc7fb71de22257cc149f6 Signed-off-by: jooseong lee --- packaging/esd.service | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/esd.service b/packaging/esd.service index 78bda75..1cab817 100644 --- a/packaging/esd.service +++ b/packaging/esd.service @@ -5,6 +5,7 @@ After=dbus.service [Service] User=app_fw Group=app_fw +SmackProcessLabel=System ExecStart=/usr/bin/esd Restart=always RestartSec=0 -- 2.7.4 From ec0dcb89a86dad34d00c537e636efed0f3f03827 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 29 Jun 2016 22:49:55 +0900 Subject: [PATCH 09/16] support eventsystem_keep_last_event_data api Change-Id: I3cdad951b79f69ae08d25859a53f4ef4659dfecb Signed-off-by: Jiwoong Im --- src/esd_main.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/src/esd_main.c b/src/esd_main.c index 89b9ebd..cad7621 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -24,6 +24,10 @@ #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) #define ROOT_USER 0 +#define SYS_EVENT_NAME_PREFIX "tizen.system.event" +#define SYS_EVENT_OBJ_PATH "/tizen/system/event" +#define REQUEST_LAST_DATA "request_last_data" + static GHashTable *event_launch_table; /* table of events for launch_on_event*/ static const char *event_launch_support_list[] = { @@ -68,6 +72,16 @@ typedef struct __earlier_table_item { static bool g_is_bootcompleted = false; #endif +static GHashTable *user_last_event_table; /* table of user events for last data */ + +struct __last_event_item { + char *key; + char *app_id; + char *event_name; + char *own_name; + uid_t uid; +}; + static GHashTable *trusted_busname_table; /* table of dbus bus-names for trusted user-event */ typedef struct __trusted_busname_item { @@ -152,6 +166,17 @@ static void __esd_finish_cynara(void) r_cynara = NULL; } +static void free_saved_event(struct __last_event_item *item) +{ + if (!item) + return; + + free(item->event_name); + free(item->own_name); + free(item->app_id); + free(item); +} + #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE static int __esd_check_earlier_support(const char *event_name) { @@ -1136,6 +1161,16 @@ static const gchar introspection_xml[] = " " " " #endif +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " " " ""; @@ -1473,6 +1508,157 @@ static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvoca } #endif +static void keep_last_data_method_call(GDBusConnection *connection, + const gchar *sender, GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + GVariant *param; + int result = ES_R_OK; + char *event_name; + char *own_name; + char *key; + char app_id[128]; + int sender_pid; + uid_t sender_uid; + struct __last_event_item *item; + + g_variant_get(parameters, "(&s&s)", &event_name, &own_name); + + if (!event_name || !own_name) { + result = ES_R_ERROR; + _E("invalid event_name and own_name"); + goto out; + } + + sender_pid = __get_sender_pid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, + sizeof(app_id)) < 0) { + _E("failed to get appid by pid"); + result = ES_R_ERROR; + goto out; + } + + key = (char *)malloc(sizeof(event_name) + 10); + if (!key) { + result = ES_R_ENOMEM; + _E("out of memory"); + goto out; + } + + snprintf(key, sizeof(event_name) + 10, "%s_%d", event_name, sender_uid); + item = (struct __last_event_item *)g_hash_table_lookup(user_last_event_table, + key); + if (!item) { + item = calloc(1, sizeof(*item)); + if (!item) { + result = ES_R_ERROR; + goto out; + } + item->key = key; + item->event_name = strdup(event_name); + item->own_name = strdup(own_name); + item->uid = sender_uid; + item->app_id = strdup(app_id); + g_hash_table_insert(user_last_event_table, + item->key, item); + } else { + free(item->own_name); + item->own_name = strdup(own_name); + } + +out: + param = g_variant_new("(i)", result); + + g_dbus_method_invocation_return_value(invocation, param); +} + +static void check_last_data_method_call(GDBusConnection *connection, + const gchar *sender, GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + GVariant *param; + int result = ES_R_OK; + char *event_name; + char *own_name; + char *key; + char app_id[128]; + int sender_pid; + uid_t sender_uid; + struct __last_event_item *item; + + g_variant_get(parameters, "(&s&s)", &event_name, &own_name); + + if (!event_name || !own_name) { + result = ES_R_ERROR; + _E("invalid event_name and own_name"); + goto out; + } + + sender_pid = __get_sender_pid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, + sizeof(app_id)) < 0) { + result = ES_R_ERROR; + _E("failed to get appid by pid"); + goto out; + } + + key = (char *)malloc(sizeof(event_name) + 10); + if (!key) { + result = ES_R_ENOMEM; + _E("out of memory"); + goto out; + } + + snprintf(key, sizeof(event_name) + 10, "%s_%d", event_name, sender_uid); + item = (struct __last_event_item *)g_hash_table_lookup(user_last_event_table, + key); + free(key); + if (item) { + GVariant *gv; + bundle *b; + bundle_raw *raw; + int len; + int ret; + GError *error = NULL; + + b = bundle_create(); + if (!b) { + result = ES_R_ERROR; + goto out; + } + bundle_add_str(b, EVT_KEY_KEPT_EVENT_NAME, event_name); + bundle_add_str(b, EVT_KEY_KEPT_OWN_NAME, own_name); + if (__esd_check_certificate_match(item->uid, item->app_id, + sender_uid, app_id) == ES_R_OK) + bundle_add_str(b, EVT_KEY_KEPT_IS_TRUSTED, "true"); + else + bundle_add_str(b, EVT_KEY_KEPT_IS_TRUSTED, "false"); + + bundle_encode(b, &raw, &len); + gv = g_variant_new("(us)", len, raw); + ret = g_dbus_connection_emit_signal(connection, + item->own_name, + SYS_EVENT_OBJ_PATH, + SYS_EVENT_NAME_PREFIX, + REQUEST_LAST_DATA, + gv, + &error); + if (ret == FALSE) { + _E("Unable to emit signal: %s", error->message); + g_error_free(error); + } + bundle_free_encoded_rawdata(&raw); + bundle_free(b); + } + +out: + param = g_variant_new("(i)", result); + + g_dbus_method_invocation_return_value(invocation, param); +} + static void handle_method_call(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, @@ -1493,6 +1679,10 @@ static void handle_method_call(GDBusConnection *connection, } else if (g_strcmp0(method_name, "GetEarlierData") == 0) { get_earlier_data_method_call(parameters, invocation); #endif + } else if (g_strcmp0(method_name, "KeepLastData") == 0) { + keep_last_data_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "CheckLastData") == 0) { + check_last_data_method_call(connection, sender, parameters, invocation); } } @@ -1570,6 +1760,8 @@ static int __esd_before_loop(void) earlier_item *item; earlier_event_table = g_hash_table_new(g_str_hash, g_str_equal); + user_last_event_table = g_hash_table_new_full(g_str_hash, + g_str_equal, NULL, (GDestroyNotify)free_saved_event); _I("register events for earlier_data"); size = sizeof(earlier_event_list)/sizeof(*earlier_event_list); @@ -1993,6 +2185,8 @@ static void __esd_finalize(void) } g_hash_table_unref(earlier_event_table); } + + g_hash_table_destroy(user_last_event_table); #endif if (event_launch_table) { -- 2.7.4 From 52454fecdce7ba8150942837bf436603963e47bc Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 11 Nov 2016 20:12:20 +0900 Subject: [PATCH 10/16] Fix memory leak Change-Id: I9043d191af121746400d74780dc6a31d1aa1f2d5 Signed-off-by: Hwankyu Jhun --- src/esd_system_event.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/esd_system_event.c b/src/esd_system_event.c index 339833b..12fd9ee 100644 --- a/src/esd_system_event.c +++ b/src/esd_system_event.c @@ -214,6 +214,8 @@ static void __esd_vconfcb_language_set(keynode_t *node, void *user_data) if (b) bundle_free(b); + if (str) + free(str); } static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) @@ -273,6 +275,8 @@ static void __esd_vconfcb_region_format(keynode_t *node, void *user_data) if (b) bundle_free(b); + if (str) + free(str); } static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) @@ -524,6 +528,8 @@ static void __esd_vconfcb_font_set(keynode_t *node, void *user_data) if (b) bundle_free(b); + if (str) + free(str); } static struct esd_vconf_handler vconf_callbacks[] = { -- 2.7.4 From 795ce64354c9e6d54359ac226aece8c1bc5cec3f Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Thu, 10 Nov 2016 20:27:03 +0900 Subject: [PATCH 11/16] replace ecore_main_loop to g_main_loop Change-Id: I3b232d30a681beeacb45a213b1a084c6121af014 Signed-off-by: Jiwoong Im --- CMakeLists.txt | 2 +- include/eventsystem_daemon.h | 4 ++ packaging/esd.spec | 1 - src/esd_main.c | 104 +++++++++++++++---------------------------- 4 files changed, 42 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d1c5e7..58baf5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) ### Required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED dlog bundle pkgmgr-info glib-2.0 gio-2.0 appsvc aul ecore vconf libtzplatform-config libsystemd-daemon cynara-client cynara-creds-gdbus cynara-session security-manager) +pkg_check_modules(pkgs REQUIRED dlog bundle pkgmgr-info glib-2.0 gio-2.0 appsvc aul vconf libtzplatform-config libsystemd-daemon cynara-client cynara-creds-gdbus cynara-session security-manager) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h index 773c315..9fa24ce 100644 --- a/include/eventsystem_daemon.h +++ b/include/eventsystem_daemon.h @@ -42,6 +42,10 @@ extern "C" { #define ESD_BOOT_COMPLETED "/tmp/esd_ready" +#define LOGIND_INTERFACE "org.freedesktop.login1.Manager" +#define LOGIND_PATH "/org/freedesktop/login1" +#define LOGIND_SIGNAL_USER_NEW "UserNew" + int __esd_register_vconf_callbacks(void); #ifdef __cplusplus diff --git a/packaging/esd.spec b/packaging/esd.spec index 06fb481..2c70904 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -7,7 +7,6 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: esd.service BuildRequires: cmake -BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(dlog) diff --git a/src/esd_main.c b/src/esd_main.c index cad7621..7c9e270 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -1,10 +1,10 @@ #include +#include #include #include #include #include #include -#include #include #include #include @@ -132,9 +132,6 @@ typedef struct esd_info { } esd_info_s; static esd_info_s s_info; -static Ecore_Fd_Handler *g_fd_handler; -sd_login_monitor *g_sd_monitor; - typedef struct __esd_appctrl_cb_data { char *appid; char *pkgid; @@ -1047,64 +1044,21 @@ static int __esd_get_user_items(void) return ES_R_OK; } -static Eina_Bool __esd_fd_handler_func(void *data, Ecore_Fd_Handler *fd_handler) +static void __esd_signal_handler(GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) { - if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { - _I("fd read"); - __esd_get_user_items(); - } - - return ECORE_CALLBACK_CANCEL; -} - -static int __esd_start_sd_monitor(void) -{ - int ret = 0; - int fd = 0; - - ret = __esd_get_user_items(); - if (ret < 0) - return ES_R_ERROR; - - ret = sd_login_monitor_new("uid", &g_sd_monitor); - if (ret < 0) { - _E("sd_login_monitor_new error (%d)", ret); - return ES_R_ERROR; - } - - fd = sd_login_monitor_get_fd(g_sd_monitor); - if (fd < 0) { - _E("sd_login_monitor_get_fd error"); - sd_login_monitor_unref(g_sd_monitor); - return ES_R_ERROR; - } - - g_fd_handler = ecore_main_fd_handler_add(fd, - (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR), - __esd_fd_handler_func, NULL, NULL, NULL); - if (g_fd_handler == NULL) { - _E("fd_handler is NULL"); - sd_login_monitor_unref(g_sd_monitor); - return ES_R_ERROR; - } - - _I("setup sd-monitor done"); - - return ES_R_OK; -} - -static int __esd_stop_sd_monitor(void) -{ - _I("stop sd_monitor"); - if (g_fd_handler) { - ecore_main_fd_handler_del(g_fd_handler); - g_fd_handler = NULL; - } - - sd_login_monitor_unref(g_sd_monitor); - g_sd_monitor = 0; + guint uid; + if (g_strcmp0(signal_name, LOGIND_SIGNAL_USER_NEW)) + return; - return ES_R_OK; + g_variant_get(parameters, "(uo)", &uid, NULL); + _I("New user login(%d)", uid); + __esd_get_user_items(); } static GDBusNodeInfo *introspection_data; @@ -1698,6 +1652,7 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, _I("bus acquired(%s)", name); guint reg_id = 0; + guint s_id = 0; GError *error = NULL; reg_id = g_dbus_connection_register_object(connection, @@ -1709,6 +1664,22 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, _E("g_dbus_connection_register_object error(%s)", error->message); g_error_free(error); } + + s_id = g_dbus_connection_signal_subscribe(connection, + NULL, + LOGIND_INTERFACE, + LOGIND_SIGNAL_USER_NEW, + LOGIND_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __esd_signal_handler, + NULL, + NULL); + + if (s_id == 0) { + _E("g_dbus_connection_signal_subscribe() is failed."); + g_object_unref(connection); + } } static void __esd_on_name_acquired(GDBusConnection *connection, @@ -1730,7 +1701,7 @@ static void __esd_on_name_acquired(GDBusConnection *connection, __esd_trusted_busname_print_items(); - __esd_start_sd_monitor(); + __esd_get_user_items(); __esd_dbus_name_monitor(connection); } @@ -2091,8 +2062,6 @@ static int __esd_init() #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36) g_type_init(); #endif - ecore_init(); - __esd_init_cynara(); client = pkgmgr_client_new(PC_LISTENING); @@ -2150,8 +2119,6 @@ static void __esd_finalize(void) _D("esd finalize"); - __esd_stop_sd_monitor(); - if (trusted_busname_table) { g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { @@ -2224,8 +2191,11 @@ static void __esd_finalize(void) int main(int argc, char *argv[]) { + GMainLoop *mainloop = NULL; _I("event system daemon : main()"); + mainloop = g_main_loop_new(NULL, FALSE); + if (__esd_init() != 0) { _E("ESD Initialization failed!"); return ES_R_ERROR; @@ -2237,13 +2207,13 @@ int main(int argc, char *argv[]) return ES_R_ERROR; } - ecore_main_loop_begin(); + g_main_loop_run(mainloop); _E("shutdown"); __esd_finalize(); - ecore_shutdown(); + g_main_loop_unref(mainloop); return 0; } -- 2.7.4 From 4fb22f7d4b2b3ce8d83bc59970bd486af9b91808 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 18 Nov 2016 10:44:10 +0900 Subject: [PATCH 12/16] Fix CMakeLists.txt To make extendible for adding source & header files. Change-Id: I15f058e2c81aed42b86947bd9a873b69da9b908c Signed-off-by: Jiwoong Im --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58baf5b..68006e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(esd C) +AUX_SOURCE_DIRECTORY(src/ SRCS) SET(VERSION 0.0.1) SET(VERSION_MAJOR 0) @@ -35,10 +36,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ##build eventsystem daemon -add_executable(esd - src/esd_main.c - src/esd_system_event.c -) +add_executable(esd ${SRCS}) TARGET_LINK_LIBRARIES(esd eventsystem pkgmgr-client ${pkgs_LDFLAGS}) SET_TARGET_PROPERTIES(esd PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE") SET_TARGET_PROPERTIES(esd PROPERTIES LINK_FLAGS "-pie") -- 2.7.4 From 89abea5efd475de7364ff06461f21222a5199521 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 14 Nov 2016 19:13:51 +0900 Subject: [PATCH 13/16] send SYS_EVENT_BOOT_COMPLETED event - Listen system & user finished signal which is sent by systemd and send SYS_EVENT_BOOT_COMPLETED event to system session. Change-Id: I8b6768f4abb4526a81f02ac1950f2fff62265d0d Signed-off-by: Jiwoong Im --- include/eventsystem_daemon.h | 8 +-- src/esd_main.c | 124 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 106 insertions(+), 26 deletions(-) diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h index 9fa24ce..a5aaa8f 100644 --- a/include/eventsystem_daemon.h +++ b/include/eventsystem_daemon.h @@ -42,9 +42,11 @@ extern "C" { #define ESD_BOOT_COMPLETED "/tmp/esd_ready" -#define LOGIND_INTERFACE "org.freedesktop.login1.Manager" -#define LOGIND_PATH "/org/freedesktop/login1" -#define LOGIND_SIGNAL_USER_NEW "UserNew" +#define SYSTEMD_DBUS_DEST "org.freedesktop.systemd1" +#define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_DEST ".Manager" +#define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" +#define SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED "StartupFinished" +#define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED "UserSessionStartupFinished" int __esd_register_vconf_callbacks(void); diff --git a/src/esd_main.c b/src/esd_main.c index 7c9e270..c7fb780 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -69,8 +69,9 @@ typedef struct __earlier_table_item { bundle *earlier_data; /* event-data from earlier occurrence */ } earlier_item; -static bool g_is_bootcompleted = false; #endif +static bool system_bootcompleted; +static bool user_bootcompleted; static GHashTable *user_last_event_table; /* table of user events for last data */ @@ -884,7 +885,6 @@ static void __esd_earlier_table_print_items(void) static void __esd_earlier_event_handler(char *event_name, bundle *data, void *user_data) { - int handle; earlier_item *item; _D("event_name(%s)", event_name); @@ -895,15 +895,6 @@ static void __esd_earlier_event_handler(char *event_name, bundle *data, void *us bundle_free(item->earlier_data); item->earlier_data = bundle_dup(data); - - if (!g_is_bootcompleted) { - if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { - handle = creat(ESD_BOOT_COMPLETED, 0640); - if (handle != -1) - close(handle); - g_is_bootcompleted = true; - } - } } } #endif @@ -1044,6 +1035,62 @@ static int __esd_get_user_items(void) return ES_R_OK; } +static int __esd_send_bootcomplete(GDBusConnection *conn, const char *list_name) +{ + GVariant *result; + GError *error = NULL; + GVariantIter *iter; + gchar *str; + GVariant *gv; + bundle *b; + bundle_raw *raw; + int len; + gboolean ret; + + result = g_dbus_connection_call_sync(conn, + "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", + list_name, NULL, G_VARIANT_TYPE("(as)"), G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + + if (result == NULL) { + _E("get (%s) error(%s)", list_name, error->message); + g_error_free(error); + return ES_R_ERROR; + } + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_BOOT_COMPLETED, + EVT_VAL_BOOT_COMPLETED_TRUE); + + bundle_encode(b, &raw, &len); + + g_variant_get(result, "(as)", &iter); + while (g_variant_iter_loop(iter, "s", &str)) { + if (!strstr((const char *)str, "event.busname")) + continue; + + gv = g_variant_new("(us)", (unsigned int)len, raw); + ret = g_dbus_connection_emit_signal(conn, + str, + SYS_EVENT_OBJ_PATH, + SYS_EVENT_NAME_PREFIX, + EVT_KEY_BOOT_COMPLETED, + gv, + &error); + if (ret == FALSE) { + _E("Unable to emit signal: %s", error->message); + g_error_free(error); + } + } + + g_variant_iter_free(iter); + g_variant_unref(result); + bundle_free_encoded_rawdata(&raw); + bundle_free(b); + + return ES_R_OK; +} + static void __esd_signal_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -1052,13 +1099,27 @@ static void __esd_signal_handler(GDBusConnection *connection, GVariant *parameters, gpointer user_data) { - guint uid; - if (g_strcmp0(signal_name, LOGIND_SIGNAL_USER_NEW)) - return; + int handle; - g_variant_get(parameters, "(uo)", &uid, NULL); - _I("New user login(%d)", uid); - __esd_get_user_items(); + if (!g_strcmp0(signal_name, + SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED)) { + _I("System session finished"); + system_bootcompleted = true; + } else if (!g_strcmp0(signal_name, + SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED)) { + _I("User session finished"); + __esd_get_user_items(); + user_bootcompleted = true; + } + + if (system_bootcompleted && user_bootcompleted) { + __esd_send_bootcomplete(connection, "ListNames"); + __esd_send_bootcomplete(connection, "ListActivatableNames"); + + handle = creat(ESD_BOOT_COMPLETED, 0640); + if (handle != -1) + close(handle); + } } static GDBusNodeInfo *introspection_data; @@ -1652,7 +1713,8 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, _I("bus acquired(%s)", name); guint reg_id = 0; - guint s_id = 0; + guint boot_id = 0; + guint user_boot_id = 0; GError *error = NULL; reg_id = g_dbus_connection_register_object(connection, @@ -1665,18 +1727,34 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, g_error_free(error); } - s_id = g_dbus_connection_signal_subscribe(connection, + boot_id = g_dbus_connection_signal_subscribe(connection, + NULL, + SYSTEMD_DBUS_IFACE_MANAGER, + SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED, + SYSTEMD_DBUS_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __esd_signal_handler, + NULL, + NULL); + + if (boot_id == 0) { + _E("g_dbus_connection_signal_subscribe() is failed."); + g_object_unref(connection); + } + + user_boot_id = g_dbus_connection_signal_subscribe(connection, NULL, - LOGIND_INTERFACE, - LOGIND_SIGNAL_USER_NEW, - LOGIND_PATH, + SYSTEMD_DBUS_IFACE_MANAGER, + SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED, + SYSTEMD_DBUS_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __esd_signal_handler, NULL, NULL); - if (s_id == 0) { + if (user_boot_id == 0) { _E("g_dbus_connection_signal_subscribe() is failed."); g_object_unref(connection); } -- 2.7.4 From ba389ed8b790a128a853908952016bca92dc21dd Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 14 Dec 2016 13:36:43 +0900 Subject: [PATCH 14/16] Fix resource leak Change-Id: Ia27ac19283e2b4ffaaba990c7bb8b19a0e1495dd Signed-off-by: Hwankyu Jhun --- src/esd_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index c7fb780..1bbe29d 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -2145,6 +2145,7 @@ static int __esd_init() client = pkgmgr_client_new(PC_LISTENING); if (client == NULL) { _E("set pkgmgr client failed"); + __esd_finish_cynara(); return ES_R_ERROR; } @@ -2154,7 +2155,7 @@ static int __esd_init() ret = pkgmgr_client_free(client); if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - + __esd_finish_cynara(); return ES_R_ENOMEM; } @@ -2164,7 +2165,8 @@ static int __esd_init() ret = pkgmgr_client_free(client); if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - + free(pkg_event); + __esd_finish_cynara(); return ES_R_ERROR; } @@ -2269,19 +2271,25 @@ static void __esd_finalize(void) int main(int argc, char *argv[]) { - GMainLoop *mainloop = NULL; + GMainLoop *mainloop; _I("event system daemon : main()"); mainloop = g_main_loop_new(NULL, FALSE); + if (mainloop == NULL) { + _E("out of memory"); + return ES_R_ERROR; + } if (__esd_init() != 0) { _E("ESD Initialization failed!"); + g_main_loop_unref(mainloop); return ES_R_ERROR; } if (__esd_before_loop() < 0) { _E("ESD failed!"); __esd_finalize(); + g_main_loop_unref(mainloop); return ES_R_ERROR; } -- 2.7.4 From 84ed104e0aa96dd633440ffe4bb0934c836022a8 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 22 Dec 2016 20:47:25 +0900 Subject: [PATCH 15/16] Make esd broadcast boot_complete once. boot_complete system-event will be emitted after system-session finished. Change-Id: Ifb604a813d5f4c2339c17252ddabf14c079308c6 Signed-off-by: jongmyeongko --- include/eventsystem_daemon.h | 1 - src/esd_main.c | 91 +++----------------------------------------- 2 files changed, 6 insertions(+), 86 deletions(-) diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h index a5aaa8f..56f44a0 100644 --- a/include/eventsystem_daemon.h +++ b/include/eventsystem_daemon.h @@ -46,7 +46,6 @@ extern "C" { #define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_DEST ".Manager" #define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" #define SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED "StartupFinished" -#define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED "UserSessionStartupFinished" int __esd_register_vconf_callbacks(void); diff --git a/src/esd_main.c b/src/esd_main.c index 1bbe29d..93e096a 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -70,8 +70,6 @@ typedef struct __earlier_table_item { } earlier_item; #endif -static bool system_bootcompleted; -static bool user_bootcompleted; static GHashTable *user_last_event_table; /* table of user events for last data */ @@ -1035,62 +1033,6 @@ static int __esd_get_user_items(void) return ES_R_OK; } -static int __esd_send_bootcomplete(GDBusConnection *conn, const char *list_name) -{ - GVariant *result; - GError *error = NULL; - GVariantIter *iter; - gchar *str; - GVariant *gv; - bundle *b; - bundle_raw *raw; - int len; - gboolean ret; - - result = g_dbus_connection_call_sync(conn, - "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", - list_name, NULL, G_VARIANT_TYPE("(as)"), G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - - if (result == NULL) { - _E("get (%s) error(%s)", list_name, error->message); - g_error_free(error); - return ES_R_ERROR; - } - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_BOOT_COMPLETED, - EVT_VAL_BOOT_COMPLETED_TRUE); - - bundle_encode(b, &raw, &len); - - g_variant_get(result, "(as)", &iter); - while (g_variant_iter_loop(iter, "s", &str)) { - if (!strstr((const char *)str, "event.busname")) - continue; - - gv = g_variant_new("(us)", (unsigned int)len, raw); - ret = g_dbus_connection_emit_signal(conn, - str, - SYS_EVENT_OBJ_PATH, - SYS_EVENT_NAME_PREFIX, - EVT_KEY_BOOT_COMPLETED, - gv, - &error); - if (ret == FALSE) { - _E("Unable to emit signal: %s", error->message); - g_error_free(error); - } - } - - g_variant_iter_free(iter); - g_variant_unref(result); - bundle_free_encoded_rawdata(&raw); - bundle_free(b); - - return ES_R_OK; -} - static void __esd_signal_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -1100,21 +1042,17 @@ static void __esd_signal_handler(GDBusConnection *connection, gpointer user_data) { int handle; + bundle *b; if (!g_strcmp0(signal_name, SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED)) { _I("System session finished"); - system_bootcompleted = true; - } else if (!g_strcmp0(signal_name, - SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED)) { - _I("User session finished"); - __esd_get_user_items(); - user_bootcompleted = true; - } - if (system_bootcompleted && user_bootcompleted) { - __esd_send_bootcomplete(connection, "ListNames"); - __esd_send_bootcomplete(connection, "ListActivatableNames"); + b = bundle_create(); + bundle_add_str(b, EVT_KEY_BOOT_COMPLETED, + EVT_VAL_BOOT_COMPLETED_TRUE); + eventsystem_send_system_event(SYS_EVENT_BOOT_COMPLETED, b); + bundle_free(b); handle = creat(ESD_BOOT_COMPLETED, 0640); if (handle != -1) @@ -1714,7 +1652,6 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, guint reg_id = 0; guint boot_id = 0; - guint user_boot_id = 0; GError *error = NULL; reg_id = g_dbus_connection_register_object(connection, @@ -1742,22 +1679,6 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, _E("g_dbus_connection_signal_subscribe() is failed."); g_object_unref(connection); } - - user_boot_id = g_dbus_connection_signal_subscribe(connection, - NULL, - SYSTEMD_DBUS_IFACE_MANAGER, - SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED, - SYSTEMD_DBUS_PATH, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - __esd_signal_handler, - NULL, - NULL); - - if (user_boot_id == 0) { - _E("g_dbus_connection_signal_subscribe() is failed."); - g_object_unref(connection); - } } static void __esd_on_name_acquired(GDBusConnection *connection, -- 2.7.4 From 3e6c808794ee4a936b60dc3aff0001a511f66888 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 20 Feb 2017 16:36:20 +0900 Subject: [PATCH 16/16] Fix Restart option - Use "on-failure" option instead of "always" option Change-Id: If5b5229b516d00a514e5a407c7bf707e4fe83a66 Signed-off-by: Jiwoong Im --- packaging/esd.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/esd.service b/packaging/esd.service index 1cab817..b6cad4f 100644 --- a/packaging/esd.service +++ b/packaging/esd.service @@ -7,7 +7,7 @@ User=app_fw Group=app_fw SmackProcessLabel=System ExecStart=/usr/bin/esd -Restart=always +Restart=on-failure RestartSec=0 [Install] -- 2.7.4