From a4256940da049f91bbbea5e53e469a59ea9c10f7 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 25 Oct 2013 21:20:58 +0200 Subject: Imported Upstream version 0.9.8.8 --- callouts/nm-dhcp-client-action.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'callouts/nm-dhcp-client-action.c') 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 #include #include #include #include +#include #include @@ -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); -- cgit 1.3.0-6-gf8a5