[PATCH] Ensure that dhcp client is exited



Hello!

Since NM does not stop dhcp client when it exits, there may persist an
old instance of dhcp client during NM start again and it is not a child
of the current process. So we need to wait until it is actually exited,
otherwise a race condition may occurs, as I noticed in case dhcpcd
4.x.x (the pidfile was removed by exiting old dhcpcd instance).

-- 
WBR, Mikhail Efremov
>From 45e528745f7ec9e6cd4683ffc4bf1e5ee40fc394 Mon Sep 17 00:00:00 2001
From: Mikhail Efremov <sem altlinux org>
Date: Thu, 11 Nov 2010 20:07:32 +0300
Subject: [PATCH] dhcp: Ensure that dhcp client is exited.

Do not start another dhcp client until existing one
really exited.
---
 src/dhcp-manager/nm-dhcp-client.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index 0c7f3d4..3a8b194 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -156,11 +156,15 @@ stop_process (GPid pid, const char *iface)
 
 		if (ret == -1) {
 			/* Child already exited */
-			if (errno == ECHILD)
+			if (errno == ECHILD) {
+				/* Was it really our child and it exited? */
+				if (kill (pid, 0) < 0 && errno == ESRCH)
+					break;
+			} else {
+				/* Took too long; shoot it in the head */
+				i = 0;
 				break;
-			/* Took too long; shoot it in the head */
-			i = 0;
-			break;
+			}
 		}
 		g_usleep (G_USEC_PER_SEC / 5);
 	}
-- 
1.7.3.2



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]