diff options
Diffstat (limited to 'callouts/nm-dhcp-client-action.c')
| -rw-r--r-- | callouts/nm-dhcp-client-action.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/callouts/nm-dhcp-client-action.c b/callouts/nm-dhcp-client-action.c index d1a3747c..2553a61a 100644 --- a/callouts/nm-dhcp-client-action.c +++ b/callouts/nm-dhcp-client-action.c @@ -20,11 +20,13 @@ /* for environ */ #define _GNU_SOURCE +#include <config.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> +#include <signal.h> #include <dbus/dbus.h> @@ -277,6 +279,22 @@ error: return NULL; } +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[]) { @@ -287,26 +305,26 @@ main (int argc, char *argv[]) /* Get a connection to the system bus */ connection = dbus_init (); if (connection == NULL) - exit (1); + fatal_error (); 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); |