dhcp: kill dhclient on fatal errors

This helps to avoid dhclient DOSing the network.

https://bugzilla.gnome.org/show_bug.cgi?id=705137
This commit is contained in:
Pavel Šimerda 2013-07-30 14:21:54 +02:00
parent ff40555e84
commit 80c48a62be

View file

@ -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);