philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

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

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