about 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:21:07 +0200
committerSjoerd Simons <sjoerd@luon.net>2013-10-25 21:21:07 +0200
commite83d1de9b746dbc078ac1cf45f1798e1bc6b7e2f (patch)
treec36a40d79a5ae7d2bbca7d240d0a6f664049b435 /callouts/nm-dhcp-client-action.c
parent26283b4c9e5035574a6c168003e7f1da53a8f32a (diff)
parenta4256940da049f91bbbea5e53e469a59ea9c10f7 (diff)
Merge tag 'upstream/0.9.8.8' into experimental
Upstream version 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);