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

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