From patchwork Thu May 16 04:21:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gnoutcheff X-Patchwork-Id: 244208 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 926A12C009E for ; Thu, 16 May 2013 14:22:30 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id A4AC59C235; Thu, 16 May 2013 00:22:25 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BON5-02w15BD; Thu, 16 May 2013 00:22:25 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 4018B9C247; Thu, 16 May 2013 00:22:21 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 2D42B9C247 for ; Thu, 16 May 2013 00:22:20 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cB9R604OWjGc for ; Thu, 16 May 2013 00:22:15 -0400 (EDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id D8A0D9C235 for ; Thu, 16 May 2013 00:22:15 -0400 (EDT) Received: by mail-vc0-f173.google.com with SMTP id ht10so2436671vcb.4 for ; Wed, 15 May 2013 21:22:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=Jxrvah0o9tdUwq/Gs6aaIALeRhoL3mrxg7xqlw30pLA=; b=oAnKjHxjz7u52dHb5v0qBo4CXqzNnW9G5Io1+Dw2QGNUaqPvtsn1lGuUvvqr4+UmbH 4Vdzf/GeDSG9GbGOWvlbl1acLUDJgRGkbC0jhQ3uEjzr96s0kMErzKWEzL2sjBJxUbdb 0hOt8Lfnfj/fn0n1OmRHiYLWX1zShNUeefKlBu3X4ZUJd6H1czcUPGJpFcXomj8uV7zK M3WnY0AOuiEybQ6UdwXaJ2hq3C+o6MNcki4ke4b8KyTdU89kIc6O/f3pld+xNfH7QsRm SW25wxnEo+xc5lCVxTCGtjPQ3qlF+vPG//NMRNNBlOrTYb8RQJdWXhYDpX9JTCJFS17M LATw== X-Received: by 10.52.160.102 with SMTP id xj6mr12047234vdb.45.1368678135279; Wed, 15 May 2013 21:22:15 -0700 (PDT) Received: from localhost.localdomain (ool-44c7d9e4.dyn.optonline.net. [68.199.217.228]) by mx.google.com with ESMTPSA id kz18sm5733774vdb.13.2013.05.15.21.22.14 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 May 2013 21:22:14 -0700 (PDT) From: Daniel Gnoutcheff To: hostap@lists.shmoo.com Subject: [PATCH] dbus: terminate cleanly on messagebus shutdown Date: Thu, 16 May 2013 00:21:30 -0400 Message-Id: <1368678090-7021-1-git-send-email-daniel@gnoutcheff.name> X-Mailer: git-send-email 1.8.1.2 X-Gm-Message-State: ALoCoQmHyDFeB15wkMdB+N1c+mBvfmlvPFhZ8L70GSE1TNZ2ZNFeMlh//xpivyToHY7Mim6mHw+E X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com By default, dbus_connection_dispatch() will call _exit() if the bus connection has been closed. This caused wpa_supplicant to terminate without properly cleaning up after itself. To ensure that we terminate cleanly when the messagebus terminates, override the exit_on_disconnect behavior and install a filter to handle libdbus's "Disconnected" signal. Signed-hostap: Daniel Gnoutcheff --- This is a slightly edited version of the patch I previously submitted as an attachment to: https://w1.fi/bugz/show_bug.cgi?id=474 See also: https://bugs.launchpad.net/ubuntu/+source/wpa/+bug/1124789 wpa_supplicant/dbus/dbus_common.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/wpa_supplicant/dbus/dbus_common.c b/wpa_supplicant/dbus/dbus_common.c index 5d0e31e..1e2153c 100644 --- a/wpa_supplicant/dbus/dbus_common.c +++ b/wpa_supplicant/dbus/dbus_common.c @@ -17,6 +17,7 @@ #include "dbus_common_i.h" #include "dbus_new.h" #include "dbus_old.h" +#include "../wpa_supplicant_i.h" #ifndef SIGPOLL @@ -256,6 +257,20 @@ static int integrate_with_eloop(struct wpas_dbus_priv *priv) return 0; } +static DBusHandlerResult disconnect_filter(DBusConnection *conn, + DBusMessage *message, void *data) +{ + struct wpas_dbus_priv *priv = data; + + if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, + "Disconnected")) { + wpa_printf(MSG_DEBUG, "dbus: bus disconnected, terminating"); + dbus_connection_set_exit_on_disconnect(conn, FALSE); + wpa_supplicant_terminate_proc(priv->global); + return DBUS_HANDLER_RESULT_HANDLED; + } else + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} static int wpas_dbus_init_common(struct wpas_dbus_priv *priv) { @@ -265,7 +280,10 @@ static int wpas_dbus_init_common(struct wpas_dbus_priv *priv) /* Get a reference to the system bus */ dbus_error_init(&error); priv->con = dbus_bus_get(DBUS_BUS_SYSTEM, &error); - if (!priv->con) { + if (priv->con) { + dbus_connection_add_filter(priv->con, disconnect_filter, priv, + NULL); + } else { wpa_printf(MSG_ERROR, "dbus: Could not acquire the system " "bus: %s - %s", error.name, error.message); ret = -1; @@ -304,6 +322,9 @@ static void wpas_dbus_deinit_common(struct wpas_dbus_priv *priv) NULL, NULL, NULL); dbus_connection_set_timeout_functions(priv->con, NULL, NULL, NULL, NULL, NULL); + dbus_connection_remove_filter(priv->con, disconnect_filter, + priv); + dbus_connection_unref(priv->con); }