From 569ca7918daa63832207e0d96f7d0b2d78300850 Mon Sep 17 00:00:00 2001
From: zhanglu <zhanglu37@huawei.com>
Date: Thu, 27 Feb 2020 20:47:22 +0800
Subject: [PATCH] dhcp: solve start dhclient when last pid was held.

Signed-off-by: zhanglu <zhanglu37@huawei.com>
---
 client/dhclient.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/client/dhclient.c b/client/dhclient.c
index 9f8ba06..eff3444 100644
--- a/client/dhclient.c
+++ b/client/dhclient.c
@@ -774,15 +774,26 @@ main(int argc, char **argv) {
 		}
 	} else {
 		FILE *pidfp = NULL;
+		FILE *commfp = NULL;
 		long temp = 0;
 		pid_t dhcpid = 0;
 		int dhc_running = 0;
 		char procfn[256] = "";
+		char pidname_path[256] = "";
+		char pidname[256] = "";
 
 		if ((pidfp = fopen(path_dhclient_pid, "re")) != NULL) {
 			if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
 				snprintf(procfn,256,"/proc/%u",dhcpid);
-				dhc_running = (access(procfn, F_OK) == 0);
+				snprintf(pidname_path,256,"%s/comm",procfn);
+
+				if (access(procfn, F_OK) == 0) {
+					if ((commfp = fopen(pidname_path, "r")) != NULL) {
+						fscanf(commfp, "%s", pidname);
+						dhc_running = (strncmp("dhclient", pidname, strlen("dhclient")) == 0);
+						fclose(commfp);
+					}
+				}
 			}
 
 			fclose(pidfp);
-- 
2.19.1

