From: Saurav Babu Date: Fri, 16 Sep 2016 06:12:45 +0000 (+0530) Subject: [net-config] Fixed stopping of mdnsd when dns-sd application terminates abruptly X-Git-Tag: submit/tizen/20160921.025733^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a82f2e86ead1b6c4b9a5ad27d71f331fde8958f;p=platform%2Fcore%2Fconnectivity%2Fnet-config.git [net-config] Fixed stopping of mdnsd when dns-sd application terminates abruptly This patch accepts unique dbus name in handle_launch_mdns() and registers NameOwnerChanged() signal for all the unique dbus name. Whenever application terminates abruptly or deinitializes then dbus connection is closed and net-config receives NameOwnerChanged signal corresponding to that application and decreases ref count of mdnsd daemon. When ref count drops to 0 then mdnsd is stopped. Change-Id: I0d0d5c683ab6ae7b346bec43f70f031a8afee7cf Signed-off-by: Saurav Babu --- diff --git a/include/util.h b/include/util.h index 6a5e541..9df584b 100755 --- a/include/util.h +++ b/include/util.h @@ -63,9 +63,8 @@ int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gi int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family); gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context); -gboolean handle_ref_mdns(Network *object, GDBusMethodInvocation *context); -gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context); +gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context, + gchar *name); gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * data); int netconfig_send_message_to_net_popup(const char *title, diff --git a/interfaces/netconfig-iface-network-state.xml b/interfaces/netconfig-iface-network-state.xml index d059cfe..7d0a32c 100755 --- a/interfaces/netconfig-iface-network-state.xml +++ b/interfaces/netconfig-iface-network-state.xml @@ -23,8 +23,9 @@ - - + + + diff --git a/src/network-state.c b/src/network-state.c index 9b2b9c0..f0c488f 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -1087,8 +1087,6 @@ void state_object_create_and_init(void) G_CALLBACK(handle_remove_route), NULL); g_signal_connect(netconfigstate, "handle-launch-mdns", G_CALLBACK(handle_launch_mdns), NULL); - g_signal_connect(netconfigstate, "handle-unref-mdns", - G_CALLBACK(handle_unref_mdns), NULL); g_signal_connect(netconfigstate, "handle-device-policy-set-wifi", G_CALLBACK(handle_device_policy_set_wifi), NULL); g_signal_connect(netconfigstate, "handle-device-policy-get-wifi", diff --git a/src/utils/util.c b/src/utils/util.c index d028cd5..9755f48 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -41,12 +41,19 @@ #include "util.h" #include "neterror.h" #include "wifi-state.h" +#include "netdbus.h" +#define DBUS_SERVICE_DBUS "org.freedesktop.DBus" +#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus" #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_ETC, "/.mac.info") #define MAC_ADDRESS_MAX_LEN 18 static gboolean netconfig_device_picker_test = FALSE; static int mdnsd_ref_count = 0; +typedef struct { + char *conn_name; + int conn_id; +} dnssd_conn_destroy_data; GKeyFile *netconfig_keyfile_load(const char *pathname) { @@ -774,45 +781,78 @@ int execute_mdnsd_script(char* op) { return netconfig_execute_file(path, args, envs); } -gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context) +static void __dnssd_conn_destroyed_cb(GDBusConnection *conn, + const gchar *Name, const gchar *path, const gchar *interface, + const gchar *sig, GVariant *param, gpointer user_data) { - DBG("Launch mdnsresponder daemon"); + gchar *name = NULL; + gchar *old = NULL; + gchar *new = NULL; + dnssd_conn_destroy_data *data = user_data; + GDBusConnection *connection = NULL; + connection = netdbus_get_connection(); + + if (param == NULL) + return; - if (execute_mdnsd_script("start") < 0) { - ERR("Failed to launch mdnsresponder daemon"); - netconfig_error_invalid_parameter(context); - return FALSE; + g_variant_get(param, "(sss)", &name, &old, &new); + + if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') { + DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name, + data->conn_id); + mdnsd_ref_count--; + g_dbus_connection_signal_unsubscribe(connection, data->conn_id); + if (mdnsd_ref_count == 0) { + if (execute_mdnsd_script("stop") < 0) + ERR("Failed to stop mdnsresponder daemon"); + } } + g_free(name); + g_free(old); + g_free(new); + g_free(data->conn_name); + g_free(data); + return; +} - mdnsd_ref_count++; - DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count); +static void register_dnssd_conn_destroy_signal(gchar *name) +{ + dnssd_conn_destroy_data *data; + GDBusConnection *connection = NULL; + connection = netdbus_get_connection(); - network_complete_launch_mdns(object, context); - return TRUE; + if (connection == NULL) { + ERR("Failed to get GDbus Connection"); + return; + } + + data = g_try_malloc0(sizeof(dnssd_conn_destroy_data)); + data->conn_name = g_strdup(name); + + data->conn_id = g_dbus_connection_signal_subscribe(connection, + DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS, + "NameOwnerChanged", NULL, name, + G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb, + data, NULL); + return; } -gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context) +gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context, + gchar *name) { - DBG("Unef mdnsresponder daemon"); + DBG("Launch mdnsresponder daemon"); - if (mdnsd_ref_count <= 0) { - ERR("Invalid access"); + if (execute_mdnsd_script("start") < 0) { + ERR("Failed to launch mdnsresponder daemon"); netconfig_error_invalid_parameter(context); return FALSE; } - mdnsd_ref_count--; - - DBG("Unref mdnsresponder daemon. ref count: %d", mdnsd_ref_count); - if (mdnsd_ref_count == 0) { - if (execute_mdnsd_script("stop") < 0) { - ERR("Failed to stop mdnsresponder daemon"); - netconfig_error_invalid_parameter(context); - return FALSE; - } - } + mdnsd_ref_count++; + register_dnssd_conn_destroy_signal(name); + DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count); - network_complete_unref_mdns(object, context); + network_complete_launch_mdns(object, context); return TRUE; }