From 16eddec676cc2cf514bb9c9a686ce354214688d6 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 26 Sep 2019 16:48:59 +0900 Subject: [PATCH 01/16] Fix wrong dbus policy Change-Id: Id8d01a7d60e103da71325c5fc0b32c425269bba0 --- packaging/capi-ui-sticker.conf | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packaging/capi-ui-sticker.conf b/packaging/capi-ui-sticker.conf index 9d90095..84113c9 100644 --- a/packaging/capi-ui-sticker.conf +++ b/packaging/capi-ui-sticker.conf @@ -3,12 +3,14 @@ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - + - - - + + + + + \ No newline at end of file -- 2.7.4 From 45a051d02db10bb344de74ed1ee1984321fb892f Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 26 Sep 2019 17:29:16 +0900 Subject: [PATCH 02/16] Update package version to 0.1.1 Change-Id: I769d9103e80c8751088b870d1a96552d2aa3c7c4 --- packaging/capi-ui-sticker.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 1a94b61..b0b7a4f 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.0 +Version: 0.1.1 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 @@ -100,4 +100,4 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %{_includedir}/sticker_error.h %{_includedir}/sticker_data.h %{_includedir}/sticker_consumer.h -%{_includedir}/sticker_provider.h \ No newline at end of file +%{_includedir}/sticker_provider.h -- 2.7.4 From 1912bd83181233f748cbbe81dd77f3e1f82bcb74 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 27 Sep 2019 16:16:30 +0900 Subject: [PATCH 03/16] Apply ASLR in daemon Change-Id: I73350cc6b0c8a44441f41bf5020e6cf7e98c3e59 Signed-off-by: Jihoon Kim --- server/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 1c15da7..655ed42 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -10,10 +10,11 @@ FOREACH(flag ${pkgs_CFLAGS}) ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") ## Executable ## ADD_EXECUTABLE(sticker-server ${SRCS}) TARGET_LINK_LIBRARIES(sticker-server ${pkgs_LDFLAGS}) ## Install library files ## -INSTALL(TARGETS sticker-server DESTINATION bin) \ No newline at end of file +INSTALL(TARGETS sticker-server DESTINATION bin) -- 2.7.4 From fbd50f9eaa03104257e87c1ae0f15ceaaacb2b12 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 27 Sep 2019 16:30:05 +0900 Subject: [PATCH 04/16] Change install destination of daemon Change-Id: Ibd790f2f32ae7320d2497693748ab3e5cd7beeee Signed-off-by: Jihoon Kim --- server/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 655ed42..0b7fe18 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -16,5 +16,5 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") ADD_EXECUTABLE(sticker-server ${SRCS}) TARGET_LINK_LIBRARIES(sticker-server ${pkgs_LDFLAGS}) -## Install library files ## -INSTALL(TARGETS sticker-server DESTINATION bin) +## Install daemon file ## +INSTALL(TARGETS sticker-server DESTINATION /usr/bin) -- 2.7.4 From 28da3a63a4185ace0cd45ec70853b97a84622b45 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 30 Sep 2019 15:18:34 +0900 Subject: [PATCH 05/16] Update package version to 0.1.2 Change-Id: Ia7ff4cef75083dffb1e048e33f0209ff3a343bed Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index b0b7a4f..32b94b0 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.1 +Version: 0.1.2 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 016c4f21c479dec9f7272536a2333ce779b6154c Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 30 Sep 2019 15:26:51 +0900 Subject: [PATCH 06/16] Modified user and group id of sticker daemon to ui_fw Change-Id: I98e2afcb0fd5432bbf7ee0ab4d9f286c9a270b09 --- packaging/capi-ui-sticker.spec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 32b94b0..caa2293 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -80,9 +80,8 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %files %manifest %{name}.manifest %license LICENSE -%defattr(-,root,root,-) %{_libdir}/lib*.so -%attr(0755,root,root) %{_bindir}/sticker-server +%attr(0755,ui_fw,ui_fw) %{_bindir}/sticker-server %attr(0644,root,root) %{_unitdir}/capi-ui-sticker.service %attr(0644,root,root) %{_unitdir}/multi-user.target.wants/capi-ui-sticker.service %attr(0644,root,root) %{_datadir}/dbus-1/system-services/org.tizen.sticker.server.service -- 2.7.4 From 5050e0ce1e47fe4c6f606476ad09c921d5409d0c Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 8 Oct 2019 10:59:53 +0900 Subject: [PATCH 07/16] Fix memory leak detected by static analysis tool Change-Id: I6d2e34c696e47177f2ff67cbdb4784812e05bfba Signed-off-by: Jihoon Kim --- provider/sticker_provider.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/provider/sticker_provider.c b/provider/sticker_provider.c index 474c6a9..3761d6a 100644 --- a/provider/sticker_provider.c +++ b/provider/sticker_provider.c @@ -198,7 +198,8 @@ EXPORT_API int sticker_provider_insert_data_by_json_file(sticker_provider_h prov ret = sticker_dbus_insert_sticker_info_by_json(provider_handle->gdbus_connection, app_id, file_path); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to load json file : %d", ret); - return STICKER_ERROR_OPERATION_FAILED; + ret = STICKER_ERROR_OPERATION_FAILED; + goto cleanup; } provider_handle->insert_finished_cb = callback; -- 2.7.4 From c0d907c5534b7e1a580555af02e874ad4e76a098 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 8 Oct 2019 15:18:03 +0900 Subject: [PATCH 08/16] Fix memory leak Change-Id: Ie57fdd246e3381c19bf7a886899a8ffb26b855c8 Signed-off-by: InHong Han --- client/sticker_dbus.c | 2 +- server/stickerd_data_manager.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index a3e2377..847283a 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -558,7 +558,7 @@ static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder return; } - g_variant_builder_add(keyword_builder, "(s)", strdup((const char *)keyword)); + g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword); } int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data) diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index a3e235d..b0922da 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -902,7 +902,7 @@ static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder return; } - g_variant_builder_add(keyword_builder, "(s)", strdup((const char *)keyword)); + g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword); } int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body) -- 2.7.4 From c37c613fc0656e20d61e50916f2a6aae9457f622 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 8 Oct 2019 15:20:33 +0900 Subject: [PATCH 09/16] Update package version to 0.1.3 Change-Id: Ie333498a2f455f08c4fbc200b40fc9194de39754 --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index caa2293..9bc90ad 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.2 +Version: 0.1.3 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From c25dd19263570ca8b5dac175c1514cc78fa729a5 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 18 Oct 2019 19:44:56 +0900 Subject: [PATCH 10/16] Support to generate gcov package Change-Id: I060934c1a13e9447aa2b370cdf1236f362a31e1c Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 9bc90ad..57ba2cb 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -39,20 +39,39 @@ Requires: %{name} = %{version}-%{release} %description devel Sticker client library and daemon (Development) +%if 0%{?gcov:1} +%package gcov +Summary: Sticker client library and daemon (gcov) +Group: Graphics & UI Framework/Input +%description gcov +Sticker client library and daemon (gcov) +%endif + %prep %setup -q -n %{name}-%{version} cp %{SOURCE2} . %build +%if 0%{?gcov:1} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" +export FFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov" +%endif export CFLAGS+=" -DTIZEN_DEBUG_ENABLE -fvisibility=hidden -Werror" export CXXFLAGS+=" -DTIZEN_DEBUG_ENABLE -fvisibility=hidden -Werror" export FFLAGS+=" -DTIZEN_DEBUG_ENABLE -fvisibility=hidden" -cmake . -DCMAKE_INSTALL_PREFIX=/usr -DLIBDIR=%{_libdir} -DBINDIR=%{_bindir} -DINCLUDEDIR=%{_includedir} \ - -DTZ_SYS_RO_SHARE=%TZ_SYS_RO_SHARE -DTZ_SYS_BIN=%TZ_SYS_BIN -DTZ_SYS_SHARE=%TZ_SYS_SHARE +%cmake . -DCMAKE_INSTALL_PREFIX=/usr -DLIBDIR=%{_libdir} -DBINDIR=%{_bindir} -DINCLUDEDIR=%{_includedir} \ + -DTZ_SYS_RO_SHARE=%TZ_SYS_RO_SHARE -DTZ_SYS_BIN=%TZ_SYS_BIN -DTZ_SYS_SHARE=%TZ_SYS_SHARE make %{?jobs:-j%jobs} +%if 0%{?gcov:1} +mkdir -p gcov-obj +find . -name '*.gcno' -exec cp '{}' gcov-obj ';' +%endif + %install rm -rf %{buildroot} %make_install @@ -67,6 +86,11 @@ install -m 0644 %SOURCE2 %{buildroot}%{_datadir}/dbus-1/system-services/org.tize mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d install -m 0644 %SOURCE3 %{buildroot}%{_sysconfdir}/dbus-1/system.d/capi-ui-sticker.conf +%if 0%{?gcov:1} +mkdir -p %{buildroot}%{_datadir}/gcov/obj +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +%endif + %post /sbin/ldconfig @@ -100,3 +124,8 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %{_includedir}/sticker_data.h %{_includedir}/sticker_consumer.h %{_includedir}/sticker_provider.h + +%if 0%{?gcov:1} +%files gcov +%{_datadir}/gcov/obj/* +%endif -- 2.7.4 From 78cccd3e56fdc5277edd7f26ce5f822f96cb6aea Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 18 Oct 2019 19:53:03 +0900 Subject: [PATCH 11/16] Add exclude section of coverage Change-Id: Idb6ff03963afc7afcdbe639c90fe10ee62f9d14e Signed-off-by: Jihoon Kim --- client/sticker_dbus.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 847283a..12b6722 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -30,10 +30,12 @@ static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, LOGD("name : %s, name_owner : %s", name, name_owner); } +//LCOV_EXCL_START static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data) { LOGD("name : %s", name); } +//LCOV_EXCL_STOP static int _dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id) { @@ -178,6 +180,7 @@ static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVarian } } +//LCOV_EXCL_START static void _handle_sticker_consumer_cb(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -244,6 +247,7 @@ static void _handle_sticker_consumer_cb(GDBusConnection *connection, _free_sticker_data(sticker_data); #endif } +//LCOV_EXCL_STOP static void _handle_sticker_provider_cb(GDBusConnection *connection, const gchar *sender_name, @@ -486,12 +490,14 @@ static void _on_name_appeared(GDBusConnection *connection, _monitor_register(connection); } +//LCOV_EXCL_START static void _on_name_vanished(GDBusConnection *connection, const gchar *name, gpointer user_data) { is_server_started = 0; } +//LCOV_EXCL_STOP int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id, int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data) -- 2.7.4 From c4286a559c95f9d9bef09d028a435c210f99e6fb Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 18 Oct 2019 19:53:43 +0900 Subject: [PATCH 12/16] Update package version to 0.1.4 Change-Id: I1c75f17b4a964d815805671a5fbd291a41f983b6 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 57ba2cb..50c55df 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.3 +Version: 0.1.4 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From ec53be564d596116ed261e6150a8cf98a4e376f9 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 7 Nov 2019 14:03:04 +0900 Subject: [PATCH 13/16] Support on-demand launch Change-Id: I58af3046adb9eef35e85d6466b286b345adfae6e --- client/sticker_dbus.c | 112 +++++++++++++++++----------------- client/sticker_dbus.h | 4 +- consumer/sticker_consumer.c | 3 +- consumer/sticker_consumer_main.h | 2 +- packaging/capi-ui-sticker.spec | 4 +- provider/sticker_provider.c | 3 +- provider/sticker_provider_main.h | 2 +- server/stickerd_data_manager.c | 35 +++++++++-- server/stickerd_dbus.c | 127 +++++++++++++++++++++++---------------- server/stickerd_dbus.h | 3 +- server/stickerd_main.c | 2 +- 11 files changed, 175 insertions(+), 122 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 12b6722..627fe46 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -37,9 +37,10 @@ static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, } //LCOV_EXCL_STOP -static int _dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id) +static int _dbus_init(GDBusConnection **gdbus_connection) { GError *error = NULL; + int watch_id = 0; if (*gdbus_connection == NULL) { GDBusConnection *conn = NULL; @@ -55,17 +56,15 @@ static int _dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_ } LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection)); - if (*server_watcher_id == 0) { - *server_watcher_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM, - STICKER_DBUS_NAME, - G_BUS_NAME_WATCHER_FLAGS_NONE, - _server_appeared_cb, - _server_vanished_cb, - NULL, NULL); - } + watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM, + STICKER_DBUS_NAME, + G_BUS_NAME_WATCHER_FLAGS_NONE, + _server_appeared_cb, + _server_vanished_cb, + NULL, NULL); - LOGD("server_watcher_id : %d", *server_watcher_id); - if (*server_watcher_id == 0) { + LOGD("watch_id : %d", watch_id); + if (watch_id == 0) { LOGE("Failed to get identifier"); return STICKER_CLIENT_ERROR_IO_ERROR; } @@ -413,70 +412,54 @@ static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, return ret; } -static void _gdbus_reply_message_async_cb(GDBusConnection *connection, GAsyncResult *res, gpointer user_data) -{ - GDBusMessage *reply = NULL; - GError *err = NULL; - - reply = g_dbus_connection_send_message_with_reply_finish(connection, res, &err); - - if (reply) { - if (g_dbus_message_to_gerror(reply, &err)) { - LOGE("error message = %s, code = %d", err->message, err->code); - g_error_free(err); - return; - } - } else { - LOGE("There is no reply"); - return; - } - - if (reply) - g_object_unref(reply); - - LOGD("Reply message was received"); - return; -} - static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd) { int ret = STICKER_CLIENT_ERROR_NONE; GDBusMessage *msg = NULL; + GError *err = NULL; msg = _get_gbus_message(body, cmd); if (msg == NULL) return STICKER_CLIENT_ERROR_IO_ERROR; - g_dbus_connection_send_message_with_reply( - gdbus_connection, - msg, - G_DBUS_SEND_MESSAGE_FLAGS_NONE, - -1, - NULL, - NULL, - (GAsyncReadyCallback)_gdbus_reply_message_async_cb, - NULL); + g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err); if (msg) g_object_unref(msg); + if (err != NULL) { + ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY; + LOGE("Error occurred when sending message(%s) : %s", cmd, err->message); + + if (err->code == G_DBUS_ERROR_ACCESS_DENIED) + ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED; + + g_error_free(err); + return ret; + } + return ret; } -static int _monitor_register(GDBusConnection *gdbus_connection) +static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id) { int ret; GDBusMessage *reply = NULL; + GVariant *reply_body = NULL; ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "sticker_service_register"); - if (reply) - g_object_unref(reply); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("_send_sync_message() failed : %d", ret); return ret; } + reply_body = g_dbus_message_get_body(reply); + g_variant_get(reply_body, "(i)", server_watcher_id); + + if (reply) + g_object_unref(reply); + is_server_started = 1; return ret; } @@ -486,8 +469,10 @@ static void _on_name_appeared(GDBusConnection *connection, const gchar *name_owner, gpointer user_data) { - if (is_server_started == 0) - _monitor_register(connection); + if (is_server_started == 0) { + int *watcher_id = (int *)user_data; + _monitor_register(connection, watcher_id); + } } //LCOV_EXCL_START @@ -499,12 +484,12 @@ static void _on_name_vanished(GDBusConnection *connection, } //LCOV_EXCL_STOP -int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id, +int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id, int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data) { int ret; - ret = _dbus_init(gdbus_connection, server_watcher_id); + ret = _dbus_init(gdbus_connection); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("_dbus_init() failed : %d", ret); return ret; @@ -516,7 +501,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_ return ret; } - ret = _monitor_register(*gdbus_connection); + ret = _monitor_register(*gdbus_connection, server_watcher_id); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("_monitor_register() failed : %d", ret); return ret; @@ -529,7 +514,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_ G_BUS_NAME_WATCHER_FLAGS_NONE, _on_name_appeared, _on_name_vanished, - NULL, + server_watcher_id, NULL); if (*server_monitor_id == 0) { g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id); @@ -542,8 +527,22 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_ return STICKER_CLIENT_ERROR_NONE; } -int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_monitor_id, int *monitor_id) +int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id) { + int ret; + GVariant *body = NULL; + + if (server_watcher_id) { + body = g_variant_new("(i)", *server_watcher_id); + ret = _send_async_message(gdbus_connection, body, "sticker_service_unregister"); + if (ret != STICKER_CLIENT_ERROR_NONE) { + LOGE("Failed to unregister sticker service"); + return ret; + } + + *server_watcher_id = 0; + } + if (*server_monitor_id) { g_bus_unwatch_name(*server_monitor_id); *server_monitor_id = 0; @@ -554,6 +553,9 @@ int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_monitor *monitor_id = 0; } + if (body) + g_variant_unref(body); + return STICKER_CLIENT_ERROR_NONE; } diff --git a/client/sticker_dbus.h b/client/sticker_dbus.h index d8fcbcd..44d2309 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -42,9 +42,9 @@ enum sticker_client_error { STICKER_CLIENT_ERROR_IO_ERROR, }; -int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id, +int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id, int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data); -int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_monitor_id, int *monitor_id); +int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id); int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data); int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path); int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id); diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 7b5d544..8602652 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -180,7 +180,8 @@ EXPORT_API int sticker_consumer_destroy(sticker_consumer_h consumer_handle) return STICKER_ERROR_INVALID_PARAMETER; LOGD("consumer_handle : %p", consumer_handle); - ret = sticker_dbus_shutdown(consumer_handle->gdbus_connection, &consumer_handle->server_monitor_id, &consumer_handle->monitor_id); + ret = sticker_dbus_shutdown(consumer_handle->gdbus_connection, &consumer_handle->server_watcher_id, + &consumer_handle->server_monitor_id, &consumer_handle->monitor_id); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to finalize dbus : %d", ret); free(consumer_handle); diff --git a/consumer/sticker_consumer_main.h b/consumer/sticker_consumer_main.h index ba7f90d..7a08ad2 100644 --- a/consumer/sticker_consumer_main.h +++ b/consumer/sticker_consumer_main.h @@ -28,7 +28,7 @@ extern "C" struct sticker_consumer_s { GDBusConnection *gdbus_connection; - guint server_watcher_id; + int server_watcher_id; int monitor_id; int server_monitor_id; }; diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 50c55df..9ded0a6 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -76,9 +76,8 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';' rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants +mkdir -p %{buildroot}%{_prefix}/lib/systemd/system install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/capi-ui-sticker.service -%install_service multi-user.target.wants capi-ui-sticker.service mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services install -m 0644 %SOURCE2 %{buildroot}%{_datadir}/dbus-1/system-services/org.tizen.sticker.server.service @@ -107,7 +106,6 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %{_libdir}/lib*.so %attr(0755,ui_fw,ui_fw) %{_bindir}/sticker-server %attr(0644,root,root) %{_unitdir}/capi-ui-sticker.service -%attr(0644,root,root) %{_unitdir}/multi-user.target.wants/capi-ui-sticker.service %attr(0644,root,root) %{_datadir}/dbus-1/system-services/org.tizen.sticker.server.service %config %{_sysconfdir}/dbus-1/system.d/capi-ui-sticker.conf %{TZ_SYS_RO_SHARE}/parser-plugins/capi-ui-sticker.info diff --git a/provider/sticker_provider.c b/provider/sticker_provider.c index 3761d6a..a271ca6 100644 --- a/provider/sticker_provider.c +++ b/provider/sticker_provider.c @@ -106,7 +106,8 @@ EXPORT_API int sticker_provider_destroy(sticker_provider_h provider_handle) return STICKER_ERROR_INVALID_PARAMETER; LOGD("provider_handle : %p", provider_handle); - ret = sticker_dbus_shutdown(provider_handle->gdbus_connection, &provider_handle->server_monitor_id, &provider_handle->monitor_id); + ret = sticker_dbus_shutdown(provider_handle->gdbus_connection, &provider_handle->server_watcher_id, + &provider_handle->server_monitor_id, &provider_handle->monitor_id); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to finalize dbus : %d", ret); free(provider_handle); diff --git a/provider/sticker_provider_main.h b/provider/sticker_provider_main.h index 6280801..4f1c9dd 100644 --- a/provider/sticker_provider_main.h +++ b/provider/sticker_provider_main.h @@ -28,7 +28,7 @@ extern "C" struct sticker_provider_s { GDBusConnection *gdbus_connection; - guint server_watcher_id; + int server_watcher_id; int monitor_id; int server_monitor_id; sticker_provider_insert_finished_cb insert_finished_cb; diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index b0922da..f7a1e7b 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -42,8 +42,19 @@ #define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data") #define MAX_ERROR_BUFFER 256 -static GHashTable *_monitoring_hash; +static GHashTable *_monitoring_hash = NULL; static char error_buffer[MAX_ERROR_BUFFER]; +extern GMainLoop *main_loop; + +static void _check_watcher_exist() +{ + if (_monitoring_hash != NULL && g_hash_table_size(_monitoring_hash) == 0) { + LOGD("Terminate sticker daemon"); + g_hash_table_destroy(_monitoring_hash); + _monitoring_hash = NULL; + g_main_loop_quit(main_loop); + } +} static void _on_name_appeared(GDBusConnection *connection, const gchar *name, @@ -60,15 +71,19 @@ static void _on_name_vanished(GDBusConnection *connection, monitoring_info_s *info = (monitoring_info_s *)user_data; if (info) { - LOGD("name: %s", name); - g_bus_unwatch_name(info->watcher_id); - delete_monitoring_list(&_monitoring_hash, info->bus_name, info->uid); + if (_monitoring_hash != NULL && g_hash_table_lookup(_monitoring_hash, GUINT_TO_POINTER(info->watcher_id)) != NULL) { + LOGD("name: %s", name); + g_bus_unwatch_name(info->watcher_id); + delete_monitoring_list(&_monitoring_hash, info->bus_name, info->watcher_id); + } if (info->bus_name) free(info->bus_name); free(info); info = NULL; } + + _check_watcher_exist(); } static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, const gchar *sender, const gchar *object_path, @@ -77,12 +92,17 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con { LOGD("stickerd method_name: %s, sender: %s", method_name, sender); + if (_monitoring_hash == NULL) + _monitoring_hash = g_hash_table_new(g_direct_hash, g_direct_equal); + GVariant *reply_body = NULL; int ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; if (g_strcmp0(method_name, "sticker_service_register") == 0) { ret = stickerd_server_register(parameters, &reply_body, sender, _on_name_appeared, _on_name_vanished, &_monitoring_hash); + } else if (g_strcmp0(method_name, "sticker_service_unregister") == 0) { + ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash); } else if (g_strcmp0(method_name, "insert_sticker_info") == 0) { ret = stickerd_insert_sticker_info(parameters, &reply_body); } else if (g_strcmp0(method_name, "update_sticker_info_by_json") == 0) { @@ -131,6 +151,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con if (reply_body) g_variant_unref(reply_body); + + _check_watcher_exist(); } static const GDBusInterfaceVTable _sticker_interface_vtable = { @@ -145,6 +167,11 @@ int stickerd_register_dbus_interface(void) " " " " " " + " " + " " + + " " + " " " " " " diff --git a/server/stickerd_dbus.c b/server/stickerd_dbus.c index 4ff175a..6184033 100644 --- a/server/stickerd_dbus.c +++ b/server/stickerd_dbus.c @@ -29,67 +29,92 @@ #define LOG_TAG "STICKERD_DBUS" static GDBusConnection *_gdbus_connection; +extern GMainLoop *main_loop; int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler, GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash) { - GList *sender_list = NULL; - const char *bus_name = sender; + int ret = STICKERD_SERVER_ERROR_NONE; + char *m_info_bus_name = NULL; + char *list_bus_name = NULL; monitoring_info_s *m_info = NULL; - uid_t request_uid = 0; GList *monitoring_list = NULL; - if (bus_name == NULL) - return STICKERD_SERVER_ERROR_IO_ERROR; - - g_variant_get(parameters, "(i)", &request_uid); - monitoring_list = (GList *)g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(request_uid)); - sender_list = g_list_find_custom(monitoring_list, bus_name, (GCompareFunc) strcmp); + if (reply_body == NULL) + return STICKERD_SERVER_ERROR_INVALID_PARAMETER; - if (sender_list == NULL) { - LOGD("Add a new sender"); - m_info = (monitoring_info_s *)calloc(1, sizeof(monitoring_info_s)); - if (m_info == NULL) { - LOGE("Failed to alloc memory"); - return STICKERD_SERVER_ERROR_IO_ERROR; - } + m_info_bus_name = strdup(sender); + list_bus_name = strdup(sender); + if (m_info_bus_name == NULL || list_bus_name == NULL) { + ret = STICKERD_SERVER_ERROR_IO_ERROR; + goto cleanup; + } - m_info->bus_name = strdup(bus_name); - m_info->uid = request_uid; - m_info->watcher_id = g_bus_watch_name_on_connection( - _gdbus_connection, - bus_name, - G_BUS_NAME_WATCHER_FLAGS_NONE, - name_appeared_handler, - name_vanished_handler, - m_info, - NULL); - if (m_info->watcher_id == 0) { - LOGE("Failed to get identifier"); - free(m_info->bus_name); - free(m_info); - return STICKERD_SERVER_ERROR_IO_ERROR; - } + LOGD("Add a new sender"); + m_info = (monitoring_info_s *)calloc(1, sizeof(monitoring_info_s)); + if (m_info == NULL) { + LOGE("Failed to alloc memory"); + ret = STICKERD_SERVER_ERROR_OUT_OF_MEMORY; + goto cleanup; + } - monitoring_list = g_list_append(monitoring_list, strdup(bus_name)); - LOGD("sender: %s, len: %d", sender, g_list_length(monitoring_list)); - if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(request_uid)) == NULL) - g_hash_table_insert(*monitoring_hash, GUINT_TO_POINTER(request_uid), monitoring_list); - } else { - LOGW("Sender(%s) already exist", sender); + m_info->bus_name = m_info_bus_name; + m_info->watcher_id = g_bus_watch_name_on_connection( + _gdbus_connection, + m_info_bus_name, + G_BUS_NAME_WATCHER_FLAGS_NONE, + name_appeared_handler, + name_vanished_handler, + m_info, + NULL); + if (m_info->watcher_id == 0) { + LOGE("Failed to get identifier"); + ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; + goto cleanup; } - *reply_body = g_variant_new("()"); + *reply_body = g_variant_new("(i)", m_info->watcher_id); if (*reply_body == NULL) { - if (m_info) { - if (m_info->bus_name) - free(m_info->bus_name); - free(m_info); - } - monitoring_list = g_list_remove(monitoring_list, bus_name); LOGE("Failed to make reply"); - return STICKERD_SERVER_ERROR_OUT_OF_MEMORY; + ret = STICKERD_SERVER_ERROR_OUT_OF_MEMORY; + goto cleanup; } + + LOGD("sender: %s, watcher: %d", sender, m_info->watcher_id); + monitoring_list = g_list_append(monitoring_list, list_bus_name); + if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(m_info->watcher_id)) == NULL) + g_hash_table_insert(*monitoring_hash, GUINT_TO_POINTER(m_info->watcher_id), monitoring_list); + else + LOGW("Sender(%s) already exist", sender); + + return STICKERD_SERVER_ERROR_NONE; + +cleanup: + if (m_info_bus_name) + free(m_info_bus_name); + + if (list_bus_name) + free(list_bus_name); + + if (m_info) { + free(m_info); + m_info = NULL; + } + + return ret; +} + +int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash) +{ + int watcher_id = 0; + + g_variant_get(parameters, "(i)", &watcher_id); + + if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(watcher_id)) != NULL) { + g_bus_unwatch_name(watcher_id); + delete_monitoring_list(monitoring_hash, sender, watcher_id); + } + return STICKERD_SERVER_ERROR_NONE; } @@ -156,15 +181,15 @@ cleanup: return result; } -int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, uid_t uid) +int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, int watcher_id) { GList *monitoring_list = NULL; GList *del_list = NULL; char *bus_name; - monitoring_list = (GList *)g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(uid)); + monitoring_list = (GList *)g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(watcher_id)); if (monitoring_list == NULL) { - LOGE("The key(%d) is not found", uid); + LOGE("The key(%d) is not found", watcher_id); return STICKERD_SERVER_ERROR_IO_ERROR; } @@ -179,10 +204,10 @@ int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, uid monitoring_list = g_list_delete_link(monitoring_list, del_list); if (monitoring_list == NULL) { - g_hash_table_steal(*monitoring_hash, GUINT_TO_POINTER(uid)); + g_hash_table_steal(*monitoring_hash, GUINT_TO_POINTER(watcher_id)); } else { monitoring_list = g_list_first(monitoring_list); - g_hash_table_replace(*monitoring_hash, GUINT_TO_POINTER(uid), monitoring_list); + g_hash_table_replace(*monitoring_hash, GUINT_TO_POINTER(watcher_id), monitoring_list); } } return STICKERD_SERVER_ERROR_NONE; diff --git a/server/stickerd_dbus.h b/server/stickerd_dbus.h index 0197793..e8ad143 100644 --- a/server/stickerd_dbus.h +++ b/server/stickerd_dbus.h @@ -28,14 +28,13 @@ extern "C" { typedef struct monitoring_info { int watcher_id; char *bus_name; - uid_t uid; } monitoring_info_s; int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler, GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash); int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash); int stickerd_server_register_dbus_interface(char *introspection_xml, GDBusInterfaceVTable interface_vtable); -int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, uid_t uid); +int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, int monitoring_id); int stickerd_send_dbus_message(GVariant *body, const char *dest, char *cmd, CLIENT_LIB lib); #ifdef __cplusplus diff --git a/server/stickerd_main.c b/server/stickerd_main.c index 1650437..38d92f9 100644 --- a/server/stickerd_main.c +++ b/server/stickerd_main.c @@ -33,7 +33,7 @@ #define MAX_ERROR_BUFFER 256 -static GMainLoop *main_loop; +GMainLoop *main_loop = NULL; static GIOChannel *channel = NULL; static guint source = 0; -- 2.7.4 From 9d879d10c44c93e68709166a5dc6a1cf58488fb8 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 18 Dec 2019 16:20:12 +0900 Subject: [PATCH 14/16] Change reference link in doc file Change-Id: I84396053b9b2550fd99775040f2511c64708f4fc --- doc/sticker_doc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sticker_doc.h b/doc/sticker_doc.h index 9c7b385..4c3b325 100644 --- a/doc/sticker_doc.h +++ b/doc/sticker_doc.h @@ -33,7 +33,7 @@ * It is recommended to design feature related codes in your application for reliability.\n * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n - * More details on featuring your application can be found from Feature Element. + * More details on featuring your application can be found from Feature Element. * */ -- 2.7.4 From 5c2ee9ac85ba27ccd05ad2ce1244901a06d25aa6 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 14 Nov 2019 11:16:33 +0900 Subject: [PATCH 15/16] Exclude dbus file in coverage Change-Id: Ia70b430d1e0df296717a2c8e1444034fbc552d21 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 9ded0a6..bef1c8e 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -69,6 +69,7 @@ make %{?jobs:-j%jobs} %if 0%{?gcov:1} mkdir -p gcov-obj +find . -name '*_dbus.c.gcno' -exec rm {} \; find . -name '*.gcno' -exec cp '{}' gcov-obj ';' %endif -- 2.7.4 From 6db0cc6fc8e418d7ee33239850fce316b5821ac8 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 3 Jan 2020 10:49:46 +0900 Subject: [PATCH 16/16] Add logs for opening file Change-Id: Ie1e88bd867def7d98dacf2b5a161e8fb3a54aacd Signed-off-by: Jihoon Kim --- server/stickerd_data_manager.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index f7a1e7b..486e929 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -400,7 +400,14 @@ static int _file_copy(const char *src, const char *dest) memset(buf, '\0', 4096); fd = open(src, O_RDONLY); + if (fd == -1) { + LOGE("Failed to open file (%s) for reading", src); + } + n_fd = open(dest, O_WRONLY | O_CREAT | O_TRUNC, 0755); + if (n_fd == -1) { + LOGE("Failed to open file (%s) for writing", dest); + } if (fd == -1 || n_fd == -1) { tmp_err = errno; -- 2.7.4