From 738c498b0612eef7a77744438742949b8dc505b6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 12 Jan 2016 18:33:22 +0900 Subject: [PATCH 01/16] Adjust coding rule Change-Id: I716525bce2ad5c74df6f044819de522cf8246925 Signed-off-by: Hwankyu Jhun --- src/esd_main.c | 275 ++++++++++++++++++++++++------------------------- src/esd_system_event.c | 129 +++++++++-------------- 2 files changed, 180 insertions(+), 224 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index 931c33d..c85bb70 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -162,9 +162,8 @@ static int __esd_check_earlier_support(const char *event_name) int size = sizeof(earlier_event_list)/sizeof(*earlier_event_list); for (i = 0; i < size; i++) { - if (strcmp(earlier_event_list[i], event_name) == 0) { + if (strcmp(earlier_event_list[i], event_name) == 0) return true; - } } return false; @@ -177,9 +176,8 @@ static int __esd_check_event_launch_support(const char *event_name) int size = sizeof(event_launch_support_list)/sizeof(*event_launch_support_list); for (i = 0; i < size; i++) { - if (strcmp(event_launch_support_list[i], event_name) == 0) { + if (strcmp(event_launch_support_list[i], event_name) == 0) return true; - } } return false; @@ -244,9 +242,8 @@ static uid_t __get_sender_uid(GDBusConnection *conn, const char *sender_name) uid_t uid = -1; uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser"); - if (uid < 0) { + if (uid < 0) _E("failed to get uid"); - } _D("sender_name(%s), uid(%d)", sender_name, uid); @@ -302,15 +299,15 @@ static bool __esd_check_application_validation(uid_t uid, const char *appid) static void __esd_trusted_busname_print_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { trusted_item *item = (trusted_item *)value; - if (item) { + if (item) _D("uid(%d), appid(%s), pid(%d), busname(%s)", item->uid, item->app_id, item->pid, item->bus_name); - } } } @@ -319,6 +316,7 @@ static int __esd_trusted_busname_add_item(uid_t uid, const char *appid, const ch char *app_id = NULL; char *bus_name = NULL; trusted_item *item = NULL; + trusted_item *new_item; app_id = strdup(appid); if (app_id == NULL) { @@ -341,7 +339,7 @@ static int __esd_trusted_busname_add_item(uid_t uid, const char *appid, const ch FREE_AND_NULL(app_id); FREE_AND_NULL(bus_name); } else { - trusted_item *new_item = calloc(1, sizeof(trusted_item)); + new_item = calloc(1, sizeof(trusted_item)); if (new_item == NULL) { _E("memory alloc failed"); FREE_AND_NULL(app_id); @@ -411,9 +409,8 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na if (__esd_check_application_validation(uid, tmp_appid)) { _D("add to table"); ret = __esd_trusted_busname_add_item(uid, tmp_appid, (const char *)str, pid); - if (ret < 0) { + if (ret < 0) _E("failed to add item"); - } } } g_variant_iter_free(iter); @@ -460,6 +457,7 @@ static bool __esd_check_valid_privilege_by_cynara(const char *appid, const char return has_privilege; } +#if 0 static int __esd_privilege_func(const char *name, void *user_data) { esd_privilege_check *epc = (esd_privilege_check *)user_data; @@ -472,12 +470,12 @@ static int __esd_privilege_func(const char *name, void *user_data) return 0; } } +#endif static int __esd_check_app_privileged_event(uid_t uid, const char *appid, const char *pkgid, const char *event_name) { char *privilege_name = NULL; char client[256] = {0, }; - char *session = NULL; char *user = NULL; int retval = 1; @@ -488,7 +486,6 @@ static int __esd_check_app_privileged_event(uid_t uid, const char *appid, const if (privilege_name) { /* TODO(jongmyeong.ko): getting client should be replaced by cynara api */ snprintf(client, 256, "User::App::%s", pkgid); - session = ""; user = (char *)g_strdup_printf("%u", uid); if (!__esd_check_valid_privilege_by_cynara(appid, client, "", user, privilege_name)) { _E("app(%s) has NOT privilege(%s)", appid, privilege_name); @@ -518,13 +515,13 @@ static void __esd_print_interested_event(gpointer data, gpointer user_data) static void __esd_launch_table_print_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, event_launch_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { + while (g_hash_table_iter_next(&iter, &key, &value)) __esd_print_interested_event(value, NULL); - } } static int __esd_find_compare_by_list_item(gconstpointer data, gconstpointer user_data) @@ -563,7 +560,7 @@ static int __esd_add_launch_item(uid_t uid, const char *event_name, const char * char *app_id = NULL; char *pkg_id = NULL; esd_list_item_s *item_of_list = NULL; - + event_launch_item *eli; event_launch_item *el_item = (event_launch_item *)g_hash_table_lookup(event_launch_table, event_name); @@ -602,7 +599,7 @@ static int __esd_add_launch_item(uid_t uid, const char *event_name, const char * } } else { _D("add new item (all)"); - event_launch_item *eli = calloc(1, sizeof(event_launch_item)); + eli = calloc(1, sizeof(event_launch_item)); if (!eli) { _E("memory alloc failed"); return ES_R_ENOMEM; @@ -671,7 +668,8 @@ static void __esd_remove_all_private_usr_app_list(gpointer data, gpointer user_d static int __esd_launch_table_remove_private_usr_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; event_launch_item *eli = NULL; GList *first_list = NULL; @@ -683,9 +681,9 @@ static int __esd_launch_table_remove_private_usr_items(void) first_list = g_list_first(eli->app_list_evtlaunch); if (first_list == NULL) { - if (eli->reg_id) { + if (eli->reg_id) eventsystem_unregister_event(eli->reg_id); - } + g_hash_table_iter_remove(&iter); } } @@ -699,9 +697,8 @@ static void __esd_remove_app_list(gpointer data, gpointer user_data) esd_list_item_s *item = (esd_list_item_s *)data; event_launch_item *eli = (event_launch_item *)user_data; - if (eli->uid != GLOBAL_USER && eli->uid != item->uid) { + if (eli->uid != GLOBAL_USER && eli->uid != item->uid) skip = true; - } if (!skip && !strcmp(eli->package_name, item->pkg_id)) { _D("pkg_id(%s), app_id(%s)", eli->package_name, item->app_id); @@ -721,9 +718,9 @@ static int __esd_remove_launch_item(uid_t uid, gpointer data, const char *pkg_id first_list = g_list_first(eli->app_list_evtlaunch); if (first_list == NULL) { - if (eli->reg_id) { + if (eli->reg_id) eventsystem_unregister_event(eli->reg_id); - } + return ES_R_REMOVE; } @@ -733,7 +730,8 @@ static int __esd_remove_launch_item(uid_t uid, gpointer data, const char *pkg_id static int __esd_launch_table_remove_items(uid_t uid, const char *pkg_id) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, event_launch_table); @@ -751,13 +749,15 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; uid_t uid = item->uid; - uid_t from_uid = 0; char *app_id = item->app_id; esd_event_param *eep = (esd_event_param *)user_data; - char *from_appid = (char *)eep->user_data; static unsigned int req_id; int pid; - int ret = 0; + char event_uri[1024]; + bundle *b; + /* char *from_appid = (char *)eep->user_data; */ + /* uid_t from_uid = 0; */ + /* int ret = 0; */ _D("launch_on_event: app_id(%s), event_name(%s)", app_id, eep->event_name); @@ -777,9 +777,8 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) if (!aul_app_is_running(app_id)) { */ if (1) { - char event_uri[1024] = {0, }; - snprintf(event_uri, 1024, "event://%s", eep->event_name); - bundle *b = bundle_dup(eep->event_data); + 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); appsvc_set_uri(b, event_uri); appsvc_set_appid(b, app_id); @@ -806,48 +805,47 @@ static void __esd_check_event_launch_with_eventid(gpointer data, gpointer user_d static void __esd_launch_event_handler(char *event_name, bundle *data, void *user_data) { - _D("event_name(%s)", event_name); + const char *val; + const char *msg_type; + const char *msg_id; + esd_event_param *eep; + event_launch_item *el_item; - event_launch_item *el_item = - (event_launch_item *)g_hash_table_lookup(event_launch_table, event_name); + _D("event_name(%s)", event_name); - if (el_item == NULL) { + el_item = (event_launch_item *)g_hash_table_lookup(event_launch_table, event_name); + if (el_item == NULL) return; - } if (el_item->app_list_evtlaunch != NULL) { if (strcmp(SYS_EVENT_BATTERY_CHARGER_STATUS, event_name) == 0) { - const char *val = bundle_get_val(data, EVT_KEY_BATTERY_CHARGER_STATUS); + 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 (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0) return; - } } else if (strcmp(SYS_EVENT_USB_STATUS, event_name) == 0) { - const char *val = bundle_get_val(data, EVT_KEY_USB_STATUS); + val = bundle_get_val(data, EVT_KEY_USB_STATUS); _D("usb val(%s)", val); - if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) { + if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) return; - } } else if (strcmp(SYS_EVENT_EARJACK_STATUS, event_name) == 0) { - const char *val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); + val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); _D("earjack val(%s)", val); - if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) { + if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) return; - } } else if (strcmp(SYS_EVENT_INCOMMING_MSG, event_name) == 0) { - const char *msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); + msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); _D("msg_type(%s)", msg_type); - if (msg_type == NULL) { + if (msg_type == NULL) return; - } - const char *msg_id = bundle_get_val(data, EVT_KEY_MSG_ID); + + msg_id = bundle_get_val(data, EVT_KEY_MSG_ID); _D("msg_id(%s)", msg_id); - if (msg_id == NULL) { + if (msg_id == NULL) return; - } } - esd_event_param *eep = calloc(1, sizeof(esd_event_param)); + eep = calloc(1, sizeof(esd_event_param)); if (!eep) { _E("memory alloc failed"); return; @@ -865,26 +863,28 @@ static void __esd_print_earlier_event(gpointer data, gpointer user_data) { earlier_item *item = (earlier_item *)data; char *event_name = (char *)item->event_name; + const char *val; + _D("event_name = (%s)", event_name); if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BOOT_COMPLETED); + val = bundle_get_val(item->earlier_data, EVT_KEY_BOOT_COMPLETED); _D("boot_completed(%s)", val); } } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN); + val = bundle_get_val(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN); _D("shutdown(%s)", val); } } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_LOW_MEMORY); + val = bundle_get_val(item->earlier_data, EVT_KEY_LOW_MEMORY); _D("low_memory(%s)", val); } } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BATTERY_CHARGER_STATUS); + val = bundle_get_val(item->earlier_data, EVT_KEY_BATTERY_CHARGER_STATUS); _D("charger_status(%s)", val); } } @@ -893,32 +893,32 @@ static void __esd_print_earlier_event(gpointer data, gpointer user_data) static void __esd_earlier_table_print_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, earlier_event_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { + while (g_hash_table_iter_next(&iter, &key, &value)) __esd_print_earlier_event(value, NULL); - } } 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); - earlier_item *item = - (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); - + item = (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); if (item) { /* update earlier value */ - if (item->earlier_data != NULL) { + if (item->earlier_data != NULL) bundle_free(item->earlier_data); - } + item->earlier_data = bundle_dup(data); if (!g_is_bootcompleted) { if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { - int handle = creat(ESD_BOOT_COMPLETED, 0640); + handle = creat(ESD_BOOT_COMPLETED, 0640); if (handle != -1) close(handle); g_is_bootcompleted = true; @@ -933,25 +933,25 @@ static void __esd_event_handler(char *event_name, bundle *data, void *user_data) _D("event_name(%s)", event_name); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE - if (__esd_check_earlier_support(event_name)) { + if (__esd_check_earlier_support(event_name)) __esd_earlier_event_handler(event_name, data, user_data); - } #endif - if (__esd_check_event_launch_support(event_name)) { + if (__esd_check_event_launch_support(event_name)) __esd_launch_event_handler(event_name, data, user_data); - } } static void __esd_trusted_busname_remove_item(char *bus_name) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; + trusted_item *item; g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - trusted_item *item = (trusted_item *)value; + item = (trusted_item *)value; if (item) { if (strcmp(bus_name, item->bus_name) == 0) { _D("remove trusted busname item(%s, %s)", item->app_id, item->bus_name); @@ -986,13 +986,12 @@ static void __esd_filter_name_owner_changed(GDBusConnection *connection, _D("changed name(%s), old_onwer(%s)(%d) -> new_onwer(%s)(%d)", name, old_owner, old_len, new_owner, new_len); - if (old_len > 0 && new_len == 0) { + if (old_len > 0 && new_len == 0) __esd_trusted_busname_remove_item(name); - } else if (old_len == 0 && new_len > 0) { + else if (old_len == 0 && new_len > 0) _D("new name owned"); - } else { + else _E("not-expected name change"); - } } } @@ -1033,9 +1032,8 @@ static int __esd_get_user_items(void) _I("found uid(%d)", cur_uid); ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, cur_uid, &cur_uid); - if (ret < 0) { + if (ret < 0) _E("failed to get user(%d)-app list (%d)", cur_uid, ret); - } } } @@ -1060,9 +1058,8 @@ static int __esd_start_sd_monitor(void) int fd = 0; ret = __esd_get_user_items(); - if (ret < 0) { + if (ret < 0) return ES_R_ERROR; - } ret = sd_login_monitor_new("uid", &g_sd_monitor); if (ret < 0) { @@ -1314,6 +1311,7 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha uid_t uid = 0; char *_appid = NULL; char *_busname = NULL; + trusted_item *item; g_variant_get(parameters, "(s)", &event_name); _D("event_name(%s)", event_name); @@ -1327,19 +1325,17 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - trusted_item *item = (trusted_item *)value; + item = (trusted_item *)value; uid = item->uid; _appid = item->app_id; _busname = item->bus_name; - if (uid != GLOBAL_USER && uid != sender_uid) { + if (uid != GLOBAL_USER && uid != sender_uid) continue; - } ret = __esd_check_certificate_match(uid, _appid, sender_uid, app_id); - if (ret == ES_R_OK) { + if (ret == ES_R_OK) g_variant_builder_add(builder, "s", _busname); - } } result = 1; @@ -1348,9 +1344,8 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha param = g_variant_new("(ias)", result, builder); _D("result(%d)", result); g_dbus_method_invocation_return_value(invocation, param); - if (builder) { + if (builder) g_variant_builder_unref(builder); - } } static void setup_trusted_peer_method_call(GDBusConnection *connection, const gchar *sender, @@ -1440,11 +1435,10 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const } _D("app_id(%s), client(%s), session(%s), user(%s)", app_id, client, session, user); - if (__esd_check_valid_privilege_by_cynara(app_id, client, session, user, privilege_name)) { + if (__esd_check_valid_privilege_by_cynara(app_id, client, session, user, privilege_name)) result = 1; - } else { + else result = ES_R_EINVAL; - } } } else { result = 1; @@ -1468,6 +1462,7 @@ static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvoca bundle *b = NULL; bundle_raw *raw = NULL; int len = 0; + earlier_item *item; g_variant_get(parameters, "(s)", &event_name); @@ -1479,9 +1474,7 @@ static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvoca result = ES_R_ERROR; } - earlier_item *item = - (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); - + item = (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); if (item != NULL) { if (item->earlier_data) { b = bundle_dup(item->earlier_data); @@ -1551,12 +1544,14 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, static void __esd_on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { + bundle *b; + _I("name acquired(%s)", name); __esd_check_trusted_events(connection, "ListNames"); __esd_check_trusted_events(connection, "ListActivatableNames"); - bundle *b = bundle_create(); + b = bundle_create(); bundle_add_str(b, EVT_KEY_ESD_STATUS, EVT_VAL_ESD_STARTED); eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b); bundle_free(b); @@ -1580,21 +1575,30 @@ static int __esd_before_loop(void) { int ret = 0; uid_t uid = 0; + GError *error = NULL; + guint owner_id = 0; #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE guint subscription_id = 0; - int i, size; + int i; + int size; + char *event_name; + int fd; + int val; + int status; + int charger_status; + int charge_now; + ealier_item *item; earlier_event_table = g_hash_table_new(g_str_hash, g_str_equal); _I("register events for earlier_data"); size = sizeof(earlier_event_list)/sizeof(*earlier_event_list); for (i = 0; i < size; i++) { - char *event_name = NULL; event_name = (char *)earlier_event_list[i]; _I("event_name(%s)", event_name); - earlier_item *item = calloc(1, sizeof(earlier_item)); + item = calloc(1, sizeof(earlier_item)); if (item == NULL) { _E("memery alloc failed"); return ES_R_ENOMEM; @@ -1608,7 +1612,6 @@ static int __esd_before_loop(void) /* set initial data */ if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { - int fd = 0; fd = open(ESD_BOOT_COMPLETED, O_RDONLY); if (fd < 0) { _D("open file error(%d)", fd); @@ -1619,7 +1622,6 @@ static int __esd_before_loop(void) close(fd); } } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { - int val; ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val); if (ret != VCONF_OK) { _E("failed to get power_off status (%d)", ret); @@ -1633,7 +1635,6 @@ static int __esd_before_loop(void) } } } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { - int status; ret = vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &status); if (ret != VCONF_OK) { _E("failed to get low_memory status (%d)", ret); @@ -1650,16 +1651,13 @@ static int __esd_before_loop(void) EVT_VAL_MEMORY_NORMAL); } } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { - int charger_status; - int charge_now; ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger_status); if (ret != VCONF_OK) { _E("failed to get charger_status (%d)", ret); } else { ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &charge_now); - if (ret != VCONF_OK) { + if (ret != VCONF_OK) _E("failed to get charge_now (%d)", ret); - } } if (ret == VCONF_OK) { @@ -1682,7 +1680,6 @@ static int __esd_before_loop(void) } } - eventsystem_register_event(event_name, &subscription_id, (eventsystem_handler)__esd_event_handler, NULL); if (subscription_id == 0) { @@ -1720,10 +1717,6 @@ static int __esd_before_loop(void) trusted_busname_table = g_hash_table_new(g_str_hash, g_str_equal); /* gdbus setup for method call */ - GError *error = NULL; - guint owner_id = 0; - - error = NULL; introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error); if (!introspection_data) { _E("g_dbus_node_info_new_for_xml error(%s)", error->message); @@ -1789,9 +1782,8 @@ static int __esd_appcontrol_cb(const char *operation, } else if (!__esd_check_app_privileged_event(uid, appid, pkgid, event_name)) { _E("failed to add item (no privilege)"); } else { - if (__esd_add_launch_item(uid, event_name, appid, pkgid)) { + if (__esd_add_launch_item(uid, event_name, appid, pkgid)) _E("failed to add item"); - } } FREE_AND_NULL(event_name); } else { @@ -1933,9 +1925,8 @@ static int __esd_pkgmgr_event_callback(uid_t target_uid, int req_id, const char _E("pkg_event(%d) falied", pkg_event->type); __esd_pkgmgr_event_free(pkg_event); } else { - if (strcmp(key, "install_percent") != 0) { + if (strcmp(key, "install_percent") != 0) __esd_pkgmgr_event_free(pkg_event); - } } return 0; @@ -1945,6 +1936,8 @@ static int __esd_init() { int req_id = 0; int ret = 0; + pkgmgr_client *client; + esd_pkgmgr_event *pkg_event; #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36) g_type_init(); @@ -1953,19 +1946,19 @@ static int __esd_init() __esd_init_cynara(); - pkgmgr_client *client = pkgmgr_client_new(PC_LISTENING); + client = pkgmgr_client_new(PC_LISTENING); if (client == NULL) { _E("set pkgmgr client failed"); return ES_R_ERROR; } - esd_pkgmgr_event *pkg_event = calloc(1, sizeof(esd_pkgmgr_event)); + pkg_event = calloc(1, sizeof(esd_pkgmgr_event)); if (pkg_event == NULL) { _E("memory alloc failed"); ret = pkgmgr_client_free(client); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - } + return ES_R_ENOMEM; } @@ -1973,9 +1966,9 @@ static int __esd_init() if (req_id < 0) { _E("pkgmgr client listen failed"); ret = pkgmgr_client_free(client); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - } + return ES_R_ERROR; } @@ -1996,20 +1989,24 @@ static void __esd_remove_esd_list_item(gpointer data, gpointer user_data) static void __esd_finalize(void) { - gpointer key, value; + gpointer key; + gpointer value; + GHashTableIter iter; + trusted_item *item; + event_launch_item *el_item; int ret = 0; +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE + earlier_item *er_item; +#endif _D("esd finalize"); __esd_stop_sd_monitor(); if (trusted_busname_table) { - GHashTableIter iter; - g_hash_table_iter_init(&iter, trusted_busname_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { - trusted_item *item = (trusted_item *)value; + item = (trusted_item *)value; if (item) { free(item->app_id); free(item->bus_name); @@ -2024,19 +2021,16 @@ static void __esd_finalize(void) #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE if (earlier_event_table) { - GHashTableIter iter; - g_hash_table_iter_init(&iter, earlier_event_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { - earlier_item *item = (earlier_item *)value; - if (item) { - eventsystem_unregister_event(item->reg_id); - free(item->event_name); - bundle_free(item->earlier_data); - free(item); + er_item = (earlier_item *)value; + if (er_item) { + eventsystem_unregister_event(er_item->reg_id); + free(er_item->event_name); + bundle_free(er_item->earlier_data); + free(er_item); } else { - _E("item is NULL"); + _E("ealier item is NULL"); } g_hash_table_iter_remove(&iter); } @@ -2045,12 +2039,9 @@ static void __esd_finalize(void) #endif if (event_launch_table) { - GHashTableIter iter; - g_hash_table_iter_init(&iter, event_launch_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { - event_launch_item *el_item = (event_launch_item *)value; + el_item = (event_launch_item *)value; if (el_item) { eventsystem_unregister_event(el_item->reg_id); free(el_item->event_name); @@ -2066,15 +2057,13 @@ static void __esd_finalize(void) g_hash_table_unref(event_launch_table); } - if (introspection_data) { + if (introspection_data) g_dbus_node_info_unref(introspection_data); - } if (s_info.client) { ret = pkgmgr_client_free(s_info.client); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - } } __esd_finish_cynara(); diff --git a/src/esd_system_event.c b/src/esd_system_event.c index 5579ac5..339833b 100644 --- a/src/esd_system_event.c +++ b/src/esd_system_event.c @@ -43,9 +43,8 @@ static int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key) ret = 1; } - if (ret == 0) { + if (ret == 0) _D("same event_data"); - } return ret; } @@ -53,7 +52,6 @@ static int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key) static int __esd_send_system_event(const char *event_name, bundle *b, const char *key) { int ret = ES_R_OK; - esd_sent_item *item = (esd_sent_item *)g_hash_table_lookup(esd_sent_table, event_name); @@ -111,22 +109,19 @@ static void __esd_vconfcb_location_use_mylocation(keynode_t *node, void *user_da key = EVT_KEY_LOCATION_ENABLE_STATE; - if (enabled) { + if (enabled) val = EVT_VAL_LOCATION_ENABLED; - } else { + else val = EVT_VAL_LOCATION_DISABLED; - } b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data) @@ -147,22 +142,19 @@ static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data) key = EVT_KEY_GPS_ENABLE_STATE; - if (enabled) { + if (enabled) val = EVT_VAL_GPS_ENABLED; - } else { + else val = EVT_VAL_GPS_DISABLED; - } b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_data) @@ -183,22 +175,19 @@ static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_d key = EVT_KEY_NPS_ENABLE_STATE; - if (enabled) { + if (enabled) val = EVT_VAL_NPS_ENABLED; - } else { + else val = EVT_VAL_NPS_DISABLED; - } b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_language_set(keynode_t *node, void *user_data) @@ -220,13 +209,11 @@ static void __esd_vconfcb_language_set(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, str); - if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) @@ -255,13 +242,11 @@ static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_region_format(keynode_t *node, void *user_data) @@ -283,13 +268,11 @@ static void __esd_vconfcb_region_format(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, str); - if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) @@ -320,46 +303,42 @@ static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) val = EVT_VAL_VIBRATION_ON; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } else { key = EVT_KEY_VIBRATION_STATE; val = EVT_VAL_VIBRATION_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } if (!sound_on) { key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_ON; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } } } @@ -392,35 +371,32 @@ static void __esd_vconfcb_sound_status(keynode_t *node, void *user_data) val = EVT_VAL_VIBRATION_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } else { if (!vibration_on) { key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_ON; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } } } @@ -451,13 +427,11 @@ static void __esd_vconfcb_auto_rotate(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data) @@ -486,13 +460,11 @@ static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data) @@ -521,13 +493,11 @@ static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_font_set(keynode_t *node, void *user_data) @@ -549,13 +519,11 @@ static void __esd_vconfcb_font_set(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, str); - if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static struct esd_vconf_handler vconf_callbacks[] = { @@ -600,4 +568,3 @@ int __esd_register_vconf_callbacks(void) return result; } - -- 2.7.4 From b763bae0f2249134048454c8e2d5d3dc91e4b07d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 13 Jan 2016 07:34:25 +0900 Subject: [PATCH 02/16] Fix wrong declaration of the earlier_item pointer type Change-Id: I8dac8d69b3d968b46fc3bfe74e8101a8defc5b80 Signed-off-by: Hwankyu Jhun --- src/esd_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/esd_main.c b/src/esd_main.c index c85bb70..6d35c03 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -1588,7 +1588,7 @@ static int __esd_before_loop(void) int status; int charger_status; int charge_now; - ealier_item *item; + earlier_item *item; earlier_event_table = g_hash_table_new(g_str_hash, g_str_equal); -- 2.7.4 From 0e1ff1b9b1cb5cded132f8f6f189b8d1bdbb6cfd Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 2 Feb 2016 13:06:56 +0900 Subject: [PATCH 03/16] remove assert code. Change-Id: I70e5285b9492b203127a0b80ee34fcf6f9a76364 Signed-off-by: jongmyeongko --- src/esd_main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index 6d35c03..5488d15 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -2077,14 +2076,12 @@ int main(int argc, char *argv[]) if (__esd_init() != 0) { _E("ESD Initialization failed!"); - assert(0); return ES_R_ERROR; } if (__esd_before_loop() < 0) { _E("ESD failed!"); __esd_finalize(); - assert(0); return ES_R_ERROR; } -- 2.7.4 From 2c80ceaa5fb9d98acb87c85b3baac06d3c60065d Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 19 Feb 2016 11:56:13 +0900 Subject: [PATCH 04/16] fix TODO items checking privilege by appid. checking app runnig status by uid. checking certficate for trusted event peers. Change-Id: I3b7a9d1fbbf211c95778ba7df8e399c2390c1af8 Signed-off-by: jongmyeongko --- CMakeLists.txt | 2 +- packaging/esd.spec | 1 + src/esd_main.c | 73 ++++++++++-------------------------------------------- 3 files changed, 15 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0208eef..5d620f0 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) +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) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/packaging/esd.spec b/packaging/esd.spec index a84789f..74fd236 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -23,6 +23,7 @@ BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-creds-gdbus) BuildRequires: pkgconfig(cynara-session) +BuildRequires: pkgconfig(security-manager) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/esd_main.c b/src/esd_main.c index 5488d15..a21fade 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "eventsystem_daemon.h" #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) @@ -43,11 +44,6 @@ static const struct privilege_info privilege_check_list[] = { {SYS_EVENT_INCOMMING_MSG, "http://tizen.org/privilege/message.read"} }; -typedef struct __esd_privilege_check { - char *privilege_name; - int validation; -} esd_privilege_check; - static int privilege_check_size = sizeof(privilege_check_list)/sizeof(struct privilege_info); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE @@ -256,12 +252,7 @@ static int __esd_check_certificate_match(uid_t uid, const char *app_id, uid_t fr _D("uid(%d), app_id(%s), from_uid(%d), from_appid(%s)", uid, app_id, from_uid, from_appid); - if (uid != from_uid) { - /* TODO(jongmyeong.ko): check cert result if uids are not same */ - _D("not same uid"); - } - - ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(app_id, from_appid, uid, &res); + ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(app_id, from_appid, from_uid, &res); if (ret < 0) { _E("failed to check certificate"); return ES_R_ERROR; @@ -286,11 +277,8 @@ static bool __esd_check_application_validation(uid_t uid, const char *appid) pkgmgrinfo_appinfo_destroy_appinfo(handle); - /* FIXME(jongmyeong.ko) */ - /* - if (!aul_app_is_running(appid)) + if (!aul_app_is_running_for_uid(appid, uid)) return false; - */ return true; } @@ -456,43 +444,26 @@ static bool __esd_check_valid_privilege_by_cynara(const char *appid, const char return has_privilege; } -#if 0 -static int __esd_privilege_func(const char *name, void *user_data) -{ - esd_privilege_check *epc = (esd_privilege_check *)user_data; - - if (strcmp(name, epc->privilege_name) == 0) { - epc->validation = 1; - return -1; - } else { - epc->validation = 0; - return 0; - } -} -#endif - static int __esd_check_app_privileged_event(uid_t uid, const char *appid, const char *pkgid, const char *event_name) { char *privilege_name = NULL; - char client[256] = {0, }; - char *user = NULL; - int retval = 1; + int ret = 0; + int result = 0; _D("event_name(%s), uid(%d), appid(%s), pkgid(%s)", event_name, uid, appid, pkgid); __esd_check_privilege_name(event_name, &privilege_name); if (privilege_name) { - /* TODO(jongmyeong.ko): getting client should be replaced by cynara api */ - snprintf(client, 256, "User::App::%s", pkgid); - user = (char *)g_strdup_printf("%u", uid); - if (!__esd_check_valid_privilege_by_cynara(appid, client, "", user, privilege_name)) { - _E("app(%s) has NOT privilege(%s)", appid, privilege_name); - retval = 0; - } + ret = security_manager_app_has_privilege(appid, privilege_name, uid, &result); + if (ret != SECURITY_MANAGER_SUCCESS) + _E("failed to check privilege(%d)", ret); + _D("result(%d)", result); + } else { + result = 1; } - return retval; + return result; } static void __esd_print_appid_with_eventid(gpointer data, gpointer user_data) @@ -754,28 +725,10 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) int pid; char event_uri[1024]; bundle *b; - /* char *from_appid = (char *)eep->user_data; */ - /* uid_t from_uid = 0; */ - /* int ret = 0; */ _D("launch_on_event: app_id(%s), event_name(%s)", app_id, eep->event_name); - /* TODO(jongmyeong.ko): for launch by user-event */ - /* - if (from_appid && from_appid[0] != '\0') { - ret = __esd_check_certificate_match(uid, app_id, from_uid, from_appid); - if (ret != ES_R_OK) { - _D("from_appid(%s), no same cert", from_appid); - return; - } - } - */ - - /* FIXME(jongmyeong.ko): aul_app_is_running */ - /* - if (!aul_app_is_running(app_id)) { - */ - if (1) { + 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); -- 2.7.4 From 971a9c34d4ea5ae518c9105737ce22d98a9fc9a7 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 7 Mar 2016 11:59:40 +0900 Subject: [PATCH 05/16] fix return of __get_sender_uid and __get_sender_unixinfo - uid_t(unsigned int) can't be less than zero Change-Id: Ibb66bc32d24221f238dda1d0c6110f1b31d80164 Signed-off-by: Jiwoong Im --- src/esd_main.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index a21fade..1632334 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -178,13 +178,14 @@ static int __esd_check_event_launch_support(const char *event_name) return false; } -static uid_t __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) +static int __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) { GDBusMessage *msg = NULL; GDBusMessage *reply = NULL; GError *err = NULL; GVariant *body; - int value = -1; + int ret = -1; + unsigned int value; msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", type); @@ -207,6 +208,7 @@ static uid_t __get_sender_unixinfo(GDBusConnection *conn, const char *sender_nam body = g_dbus_message_get_body(reply); g_variant_get(body, "(u)", &value); + ret = (int)value; out: if (msg) @@ -214,7 +216,7 @@ out: if (reply) g_object_unref(reply); - return (uid_t)value; + return ret; } static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) @@ -232,13 +234,14 @@ static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) return pid; } -static uid_t __get_sender_uid(GDBusConnection *conn, const char *sender_name) +static int __get_sender_uid(GDBusConnection *conn, const char *sender_name) { - uid_t uid = -1; + int uid = -1; uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser"); - if (uid < 0) + if (uid < 0) { _E("failed to get uid"); + } _D("sender_name(%s), uid(%d)", sender_name, uid); @@ -352,7 +355,7 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na gchar *str; char tmp_appid[128] = {0, }; int pid = 0; - uid_t uid = 0; + int uid = 0; int ret = 0; result = g_dbus_connection_call_sync(conn, @@ -386,16 +389,16 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na _D("uid(%d)", uid); memset(tmp_appid, 0, sizeof(tmp_appid)); - ret = aul_app_get_appid_bypid_for_uid(pid, tmp_appid, sizeof(tmp_appid), uid); + ret = aul_app_get_appid_bypid_for_uid(pid, tmp_appid, sizeof(tmp_appid), (uid_t)uid); if (ret != AUL_R_OK) { _E("failed to get appid by pid(%d)", pid); continue; } _D("appid(%s)", tmp_appid); - if (__esd_check_application_validation(uid, tmp_appid)) { + if (__esd_check_application_validation((uid_t)uid, tmp_appid)) { _D("add to table"); - ret = __esd_trusted_busname_add_item(uid, tmp_appid, (const char *)str, pid); + ret = __esd_trusted_busname_add_item((uid_t)uid, tmp_appid, (const char *)str, pid); if (ret < 0) _E("failed to add item"); } @@ -1199,7 +1202,7 @@ static void check_sender_valid_method_call(GDBusConnection *connection, const gc g_variant_get(parameters, "(is)", &event_sender_pid, &event_name); _D("event_sender_pid(%d), event_name(%s)", event_sender_pid, event_name); - sender_uid = __get_sender_uid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); if (__esd_get_appid_by_pid(event_sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { @@ -1230,7 +1233,7 @@ static void check_send_event_valid_method_call(GDBusConnection *connection, cons _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(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; } else { @@ -1269,7 +1272,7 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(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; } else { @@ -1317,7 +1320,7 @@ static void setup_trusted_peer_method_call(GDBusConnection *connection, const gc if (destination_name && destination_name[0] != '\0') { sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(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; } else { @@ -1361,7 +1364,7 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const if (privilege_name) { sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(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; } else { -- 2.7.4 From 13fe83911cd9f9d12eb0826c9e32ac36a77a237a Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 11 Mar 2016 16:39:47 +0900 Subject: [PATCH 06/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 07/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 08/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 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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