From 658a001a3707f5c5ccbb98d6f861e52cfe33efa1 Mon Sep 17 00:00:00 2001 From: Jinhyung Jo Date: Wed, 23 Aug 2017 11:23:58 +0900 Subject: [PATCH 01/16] appcmd: change argument from local to heap Change-Id: I708ae784d24cbd5394d2787bf15b53b27ee33c16 Signed-off-by: Jinhyung Jo --- src/plugin.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index fd6ceb8..2e257fe 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -212,6 +212,8 @@ static void request_async_cmd ( int cmd, parameters* in, int out_fd ) ret = default_plugin_async_proc ( cmd, in, out_fd ); } + release_parameters(in); + free(in); sdb_close(out_fd); } @@ -229,21 +231,31 @@ static int create_async_proc_thread( int cmd, parameters* in ) sdb_thread_t t; int s[2]; - if( sdb_socketpair(s) ) { + if (sdb_socketpair(s)) { + release_parameters(in); + free(in); D("cannot create async proc socket pair\n"); return -1; } - async_param = ( async_parameter* ) malloc(sizeof(async_parameter)); - if( async_param == NULL ) fatal("cannot allocate async_parameter"); + async_param = (async_parameter*)malloc(sizeof(async_parameter)); + if (async_param == NULL) { + release_parameters(in); + free(in); + fatal("cannot allocate async_parameter"); + return -1; + } + async_param->cmd = cmd; async_param->in = in; async_param->out_fd = s[1]; - if(sdb_thread_create( &t, async_proc_bootstrap_func, async_param)){ + if (sdb_thread_create(&t, async_proc_bootstrap_func, async_param)) { free(async_param); sdb_close(s[0]); sdb_close(s[1]); + release_parameters(in); + free(in); D("cannot create async proc thread\n"); return -1; } @@ -396,27 +408,33 @@ int request_lock_state_to_plugin ( int lock_type ) // return -1 if failed to create async proc thread int request_appcmd_to_plugin ( const char* in_buf ) { - parameters in; + parameters* in; int fd; + in = (parameters*)malloc(sizeof(parameters)); + if (in == NULL) { + D("failed to allocate memory for the parameters\n"); + return -1; + } + if ( in_buf != NULL ) { - in.number_of_parameter = 1; - in.array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) ); - if (in.array_of_parameter == NULL) { + in->number_of_parameter = 1; + in->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) ); + if (in->array_of_parameter == NULL) { + free(in); D("failed to allocate memory for the parameter\n"); return -1; } - in.array_of_parameter[0].type = type_string; - in.array_of_parameter[0].v_string.length = strlen ( in_buf ); - in.array_of_parameter[0].v_string.data = strdup ( in_buf ); + in->array_of_parameter[0].type = type_string; + in->array_of_parameter[0].v_string.length = strlen ( in_buf ); + in->array_of_parameter[0].v_string.data = strdup ( in_buf ); } else { - in.number_of_parameter = 0; - in.array_of_parameter = NULL; + in->number_of_parameter = 0; + in->array_of_parameter = NULL; } - fd = create_async_proc_thread( PLUGIN_ASYNC_CMD_APPCMD_SERVICE, &in ); + fd = create_async_proc_thread( PLUGIN_ASYNC_CMD_APPCMD_SERVICE, in ); - release_parameters ( &in ); return fd; } -- 2.7.4 From 1560a95a7067bd956b578a05b84f1f774e5180f0 Mon Sep 17 00:00:00 2001 From: Jinhyung Jo Date: Wed, 23 Aug 2017 13:54:15 +0900 Subject: [PATCH 02/16] package: update version (3.0.35) Change-Id: I1e8537183d81eb117354adb4f7a4b97d05b0f32f Signed-off-by: Jinhyung Jo --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 85d2300..c8f7e71 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.34 +Version: 3.0.35 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From 87037ecc50670f4e3b6e801df933f2a90328586f Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Thu, 7 Sep 2017 15:33:33 +0900 Subject: [PATCH 03/16] packaging: modify user and group of tcp service Change-Id: Ia67f0da66d2326898d19e8e9effeb91c65eb3d4f Signed-off-by: Sooyoung Ha --- packaging/sdbd_tcp.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/sdbd_tcp.service b/packaging/sdbd_tcp.service index 9995740..7ff330d 100644 --- a/packaging/sdbd_tcp.service +++ b/packaging/sdbd_tcp.service @@ -3,6 +3,8 @@ Description=sdbd After=default.target [Service] +User=sdk +Group=sdk Type=forking Environment=DISPLAY=:0 #If necessary, Put Environment variable settings in a file like below -- 2.7.4 From 814003e36e1b7c4fd9a3a19b1929d67bd6c9e097 Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Fri, 8 Sep 2017 18:05:01 +0900 Subject: [PATCH 04/16] package: update version (3.0.36) Change-Id: I2be9a7801aa4eb64ae68a517e2eae892aeb521b4 Signed-off-by: Sooyoung Ha --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index c8f7e71..b7ff09d 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.35 +Version: 3.0.36 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From 2906cdafd12e4414bcf261b2b7e74c97ebe6a5e7 Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Tue, 19 Sep 2017 11:36:33 +0900 Subject: [PATCH 05/16] secure: change insecure system function system() -> fork() + execve() Change-Id: I0a8a062013dddfbce03f11ddb6e02962775eb3e9 Signed-off-by: Sooyoung Ha --- src/sdb.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index 7b81403..f614bfb 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1671,6 +1671,29 @@ static int init_sdk_userinfo() { return 0; } +static int safe_system(char *cmd, char *argv[], char *envp[]) { + pid_t pid; + int status; + + pid = fork(); + switch (pid) { + case -1: + return -1; + case 0: + execve(cmd, argv, envp); + D("- exec '%s' failed: (errno:%d) -\n", cmd, errno); + exit(-1); + default: + for (;;) { + pid_t p = waitpid(pid, &status, 0); + if (p == pid) { + break; + } + } + } + return 0; +} + static void init_sdk_requirements() { struct stat st; @@ -1684,11 +1707,35 @@ static void init_sdk_requirements() { if (g_sdk_home_dir != NULL && stat(g_sdk_home_dir, &st) == 0) { if (st.st_uid != g_sdk_user_id || st.st_gid != g_sdk_group_id) { - char cmd[128]; - snprintf(cmd, sizeof(cmd), "/usr/bin/chown %s:%s %s -R", SDK_USER_NAME, SDK_USER_NAME, g_sdk_home_dir); - if (system(cmd) < 0) { + char* cmd = "/usr/bin/chown"; + char params[128]; + char* envp[128]; + int envp_cnt = 0; + int i = 0; + + envp[envp_cnt++] = g_strdup("TERM=linux"); + envp[envp_cnt++] = g_strdup("DISPLAY=:0"); + envp[envp_cnt] = NULL; + + snprintf(params, sizeof(params), "%s %s:%s %s -R", cmd, SDK_USER_NAME, SDK_USER_NAME, g_sdk_home_dir); + + char* args[] = { + cmd, + params, + NULL, + }; + if (safe_system(cmd, args, envp) < 0) { D("failed to change ownership to sdk user to %s\n", g_sdk_home_dir); } + + /* free environment variables */ + if (envp_cnt > 0) { + for (i = 0; i < envp_cnt; i++) { + if (envp[i]) { + g_free(envp[i]); + } + } + } } } -- 2.7.4 From 59664783234a29d7ae553f03efa8c75afeb5c0fd Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Tue, 19 Sep 2017 11:37:52 +0900 Subject: [PATCH 06/16] package: update version (3.0.37) Change-Id: I19f19ba2b4acbe6b745233ff1179e6452aa3ef3e Signed-off-by: Sooyoung Ha --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index b7ff09d..37840ee 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.36 +Version: 3.0.37 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From a81bccd7f0fc6fe64a991455a7d72810746112ac Mon Sep 17 00:00:00 2001 From: Jinhyung Jo Date: Mon, 25 Sep 2017 17:36:20 +0900 Subject: [PATCH 07/16] service: fix a bug in crash report service Added to watch for the move event. Change-Id: I1e2a8e39217f25d19bc9c84c3dab663311fb5523 Signed-off-by: Jinhyung Jo --- src/services.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/services.c b/src/services.c index ea991c2..2976230 100644 --- a/src/services.c +++ b/src/services.c @@ -227,7 +227,7 @@ void inoti_service(int fd, void *arg) return; } - wd = inotify_add_watch( ifd, CS_PATH, IN_CREATE); + wd = inotify_add_watch(ifd, CS_PATH, IN_CREATE | IN_MOVE); if ( wd < 0 ) { D("inotify_add_watch failed (errno :%d)\n", errno); sdb_close(ifd); @@ -259,6 +259,18 @@ void inoti_service(int fd, void *arg) D( "asprintf was failed\n" ); } } + } else if (event->mask & IN_MOVE) { + if (!(event->mask & IN_ISDIR)) { + char *cspath = NULL; + int len = asprintf(&cspath, "%s/%s", CS_PATH, event->name); + if (len >= 0) { + D("The file %s was moved.\n", cspath); + writex(fd, cspath, len); + free(cspath); + } else { + D("asprintf was failed\n"); + } + } } } if (i + EVENT_SIZE + event->len < event->len) { // in case of integer overflow -- 2.7.4 From b478e56d3de022f1fb5cb755bfd48473c787bf64 Mon Sep 17 00:00:00 2001 From: Jinhyung Jo Date: Mon, 25 Sep 2017 18:13:27 +0900 Subject: [PATCH 08/16] package: update version (3.0.38) Change-Id: I814eec175f304dbfb2640a2747255ab2d39c45eb Signed-off-by: Jinhyung Jo --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 37840ee..39c16ee 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.37 +Version: 3.0.38 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From 23da1328e674bade6c281c5cef46ce770a7090ae Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Tue, 10 Oct 2017 13:50:30 +0900 Subject: [PATCH 09/16] source: fix some risky codes Change-Id: I09660d031e04a3318849c49f2fe933f6388e0627 Signed-off-by: Sooyoung Ha --- src/default_plugin_appcmd.c | 4 ++-- src/sdb.c | 13 ++++++------- src/services.c | 1 + src/subprocess.c | 1 + src/transport.c | 1 + 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/default_plugin_appcmd.c b/src/default_plugin_appcmd.c index 8ffb4e3..bd4986c 100644 --- a/src/default_plugin_appcmd.c +++ b/src/default_plugin_appcmd.c @@ -315,7 +315,7 @@ static void appcmd_receiver_default(int fd_in, int fd_out) for(;;) { memset(buf, 0, sizeof(buf)); - r = sdb_read(fd_in, buf, sizeof(buf)); + r = sdb_read(fd_in, buf, sizeof(buf)-1); if (r == 0) { break; } else if(r < 0) { @@ -480,11 +480,11 @@ static int exec_appcmd_shell_process(appcmd_info* p_info) { args[2] = p_info->shell_cmd; ptm_fd = create_subprocess(SHELL_COMMAND, &pid, (char * const*)args, (char * const*)envp); - D("create_subprocess() ptm_fd=%d pid=%d\n", ptm_fd, pid); if (ptm_fd < 0) { D("cannot create service thread\n"); return -1; } + D("create_subprocess() ptm_fd=%d pid=%d\n", ptm_fd, pid); if (p_info->receiver_func != NULL) { p_info->receiver_func(ptm_fd, p_info->fd); diff --git a/src/sdb.c b/src/sdb.c index f614bfb..efb8999 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1176,25 +1176,24 @@ void start_device_log(void) char path_file[PATH_MAX] = {0, }; struct tm now; time_t t; -// char value[PROPERTY_VALUE_MAX]; - char* p_trace = get_sdb_log_conf("SDB_TRACE"); - char* p_path = get_sdb_log_conf("SDBD_LOG_PATH"); + // read the trace mask from persistent property persist.sdb.trace_mask // give up if the property is not set or cannot be parsed - + char* p_trace = get_sdb_log_conf("SDB_TRACE"); if ((p_trace == NULL ) && !is_enable_sdbd_log()) { return; } else { free(p_trace); } - + char* p_path = get_sdb_log_conf("SDBD_LOG_PATH"); if (p_path) { snprintf(path_folder, sizeof(path_folder), "%s", p_path); free(p_path); - } else if (g_capabilities.log_path[0] != '\0') + } else if (g_capabilities.log_path[0] != '\0') { snprintf(path_folder, sizeof(path_folder), "%s", g_capabilities.log_path); - else + } else { return; + } tzset(); time(&t); diff --git a/src/services.c b/src/services.c index 2976230..b8fd31a 100644 --- a/src/services.c +++ b/src/services.c @@ -455,6 +455,7 @@ static ssize_t recv_fd(int fd, void *ptr, size_t nbytes, int *recvfd) } control_un; ssize_t ret; + memset(&msg, 0, sizeof(msg)); msg.msg_control = control_un.control; msg.msg_controllen = sizeof(control_un.control); diff --git a/src/subprocess.c b/src/subprocess.c index 6eb3ca0..9241d85 100644 --- a/src/subprocess.c +++ b/src/subprocess.c @@ -40,6 +40,7 @@ static ssize_t send_fd(int fd, void *ptr, size_t nbytes, int sendfd) char control[CMSG_SPACE(sizeof(int))]; } control_un; + memset(&msg, 0, sizeof(msg)); msg.msg_control = control_un.control; msg.msg_controllen = sizeof(control_un.control); diff --git a/src/transport.c b/src/transport.c index d6ecd66..49895e7 100644 --- a/src/transport.c +++ b/src/transport.c @@ -823,6 +823,7 @@ void broadcast_transport(apacket *p) t->connection_state = CS_PWLOCK; } } + put_apacket(ap); } } sdb_mutex_unlock(&transport_lock); -- 2.7.4 From b025dbcad47db0173a6100dfc7e0cbb7b30f4fac Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Tue, 10 Oct 2017 13:51:31 +0900 Subject: [PATCH 10/16] package: update version (3.0.39) Change-Id: I63990255b41482fe7d6985f368253f4f4aa6dd1a Signed-off-by: Sooyoung Ha --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 39c16ee..a90bd1c 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.38 +Version: 3.0.39 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From 1a356cc2a085e2e408ad50a8c49d111687d011f5 Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Tue, 10 Oct 2017 14:01:12 +0900 Subject: [PATCH 11/16] source: add g_main_loop_unref for finished mainloop Change-Id: Iefd46e1882cee1011454eafee4414e4130df21d9 Signed-off-by: Sooyoung Ha --- src/sdb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdb.c b/src/sdb.c index efb8999..a9820bd 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1361,6 +1361,7 @@ static void *bootdone_cb(void *x) { g_main_loop_run(mainloop); D("dbus loop exited"); + g_main_loop_unref(mainloop); dbus_connection_unref(bus); return NULL; -- 2.7.4 From e058b173eab3798595782878f3cb1b48c579af3c Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Tue, 10 Oct 2017 14:02:09 +0900 Subject: [PATCH 12/16] package: update version (3.0.40) Change-Id: I21ea7beee26cd393bd589007f9cc52758955ed26 Signed-off-by: Sooyoung Ha --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index a90bd1c..7705184 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.39 +Version: 3.0.40 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From 8e6db1f76ab7204528a0a47131b0b06aa9df5411 Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Wed, 11 Oct 2017 20:48:03 +0900 Subject: [PATCH 13/16] transport: do not free broadcast transport packet Change-Id: I581877a737e4b860061fca8b62b89ea31d39b695 Signed-off-by: Sooyoung Ha --- src/transport.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/transport.c b/src/transport.c index 49895e7..d6ecd66 100644 --- a/src/transport.c +++ b/src/transport.c @@ -823,7 +823,6 @@ void broadcast_transport(apacket *p) t->connection_state = CS_PWLOCK; } } - put_apacket(ap); } } sdb_mutex_unlock(&transport_lock); -- 2.7.4 From fbef2a86c98ba4d70273fc302f72cc0fe163ea8f Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Wed, 11 Oct 2017 20:49:04 +0900 Subject: [PATCH 14/16] package: update version (3.0.41) Change-Id: I749e0ddd0190e1e9c2d39062676b5ec8af413f94 Signed-off-by: Sooyoung Ha --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 7705184..00815b0 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.40 +Version: 3.0.41 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From fbb3887c013b52229f5310006ec3df850299062a Mon Sep 17 00:00:00 2001 From: Jinhyung Jo Date: Tue, 10 Oct 2017 18:06:20 +0900 Subject: [PATCH 15/16] dbus: change from dbus-glib API to GDBus API As mentioned in the URL below: https://dbus.freedesktop.org/doc/dbus-glib/ dbus-glib is a deprecated API for use of D-Bus from GLib applications. Do not use it in new code. Since version 2.26, GLib's accompanying GIO library provides a high-level API for D-Bus, "GDBus", based on an independent reimplementation of the D-Bus protocol. The maintainers of D-Bus recommend that GLib applications should use GDBus instead of dbus-glib. Change-Id: I5754e0c40fdb246e0a29766ae795e6dcaebc07e4 Signed-off-by: Jinhyung Jo --- CMakeLists.txt | 3 +- packaging/sdbd.spec | 3 +- src/sdb.c | 134 ++++++++++++++++++++++++++-------------------------- 3 files changed, 69 insertions(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e06a26d..3bc41e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,8 +70,7 @@ pkg_check_modules(pkgs REQUIRED capi-system-info vconf glib-2.0 - dbus-1 - dbus-glib-1 + gio-2.0 dlog ) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 00815b0..372ceb7 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -23,8 +23,7 @@ BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(dbus-1) -BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) Requires: dbus Provides: %{name}-profile_common = %{version}-%{release} diff --git a/src/sdb.c b/src/sdb.c index a9820bd..cd9bada 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1280,101 +1280,101 @@ int should_drop_privileges() { return 1; } -#include -#include -#include +#include +#define DEVICED_BUS "org.tizen.system.deviced" +#define DEVICED_CORE_PATH "/Org/Tizen/System/DeviceD/Core" #define BOOTING_DONE_SIGNAL "BootingDone" #define DEVICED_CORE_INTERFACE "org.tizen.system.deviced.core" -#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info" +#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info" -static DBusHandlerResult __sdbd_dbus_signal_filter(DBusConnection *conn, - DBusMessage *message, void *user_data) { - D("got dbus message\n"); - const char *interface; +static GMainLoop *g_mainloop; - DBusError error; - dbus_error_init(&error); - - interface = dbus_message_get_interface(message); - if (interface == NULL) { - D("reject by security issue - no interface\n"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +static void booting_done_signal_subscriber(GDBusConnection *connection, + const gchar *sender, const gchar *path, const gchar *interface, + const gchar *signal, GVariant *parameters, gpointer user_data) +{ + if (g_strcmp0(signal, BOOTING_DONE_SIGNAL) != 0) { + D("received signal(%s) does not match the desired signal(%s)\n", + signal, BOOTING_DONE_SIGNAL); + return; } - if (dbus_message_is_signal(message, DEVICED_CORE_INTERFACE, - BOOTING_DONE_SIGNAL)) { - booting_done = 1; - if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) { - D("booting is done before\n"); - } else { - FILE *f = fopen(SDBD_BOOT_INFO_FILE, "w"); - if (f != NULL) { - fprintf(f, "%d", 1); - fclose(f); - } + D("received the \"%s\" signal\n", signal); + + booting_done = 1; + if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) { + D("booting is already done\n"); + } else { + FILE *info_file = fopen(SDBD_BOOT_INFO_FILE, "w"); + if (info_file != NULL) { + fprintf(info_file, "%d", 1); + fclose(info_file); } D("booting is done\n"); } - D("handled dbus message\n"); - return DBUS_HANDLER_RESULT_HANDLED; + D("handled the booting done signal\n"); + g_main_loop_quit(g_mainloop); } -static void *bootdone_cb(void *x) { - int MAX_LOCAL_BUFSZ = 128; - DBusError error; - DBusConnection *bus; - char rule[MAX_LOCAL_BUFSZ]; - GMainLoop *mainloop; - -/* g_type_init() is deprecated for glib version 2.35.0 or greater, */ -#if !GLIB_CHECK_VERSION(2,35,0) - g_type_init(); -#endif - - dbus_error_init(&error); - bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); - if (!bus) { - D("Failed to connect to the D-BUS daemon: %s", error.message); - dbus_error_free(&error); +static void *bootdone_cb(void *args) +{ + GError *error = NULL; + GDBusConnection *connection = NULL; + guint id; + + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (connection == NULL) { + if (error != NULL) { + D("failed to connect to the system bus: %s\n", error->message); + g_error_free(error); + } else { + D("failed to connect to the system bus\n"); + } return NULL; } - dbus_connection_setup_with_g_main(bus, NULL); - snprintf(rule, MAX_LOCAL_BUFSZ, "type='signal',interface='%s'", - DEVICED_CORE_INTERFACE); - /* listening to messages */ - dbus_bus_add_match(bus, rule, &error); - if (dbus_error_is_set(&error)) { - D("Fail to rule set: %s", error.message); - dbus_error_free(&error); - return NULL; + g_mainloop = g_main_loop_new(NULL, false); + if (g_mainloop == NULL) { + D("failed to create a g_main_loop\n"); + goto bootdone_out; } - if (dbus_connection_add_filter(bus, __sdbd_dbus_signal_filter, NULL, NULL) - == FALSE) - return NULL; + id = g_dbus_connection_signal_subscribe(connection, + DEVICED_BUS, DEVICED_CORE_INTERFACE, BOOTING_DONE_SIGNAL, + DEVICED_CORE_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + booting_done_signal_subscriber, NULL, NULL); + if (id == 0) { + D("failed to subscribe to the booting done signal\n"); + goto bootdone_out; + } - D("booting signal initialized\n"); - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); + D("wait for the booting done signal\n"); + g_main_loop_run(g_mainloop); - D("dbus loop exited"); - g_main_loop_unref(mainloop); - dbus_connection_unref(bus); + g_dbus_connection_signal_unsubscribe(connection, id); + +bootdone_out: + if (g_mainloop != NULL) { + g_main_loop_unref(g_mainloop); + } + if (connection != NULL) { + g_object_unref(connection); + } + D("exit the bootdone_cb thread\n"); return NULL; } -void register_bootdone_cb() { - D("registerd bootdone callback\n"); - +void register_bootdone_cb() +{ sdb_thread_t t; if (sdb_thread_create(&t, bootdone_cb, NULL)) { - D("cannot create service thread\n"); + D("can not create a service thread to check the booting done\n"); return; } + D("created the bootdone_cb thread\n"); } static int sdbd_set_groups(const char *name, int gid, struct group_info default_groups[], int default_groups_size) { -- 2.7.4 From a4cd4e14dbf55d87886f9e3558ce920b79174ed8 Mon Sep 17 00:00:00 2001 From: Jinhyung Jo Date: Wed, 11 Oct 2017 15:50:02 +0900 Subject: [PATCH 16/16] package: update version (3.0.42) Change-Id: I44989f6d30412a1b596e6da8a00314766e59e290 Signed-off-by: Jinhyung Jo --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 372ceb7..894d2ca 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.41 +Version: 3.0.42 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4