From: Sangchul Lee Date: Mon, 4 Sep 2017 06:59:30 +0000 (+0900) Subject: Revise dbus error handling codes to be more defensive X-Git-Tag: accepted/tizen/unified/20170914.230142~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd1f4dc00973cbca682cfddf768da84d4df5bc14;p=platform%2Fcore%2Fmultimedia%2Flibmm-sound.git Revise dbus error handling codes to be more defensive [Version] 0.11.22 [Issue Type] Enhancement Change-Id: Ic433b6e794efc9256799a4bc09cdb535655b8e76 Signed-off-by: Sangchul Lee --- diff --git a/common/mm_sound_dbus.c b/common/mm_sound_dbus.c index 17799fa..5ddc30f 100644 --- a/common/mm_sound_dbus.c +++ b/common/mm_sound_dbus.c @@ -256,16 +256,18 @@ static int _dbus_method_call(GDBusConnection *conn, const char *bus_name, const method, args , NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); - if (!dbus_reply) { + if (!dbus_reply || err) { char *err_name = NULL, *err_msg = NULL; - debug_error("Method Call '%s.%s' Failed, %s", intf, method, err->message); - - if (_parse_error_msg(err->message, &err_name, &err_msg) < 0) { - debug_error("failed to parse error message"); - g_error_free(err); - return MM_ERROR_SOUND_INTERNAL; + debug_error("Method Call '%s.%s' Failed, %s", intf, method, err ? err->message : NULL); + ret = MM_ERROR_SOUND_INTERNAL; + if (err) { + if (_parse_error_msg(err->message, &err_name, &err_msg) < 0) { + debug_error("failed to parse error message"); + g_error_free(err); + return MM_ERROR_SOUND_INTERNAL; + } + ret = _convert_error_name(err_name); } - ret = _convert_error_name(err_name); g_error_free(err); } else { debug_log("Method Call '%s.%s' Success", intf, method); @@ -323,9 +325,11 @@ static GDBusConnection * _dbus_get_connection(GBusType bustype) debug_log("Already connected to system bus"); } else { debug_log("Get new connection on system bus"); - if (!(conn_system = g_bus_get_sync(bustype, NULL, &err))) { - debug_error("g_dbus_get_sync() error (%s)", err->message); + conn_system = g_bus_get_sync(bustype, NULL, &err); + if (!conn_system || err) { + debug_error ("g_dbus_get_sync() error (%s)", err ? err->message : NULL); g_error_free(err); + return NULL; } } return conn_system; @@ -334,9 +338,11 @@ static GDBusConnection * _dbus_get_connection(GBusType bustype) debug_log("Already connected to session bus"); } else { debug_log("Get new connection on session bus"); - if (!(conn_session = g_bus_get_sync(bustype, NULL, &err))) { - debug_error("g_dbus_get_sync() error (%s)", err->message); + conn_session = g_bus_get_sync(bustype, NULL, &err); + if (!conn_session || err) { + debug_error ("g_dbus_get_sync() error (%s)", err ? err->message : NULL); g_error_free(err); + return NULL; } } return conn_session; @@ -507,12 +513,12 @@ int mm_sound_dbus_emit_signal(audio_provider_t provider, audio_event_t event, GV return MM_ERROR_SOUND_INTERNAL; } - dbus_ret = g_dbus_connection_emit_signal(conn, - NULL, g_paths[provider].object, - g_paths[provider].interface, g_events[event].name, - param, &err); - if (!dbus_ret) { - debug_error("g_dbus_connection_emit_signal() error (%s)", err->message); + dbus_ret = g_dbus_connection_emit_signal (conn, + NULL, g_paths[provider].object, + g_paths[provider].interface, g_events[event].name, + param, &err); + if (!dbus_ret || err) { + debug_error ("g_dbus_connection_emit_signal() error (%s)", err ? err->message : NULL); g_error_free(err); return MM_ERROR_SOUND_INTERNAL; } diff --git a/focus_server/mm_sound_mgr_focus_dbus.c b/focus_server/mm_sound_mgr_focus_dbus.c index b8942d3..3a08799 100644 --- a/focus_server/mm_sound_mgr_focus_dbus.c +++ b/focus_server/mm_sound_mgr_focus_dbus.c @@ -688,8 +688,8 @@ int __mm_sound_mgr_focus_dbus_get_stream_list(stream_list_t* stream_list) int i = 0; conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (!conn && err) { - LOGE("g_bus_get_sync() error (%s)", err->message); + if (!conn || err) { + LOGE("g_bus_get_sync() error (%s)", err ? err->message : NULL); g_error_free(err); ret = MM_ERROR_SOUND_INTERNAL; return ret; @@ -705,8 +705,9 @@ int __mm_sound_mgr_focus_dbus_get_stream_list(stream_list_t* stream_list) 2000, NULL, &err); - if (!result && err) { - debug_error("g_dbus_connection_call_sync() error (%s)", err->message); + if (!result || err) { + debug_error("g_dbus_connection_call_sync() error (%s)", err ? err->message : NULL); + g_error_free(err); ret = MM_ERROR_SOUND_INTERNAL; } else { GVariantIter iter; @@ -734,9 +735,9 @@ int __mm_sound_mgr_focus_dbus_get_stream_list(stream_list_t* stream_list) } g_variant_unref(item); g_variant_unref(child); - - g_variant_unref(result); } + + g_variant_unref(result); g_object_unref(conn); return ret; diff --git a/mm_sound.c b/mm_sound.c index 5c7953f..3490e36 100644 --- a/mm_sound.c +++ b/mm_sound.c @@ -631,8 +631,8 @@ int mm_sound_subscribe_signal(mm_sound_signal_name_t signal_type, unsigned int * subscribe_cb->user_data = user_data; g_dbus_conn_mmsound = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (!g_dbus_conn_mmsound && err) { - debug_error ("g_bus_get_sync() error (%s) ", err->message); + if (!g_dbus_conn_mmsound || err) { + debug_error ("g_bus_get_sync() error (%s) ", err ? err->message : NULL); g_error_free (err); ret = MM_ERROR_SOUND_INTERNAL; goto error; @@ -697,8 +697,8 @@ int mm_sound_subscribe_signal_for_daemon(mm_sound_signal_name_t signal_type, int subscribe_cb->client_pid = client_pid; g_dbus_conn_mmsound = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (!g_dbus_conn_mmsound && err) { - debug_error ("g_bus_get_sync() error (%s) ", err->message); + if (!g_dbus_conn_mmsound || err) { + debug_error ("g_bus_get_sync() error (%s) ", err ? err->message : NULL); g_error_free (err); ret = MM_ERROR_SOUND_INTERNAL; goto error; @@ -767,8 +767,8 @@ int mm_sound_send_signal(mm_sound_signal_name_t signal_type, int value) } conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (!conn && err) { - debug_error ("g_bus_get_sync() error (%s)", err->message); + if (!conn || err) { + debug_error ("g_bus_get_sync() error (%s)", err ? err->message : NULL); ret = MM_ERROR_SOUND_INTERNAL; goto error; } @@ -786,15 +786,15 @@ int mm_sound_send_signal(mm_sound_signal_name_t signal_type, int value) NULL, MM_SOUND_DBUS_OBJECT_PATH, MM_SOUND_DBUS_INTERFACE, dbus_signal_name_str[signal_type], g_variant_new ("(i)", value), &err); - if (!dbus_ret && err) { - debug_error ("g_dbus_connection_emit_signal() error (%s)", err->message); + if (!dbus_ret || err) { + debug_error ("g_dbus_connection_emit_signal() error (%s)", err ? err->message : NULL); ret = MM_ERROR_SOUND_INTERNAL; goto error; } dbus_ret = g_dbus_connection_flush_sync(conn, NULL, &err); - if (!dbus_ret && err) { - debug_error ("g_dbus_connection_flush_sync() error (%s)", err->message); + if (!dbus_ret || err) { + debug_error ("g_dbus_connection_flush_sync() error (%s)", err ? err->message : NULL); ret = MM_ERROR_SOUND_INTERNAL; goto error; } diff --git a/mm_sound_keysound.c b/mm_sound_keysound.c index 558a8c6..99a5627 100644 --- a/mm_sound_keysound.c +++ b/mm_sound_keysound.c @@ -193,8 +193,8 @@ static int _mm_sound_play_keysound(const char *filename, int volume_config, ipc_ int idx = 0; conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (!conn && err) { - debug_error("g_bus_get_sync() error (%s)", err->message); + if (!conn || err) { + debug_error("g_bus_get_sync() error (%s)", err ? err->message : NULL); ret = MM_ERROR_SOUND_INTERNAL; } else { result = g_dbus_connection_call_sync (conn, @@ -208,8 +208,8 @@ static int _mm_sound_play_keysound(const char *filename, int volume_config, ipc_ 2000, NULL, &err); - if (!result && err) { - debug_error("g_dbus_connection_call_sync() for SIMPLE_PLAY error (%s)", err->message); + if (!result || err) { + debug_error("g_dbus_connection_call_sync() for SIMPLE_PLAY error (%s)", err ? err->message : NULL); ret = MM_ERROR_SOUND_INTERNAL; } else { g_variant_get(result, "(i)", &idx); @@ -223,9 +223,7 @@ static int _mm_sound_play_keysound(const char *filename, int volume_config, ipc_ } g_object_unref(conn); } - if (err) { - g_error_free(err); - } + g_error_free(err); } return ret; diff --git a/packaging/libmm-sound.spec b/packaging/libmm-sound.spec index afbae0c..200f60d 100644 --- a/packaging/libmm-sound.spec +++ b/packaging/libmm-sound.spec @@ -1,6 +1,6 @@ Name: libmm-sound Summary: MMSound Package contains client lib and sound_server binary -Version: 0.11.21 +Version: 0.11.22 Release: 0 Group: System/Libraries License: Apache-2.0