From c34684a9fbbebca2b66e0c4dccf72b16ab227027 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 6 Jul 2016 13:47:09 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 From deb3f4eed0524f1cdbe29c9d847000e61cd7123c Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 22 Feb 2017 10:32:37 +0900 Subject: [PATCH 11/16] Release version 0.1.0 - Fix restart option Change-Id: I2bc1a3ed7aa53107b8af1fff5c300fd776babb68 Signed-off-by: Jiwoong Im --- packaging/esd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/esd.spec b/packaging/esd.spec index 2c70904..4d78869 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -1,6 +1,6 @@ Name: esd Summary: Event system daemon -Version: 0.0.1 +Version: 0.1.0 Release: 1 Group: Application Framework/Service License: Apache-2.0 -- 2.7.4 From 151dac0912e15749df6f319aa103bdd016b2773c Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 24 Mar 2017 08:37:06 +0900 Subject: [PATCH 12/16] Set license using %license macro Change-Id: Ie5eebd7d0af610b63c333481c4597f44edcd9115 Signed-off-by: Jiwoong Im --- packaging/esd.spec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/esd.spec b/packaging/esd.spec index 4d78869..6d50190 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -57,8 +57,6 @@ rm -rf %{buildroot} mkdir -p %{buildroot}%{_unitdir}/graphical.target.wants install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/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} %post -p /sbin/ldconfig @@ -71,7 +69,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %{_bindir}/esd %{_unitdir}/esd.service %{_unitdir}/graphical.target.wants/esd.service -/usr/share/license/%{name} +%license LICENSE %files devel %defattr(-,root,root,-) -- 2.7.4 From 4cf282a6c4e4e5d90c976c19cbfbfdd87d1e2aae Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 27 Mar 2017 18:30:53 +0900 Subject: [PATCH 13/16] Release version 0.1.1 Changes: - Set license using %license macro Change-Id: Ic01195830811d3ffcff76555fc3a3d319dc24e3d Signed-off-by: Jiwoong Im --- packaging/esd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/esd.spec b/packaging/esd.spec index 6d50190..596fca7 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -1,6 +1,6 @@ Name: esd Summary: Event system daemon -Version: 0.1.0 +Version: 0.1.1 Release: 1 Group: Application Framework/Service License: Apache-2.0 -- 2.7.4 From 64d15dadffb77a56baebac5024ead13ccd21309d Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Mon, 3 Apr 2017 13:30:31 +0900 Subject: [PATCH 14/16] Fix memory leak Change-Id: If280dd2155b75cabc42f7a2d4a8544b8707dfb65 Signed-off-by: Inkyun Kil --- src/esd_main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/esd_main.c b/src/esd_main.c index 93e096a..cb00e9e 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -1010,18 +1010,21 @@ static int __esd_get_user_items(void) PMINFO_APPINFO_PROP_APP_COMPONENT, "svcapp"); if (ret < 0) { _E("failed to add appinfo filter string"); + pkgmgrinfo_appinfo_filter_destroy(handle); 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"); + pkgmgrinfo_appinfo_filter_destroy(handle); 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"); + pkgmgrinfo_appinfo_filter_destroy(handle); return ES_R_ERROR; } pkgmgrinfo_appinfo_filter_destroy(handle); -- 2.7.4 From cfe2829d43c1299ddcf64c37bc3e9287f8a9b094 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 4 Apr 2017 19:49:16 +0900 Subject: [PATCH 15/16] Release version 0.1.2 - Fix memory leak Change-Id: I70061351325cef62344dc60b48c5055497e6b519 Signed-off-by: Inkyun Kil --- packaging/esd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/esd.spec b/packaging/esd.spec index 596fca7..e56eb2a 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -1,6 +1,6 @@ Name: esd Summary: Event system daemon -Version: 0.1.1 +Version: 0.1.2 Release: 1 Group: Application Framework/Service License: Apache-2.0 -- 2.7.4 From 0fde93901d543cfb25e7a06ff3edce6fcb1cdffc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Thu, 29 Dec 2016 09:39:56 +0100 Subject: [PATCH 16/16] Remove unnecessarily strictt dependency on dbus.service Change-Id: Ie1b11f7005ce2377912fabbd94e7186f866bbf75 (cherry picked from commit b1b0df6afedde9e0cd404fb082dbab7667e1a49c) --- packaging/esd.service | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/esd.service b/packaging/esd.service index b6cad4f..cd5f3ca 100644 --- a/packaging/esd.service +++ b/packaging/esd.service @@ -1,6 +1,5 @@ [Unit] Description=Start the Event System Daemon -After=dbus.service [Service] User=app_fw -- 2.7.4