Add build option CONFIG_TERMINATE_ONLASTIF
authorSam Leffler <sam@errno.com>
Mon, 2 Mar 2009 19:57:00 +0000 (21:57 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 2 Mar 2009 19:57:00 +0000 (21:57 +0200)
This makes wpa_supplicant terminate automatically if the configured
interface(s) disappear.

wpa_supplicant/events.c

index cd5928e..e6f3a4a 100644 (file)
@@ -1017,6 +1017,19 @@ wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
 }
 
 
+#ifdef CONFIG_TERMINATE_ONLASTIF
+static int any_interfaces(struct wpa_supplicant *head)
+{
+       struct wpa_supplicant *wpa_s;
+
+       for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
+               if (!wpa_s->interface_removed)
+                       return 1;
+       return 0;
+}
+#endif /* CONFIG_TERMINATE_ONLASTIF */
+
+
 static void
 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
                                      union wpa_event_data *data)
@@ -1041,6 +1054,11 @@ wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
                wpa_supplicant_mark_disassoc(wpa_s);
                l2_packet_deinit(wpa_s->l2);
                wpa_s->l2 = NULL;
+#ifdef CONFIG_TERMINATE_ONLASTIF
+               /* check if last interface */
+               if (!any_interfaces(wpa_s->global->ifaces))
+                       eloop_terminate();
+#endif /* CONFIG_TERMINATE_ONLASTIF */
                break;
        }
 }