philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

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

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