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