From 371e0f7fdb93165a0c1fc1f7b5539e3190eada64 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 12 Sep 2014 12:42:38 +0000 Subject: [PATCH] Fix notifictions when dhcpcd is lost / re-connected. --- src/dhcpcd-gtk/main.c | 47 ++++++++++++++++++---------------- src/dhcpcd-qt/dhcpcd-qt.cpp | 1 + src/libdhcpcd/dhcpcd.c | 59 ++++++++++++++++++++---------------------- 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/dhcpcd-gtk/main.c b/src/dhcpcd-gtk/main.c index b0fa185..c285701 100644 --- a/src/dhcpcd-gtk/main.c +++ b/src/dhcpcd-gtk/main.c @@ -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 diff --git a/src/dhcpcd-qt/dhcpcd-qt.cpp b/src/dhcpcd-qt/dhcpcd-qt.cpp index 5e88aa7..2561e25 100644 --- a/src/dhcpcd-qt/dhcpcd-qt.cpp +++ b/src/dhcpcd-qt/dhcpcd-qt.cpp @@ -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; diff --git a/src/libdhcpcd/dhcpcd.c b/src/libdhcpcd/dhcpcd.c index 9efc950..0b817b1 100644 --- a/src/libdhcpcd/dhcpcd.c +++ b/src/libdhcpcd/dhcpcd.c @@ -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); -} -- 1.7.1