summary refs log tree commit diff
path: root/callouts/nm-dhcp-client-action.c
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd@luon.net>2013-10-25 21:20:58 +0200
committerSjoerd Simons <sjoerd@luon.net>2013-10-25 21:20:58 +0200
commita4256940da049f91bbbea5e53e469a59ea9c10f7 (patch)
tree2211c102aea3a33f34f960f48c8b8a55daccd97b /callouts/nm-dhcp-client-action.c
parent8d275584fc94f398f0a7c990dcd057533d9a5856 (diff)
Imported Upstream version 0.9.8.8 upstream/0.9.8.8
Diffstat (limited to 'callouts/nm-dhcp-client-action.c')
-rw-r--r--callouts/nm-dhcp-client-action.c26
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);