Blame SOURCES/dhcp-release-by-ifup.patch

26a25c
diff -up dhcp-4.3.0a1/client/dhclient.c.ifup dhcp-4.3.0a1/client/dhclient.c
26a25c
--- dhcp-4.3.0a1/client/dhclient.c.ifup	2013-12-19 14:53:08.817760677 +0100
26a25c
+++ dhcp-4.3.0a1/client/dhclient.c	2013-12-19 15:05:16.290518574 +0100
26a25c
@@ -521,9 +521,81 @@ main(int argc, char **argv) {
26a25c
 				}
26a25c
 			}
26a25c
 			fclose(pidfd);
26a25c
+		} else {
26a25c
+			/* handle release for interfaces requested with Red Hat
26a25c
+			 * /sbin/ifup - pidfile will be /var/run/dhclient-$interface.pid
26a25c
+			 */
26a25c
+
26a25c
+			if ((path_dhclient_pid == NULL) || (*path_dhclient_pid == '\0'))
26a25c
+				path_dhclient_pid = "/var/run/dhclient.pid";
26a25c
+
26a25c
+			char *new_path_dhclient_pid;
26a25c
+			struct interface_info *ip;
26a25c
+			int pdp_len = strlen(path_dhclient_pid), pfx, dpfx;
26a25c
+
26a25c
+			/* find append point: beginning of any trailing '.pid'
26a25c
+			 * or '-$IF.pid' */
26a25c
+			for (pfx=pdp_len; (pfx >= 0) && (path_dhclient_pid[pfx] != '.') && (path_dhclient_pid[pfx] != '/'); pfx--);
26a25c
+				if (pfx == -1)
26a25c
+					pfx = pdp_len;
26a25c
+
26a25c
+			if (path_dhclient_pid[pfx] == '/')
26a25c
+				pfx += 1;
26a25c
+
26a25c
+			for (dpfx=pfx; (dpfx >= 0) && (path_dhclient_pid[dpfx] != '-') && (path_dhclient_pid[dpfx] != '/'); dpfx--);
26a25c
+				if ((dpfx > -1) && (path_dhclient_pid[dpfx] != '/'))
26a25c
+					pfx = dpfx;
26a25c
+
26a25c
+			for (ip = interfaces; ip; ip = ip->next) {
26a25c
+				if (interfaces_requested && (ip->flags & (INTERFACE_REQUESTED))) {
26a25c
+					int n_len = strlen(ip->name);
26a25c
+
26a25c
+					new_path_dhclient_pid = (char*) malloc(pfx + n_len + 6);
26a25c
+					strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
26a25c
+					sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
26a25c
+
26a25c
+					if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
26a25c
+						e = fscanf(pidfd, "%ld\n", &temp);
26a25c
+						oldpid = (pid_t)temp;
26a25c
+
26a25c
+						if (e != 0 && e != EOF) {
26a25c
+							if (oldpid) {
26a25c
+								if (kill(oldpid, SIGTERM) == 0)
26a25c
+									unlink(path_dhclient_pid);
26a25c
+							}
26a25c
+						}
26a25c
+
26a25c
+						fclose(pidfd);
26a25c
+					}
26a25c
+
26a25c
+					free(new_path_dhclient_pid);
26a25c
+				}
26a25c
+			}
26a25c
+		}
26a25c
+	} else {
26a25c
+		FILE *pidfp = NULL;
26a25c
+		long temp = 0;
26a25c
+		pid_t dhcpid = 0;
26a25c
+		int dhc_running = 0;
26a25c
+		char procfn[256] = "";
26a25c
+
26a25c
+		if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
26a25c
+			if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
26a25c
+				snprintf(procfn,256,"/proc/%u",dhcpid);
26a25c
+				dhc_running = (access(procfn, F_OK) == 0);
26a25c
+			}
26a25c
+
26a25c
+			fclose(pidfp);
26a25c
+		}
26a25c
+
26a25c
+		if (dhc_running) {
26a25c
+			log_fatal("dhclient(%u) is already running - exiting. ", dhcpid);
26a25c
+			return(1);
26a25c
 		}
26a25c
 	}
26a25c
 
26a25c
+	write_client_pid_file();
26a25c
+
26a25c
 	if (!quiet) {
26a25c
 		log_info("%s %s", message, PACKAGE_VERSION);
26a25c
 		log_info(copyright);