Blame SOURCES/0003-Handle-releasing-interfaces-requested-by-sbin-ifup.patch

df4638
From af504e99abde04b881768d18eaa0054b36b16303 Mon Sep 17 00:00:00 2001
df4638
From: Pavel Zhukov <pzhukov@redhat.com>
df4638
Date: Thu, 21 Feb 2019 10:21:14 +0100
df4638
Subject: [PATCH 03/26] Handle releasing interfaces requested by /sbin/ifup
df4638
Cc: pzhukov@redhat.com
df4638
df4638
---
df4638
 client/dhclient.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
df4638
 1 file changed, 72 insertions(+)
df4638
df4638
diff --git a/client/dhclient.c b/client/dhclient.c
df4638
index 26a333c..2a2e9e6 100644
df4638
--- a/client/dhclient.c
df4638
+++ b/client/dhclient.c
df4638
@@ -787,9 +787,81 @@ main(int argc, char **argv) {
df4638
 				}
df4638
 			}
df4638
 			fclose(pidfd);
df4638
+		} else {
df4638
+			/* handle release for interfaces requested with Red Hat
df4638
+			 * /sbin/ifup - pidfile will be /var/run/dhclient-$interface.pid
df4638
+			 */
df4638
+
df4638
+			if ((path_dhclient_pid == NULL) || (*path_dhclient_pid == '\0'))
df4638
+				path_dhclient_pid = "/var/run/dhclient.pid";
df4638
+
df4638
+			char *new_path_dhclient_pid;
df4638
+			struct interface_info *ip;
df4638
+			int pdp_len = strlen(path_dhclient_pid), pfx, dpfx;
df4638
+
df4638
+			/* find append point: beginning of any trailing '.pid'
df4638
+			 * or '-$IF.pid' */
df4638
+			for (pfx=pdp_len; (pfx >= 0) && (path_dhclient_pid[pfx] != '.') && (path_dhclient_pid[pfx] != '/'); pfx--);
df4638
+				if (pfx == -1)
df4638
+					pfx = pdp_len;
df4638
+
df4638
+			if (path_dhclient_pid[pfx] == '/')
df4638
+				pfx += 1;
df4638
+
df4638
+			for (dpfx=pfx; (dpfx >= 0) && (path_dhclient_pid[dpfx] != '-') && (path_dhclient_pid[dpfx] != '/'); dpfx--);
df4638
+				if ((dpfx > -1) && (path_dhclient_pid[dpfx] != '/'))
df4638
+					pfx = dpfx;
df4638
+
df4638
+			for (ip = interfaces; ip; ip = ip->next) {
df4638
+				if (interfaces_requested && (ip->flags & (INTERFACE_REQUESTED))) {
df4638
+					int n_len = strlen(ip->name);
df4638
+
df4638
+					new_path_dhclient_pid = (char*) malloc(pfx + n_len + 6);
df4638
+					strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
df4638
+					sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
df4638
+
df4638
+					if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
df4638
+						e = fscanf(pidfd, "%ld\n", &temp);
df4638
+						oldpid = (pid_t)temp;
df4638
+
df4638
+						if (e != 0 && e != EOF) {
df4638
+							if (oldpid) {
df4638
+								if (kill(oldpid, SIGTERM) == 0)
df4638
+									unlink(path_dhclient_pid);
df4638
+							}
df4638
+						}
df4638
+
df4638
+						fclose(pidfd);
df4638
+					}
df4638
+
df4638
+					free(new_path_dhclient_pid);
df4638
+				}
df4638
+			}
df4638
+		}
df4638
+	} else {
df4638
+		FILE *pidfp = NULL;
df4638
+		long temp = 0;
df4638
+		pid_t dhcpid = 0;
df4638
+		int dhc_running = 0;
df4638
+		char procfn[256] = "";
df4638
+
df4638
+		if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
df4638
+			if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
df4638
+				snprintf(procfn,256,"/proc/%u",dhcpid);
df4638
+				dhc_running = (access(procfn, F_OK) == 0);
df4638
+			}
df4638
+
df4638
+			fclose(pidfp);
df4638
+		}
df4638
+
df4638
+		if (dhc_running) {
df4638
+			log_fatal("dhclient(%u) is already running - exiting. ", dhcpid);
df4638
+			return(1);
df4638
 		}
df4638
 	}
df4638
 
df4638
+	write_client_pid_file();
df4638
+
df4638
 	if (!quiet) {
df4638
 		log_info("%s %s", message, PACKAGE_VERSION);
df4638
 		log_info(copyright);
df4638
-- 
df4638
2.14.5
df4638