summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Šimerda <psimerda@redhat.com>2013-07-30 14:21:54 +0200
committerPavel Šimerda <psimerda@redhat.com>2013-08-13 22:35:00 +0200
commit80c48a62be1889a4ae3de858909fd66159125421 (patch)
tree3506c5485787e947fe825829d0c22a7d66c784ff
parentff40555e848da9e39de41f9cbe1f5b1cd8c46153 (diff)
downloadNetworkManager-80c48a62be1889a4ae3de858909fd66159125421.tar.gz
dhcp: kill dhclient on fatal errors
This helps to avoid dhclient DOSing the network. https://bugzilla.gnome.org/show_bug.cgi?id=705137
-rw-r--r--src/dhcp-manager/nm-dhcp-helper.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/dhcp-manager/nm-dhcp-helper.c b/src/dhcp-manager/nm-dhcp-helper.c
index 7b510d7a9c..4ddfafe173 100644
--- a/src/dhcp-manager/nm-dhcp-helper.c
+++ b/src/dhcp-manager/nm-dhcp-helper.c
@@ -25,6 +25,8 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <signal.h>
+
#include <config.h>
#include <dbus/dbus.h>
@@ -273,6 +275,22 @@ error:
}
#endif
+static void
+fatal_error (void)
+{
+ const char *pid_str = getenv ("pid");
+ int pid = 0;
+
+ if (pid_str)
+ pid = strtol (pid_str, NULL, 10);
+ if (pid) {
+ fprintf (stderr, "Fatal error occured, killing dhclient instance with pid %d.\n", pid);
+ kill (pid, SIGTERM);
+ }
+
+ exit (1);
+}
+
int
main (int argc, char *argv[])
{
@@ -293,7 +311,7 @@ main (int argc, char *argv[])
fprintf (stderr, "Error: could not connect to NetworkManager DBus socket: (%s) %s\n",
error.name, error.message);
dbus_error_free (&error);
- exit (1);
+ fatal_error ();
}
}
dbus_connection_set_exit_on_disconnect (connection, FALSE);
@@ -301,21 +319,21 @@ main (int argc, char *argv[])
message = dbus_message_new_signal ("/", NM_DHCP_CLIENT_DBUS_IFACE, "Event");
if (message == NULL) {
fprintf (stderr, "Error: Not enough memory to send DHCP Event signal.\n");
- exit (1);
+ fatal_error ();
}
/* Dump environment variables into the message */
result = build_message (message);
if (result == FALSE) {
fprintf (stderr, "Error: Not enough memory to send DHCP Event signal.\n");
- exit (1);
+ fatal_error ();
}
/* queue the message */
result = dbus_connection_send (connection, message, NULL);
if (!result) {
fprintf (stderr, "Error: Could not send send DHCP Event signal.\n");
- exit (1);
+ fatal_error ();
}
dbus_message_unref (message);