Fix notifictions when dhcpcd is lost / re-connected.
authorRoy Marples <roy@marples.name>
Fri, 12 Sep 2014 12:42:38 +0000 (12:42 +0000)
committerRoy Marples <roy@marples.name>
Fri, 12 Sep 2014 12:42:38 +0000 (12:42 +0000)
src/dhcpcd-gtk/main.c
src/dhcpcd-qt/dhcpcd-qt.cpp
src/libdhcpcd/dhcpcd.c

index b0fa185ad39d25ef52aa7ea81110822273403f5e..c28570160e3279a9795f0a968f37685f39cfeeee 100644 (file)
@@ -158,6 +158,7 @@ update_online(DHCPCD_CONNECTION *con, bool showif)
 
        if (online != ison || carrier != iscarrier) {
                online = ison;
+               carrier = iscarrier;
                if (ani_timer != 0) {
                        g_source_remove(ani_timer);
                        ani_timer = 0;
@@ -319,7 +320,8 @@ dhcpcd_watch(int fd,
 }
 
 static void
-dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status, _unused void *data)
+dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status,
+    _unused void *data)
 {
        static char *last = NULL;
        const char *msg;
@@ -335,6 +337,7 @@ dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status, _unused void *data)
                        ani_timer = 0;
                        ani_counter = 0;
                }
+               online = carrier = false;
                gtk_status_icon_set_from_icon_name(status_icon,
                    "network-offline");
                gtk_status_icon_set_tooltip_text(status_icon, msg);
@@ -414,30 +417,30 @@ dhcpcd_if_cb(DHCPCD_IF *i, _unused void *data)
        const char *icon;
        bool new_msg;
 
-       /* Update the tooltip with connection information */
-       con = dhcpcd_if_connection(i);
-       update_online(con, false);
-
        /* We should ignore renew and stop so we don't annoy the user */
-       if (g_strcmp0(i->reason, "RENEW") == 0 ||
-           g_strcmp0(i->reason, "STOP") == 0 ||
-           g_strcmp0(i->reason, "STOPPED") == 0)
-               return;
-
-       msg = dhcpcd_if_message(i, &new_msg);
-       if (msg) {
-               g_message("%s", msg);
-               if (new_msg) {
-                       if (i->up)
-                               icon = "network-transmit-receive";
-                       //else
-                       //      icon = "network-transmit";
-                       if (!i->up)
-                               icon = "network-offline";
-                       notify(_("Network event"), msg, icon);
+       if (g_strcmp0(i->reason, "RENEW") &&
+           g_strcmp0(i->reason, "STOP") &&
+           g_strcmp0(i->reason, "STOPPED"))
+       {
+               msg = dhcpcd_if_message(i, &new_msg);
+               if (msg) {
+                       g_message("%s", msg);
+                       if (new_msg) {
+                               if (i->up)
+                                       icon = "network-transmit-receive";
+                               //else
+                               //      icon = "network-transmit";
+                               if (!i->up)
+                                       icon = "network-offline";
+                               notify(_("Network event"), msg, icon);
+                       }
+                       g_free(msg);
                }
-               g_free(msg);
        }
+
+       /* Update the tooltip with connection information */
+       con = dhcpcd_if_connection(i);
+       update_online(con, false);
 }
 
 static gboolean
index 5e88aa7c4c14809add88332d6023685c3bb4f0e7..2561e25160edc3a3b1aa91668a3413535ef51794 100644 (file)
@@ -174,6 +174,7 @@ void DhcpcdQt::statusCallback(const char *status)
        if (strcmp(status, "down") == 0) {
                aniTimer->stop();
                aniCounter = 0;
+               onLine = carrier = false;
                setIcon("status", "network-offline");
                if (notifier) {
                        delete notifier;
index 9efc95041b116ecede20edf45c09ec422c38ade4..0b817b1a6dc5acd5ae2557736ad028548c9c4d02 100644 (file)
@@ -681,7 +681,9 @@ dhcpcd_set_status_callback(DHCPCD_CONNECTION *con,
 void
 dhcpcd_close(DHCPCD_CONNECTION *con)
 {
-       DHCPCD_WPA *wpa;
+       DHCPCD_IF *nif;
+       DHCPCD_WPA *nwpa;
+       DHCPCD_WI_HIST *nh;
 
        assert(con);
 
@@ -689,8 +691,24 @@ dhcpcd_close(DHCPCD_CONNECTION *con)
 
        /* Shut down WPA listeners as they aren't much good without dhcpcd.
         * They'll be restarted anyway when dhcpcd comes back up. */
-       for (wpa = con->wpa; wpa; wpa = wpa->next)
+       while (con->wpa) {
+               nwpa = con->wpa->next;
                dhcpcd_wpa_close(con->wpa);
+               free(con->wpa);
+               con->wpa = nwpa;
+       }
+       while (con->wi_history) {
+               nh = con->wi_history->next;
+               free(con->wi_history);
+               con->wi_history = nh;
+       }
+       while (con->interfaces) {
+               nif = con->interfaces->next;
+               free(con->interfaces->data);
+               free(con->interfaces->last_message);
+               free(con->interfaces);
+               con->interfaces = nif;
+       }
 
        if (con->command_fd != -1)
                shutdown(con->command_fd, SHUT_RDWR);
@@ -723,6 +741,14 @@ dhcpcd_close(DHCPCD_CONNECTION *con)
        }
 }
 
+void
+dhcpcd_free(DHCPCD_CONNECTION *con)
+{
+
+       assert(con);
+       free(con);
+}
+
 DHCPCD_CONNECTION *
 dhcpcd_if_connection(DHCPCD_IF *i)
 {
@@ -822,32 +848,3 @@ dhcpcd_if_message(DHCPCD_IF *i, bool *new_msg)
 
        return msg;
 }
-
-void
-dhcpcd_free(DHCPCD_CONNECTION *con)
-{
-       DHCPCD_IF *nif;
-       DHCPCD_WPA *nwpa;
-       DHCPCD_WI_HIST *nh;
-
-       assert(con);
-       while (con->interfaces) {
-               nif = con->interfaces->next;
-               free(con->interfaces->data);
-               free(con->interfaces->last_message);
-               free(con->interfaces);
-               con->interfaces = nif;
-       }
-       while (con->wpa) {
-               nwpa = con->wpa->next;
-               dhcpcd_wpa_close(con->wpa);
-               free(con->wpa);
-               con->wpa = nwpa;
-       }
-       while (con->wi_history) {
-               nh = con->wi_history->next;
-               free(con->wi_history);
-               con->wi_history = nh;
-       }
-       free(con);
-}