From 6ae9a6a1642fcaf808c934931139484776a56a9a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 7 May 2015 16:56:50 +0200 Subject: Fix race condition --- pam_wlan.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pam_wlan.c b/pam_wlan.c index 514f725..181bb6a 100644 --- a/pam_wlan.c +++ b/pam_wlan.c @@ -163,12 +163,16 @@ static NMDevice * find_device(NMClient *client) { return NULL; } -static void state_cb(NMActiveConnection *active_connection, GParamSpec *pspec, gpointer user_data) { +static void state_cb(NMDevice *device, GParamSpec *pspec, gpointer user_data) { cb_arg *arg = user_data; + NMActiveConnection *active_connection = nm_device_get_active_connection(device); + if (!active_connection) + return; + NMActiveConnectionState state = nm_active_connection_get_state(active_connection); - if (state != NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { + if (state != NM_ACTIVE_CONNECTION_STATE_ACTIVATING && state != NM_ACTIVE_CONNECTION_STATE_DEACTIVATING) { if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) arg->ret = PAM_SUCCESS; @@ -182,8 +186,6 @@ static void activate_cb(NMClient *client, NMActiveConnection *active_connection, if (error) goto error; - g_signal_connect(active_connection, "notify::state", G_CALLBACK(state_cb), arg); - state_cb(active_connection, NULL, arg); return; @@ -201,6 +203,7 @@ static void add_cb(NMRemoteSettings *settings, NMRemoteConnection *con, GError * if (!device) goto error; + g_signal_connect(device, "notify::state", G_CALLBACK(state_cb), arg); nm_client_activate_connection(arg->client, NM_CONNECTION(con), device, NULL, activate_cb, arg); return; -- cgit v1.2.3