|
|
f9ed25 |
From af504e99abde04b881768d18eaa0054b36b16303 Mon Sep 17 00:00:00 2001
|
|
|
f9ed25 |
From: Pavel Zhukov <pzhukov@redhat.com>
|
|
|
f9ed25 |
Date: Thu, 21 Feb 2019 10:21:14 +0100
|
|
|
f9ed25 |
Subject: [PATCH 03/26] Handle releasing interfaces requested by /sbin/ifup
|
|
|
f9ed25 |
Cc: pzhukov@redhat.com
|
|
|
f9ed25 |
|
|
|
f9ed25 |
---
|
|
|
f9ed25 |
client/dhclient.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
f9ed25 |
1 file changed, 72 insertions(+)
|
|
|
f9ed25 |
|
|
|
f9ed25 |
diff --git a/client/dhclient.c b/client/dhclient.c
|
|
|
f9ed25 |
index 26a333c..2a2e9e6 100644
|
|
|
f9ed25 |
--- a/client/dhclient.c
|
|
|
f9ed25 |
+++ b/client/dhclient.c
|
|
|
f9ed25 |
@@ -787,9 +787,81 @@ main(int argc, char **argv) {
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
fclose(pidfd);
|
|
|
f9ed25 |
+ } else {
|
|
|
f9ed25 |
+ /* handle release for interfaces requested with Red Hat
|
|
|
f9ed25 |
+ * /sbin/ifup - pidfile will be /var/run/dhclient-$interface.pid
|
|
|
f9ed25 |
+ */
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if ((path_dhclient_pid == NULL) || (*path_dhclient_pid == '\0'))
|
|
|
f9ed25 |
+ path_dhclient_pid = "/var/run/dhclient.pid";
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ char *new_path_dhclient_pid;
|
|
|
f9ed25 |
+ struct interface_info *ip;
|
|
|
f9ed25 |
+ int pdp_len = strlen(path_dhclient_pid), pfx, dpfx;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ /* find append point: beginning of any trailing '.pid'
|
|
|
f9ed25 |
+ * or '-$IF.pid' */
|
|
|
f9ed25 |
+ for (pfx=pdp_len; (pfx >= 0) && (path_dhclient_pid[pfx] != '.') && (path_dhclient_pid[pfx] != '/'); pfx--);
|
|
|
f9ed25 |
+ if (pfx == -1)
|
|
|
f9ed25 |
+ pfx = pdp_len;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (path_dhclient_pid[pfx] == '/')
|
|
|
f9ed25 |
+ pfx += 1;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ for (dpfx=pfx; (dpfx >= 0) && (path_dhclient_pid[dpfx] != '-') && (path_dhclient_pid[dpfx] != '/'); dpfx--);
|
|
|
f9ed25 |
+ if ((dpfx > -1) && (path_dhclient_pid[dpfx] != '/'))
|
|
|
f9ed25 |
+ pfx = dpfx;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ for (ip = interfaces; ip; ip = ip->next) {
|
|
|
f9ed25 |
+ if (interfaces_requested && (ip->flags & (INTERFACE_REQUESTED))) {
|
|
|
f9ed25 |
+ int n_len = strlen(ip->name);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ new_path_dhclient_pid = (char*) malloc(pfx + n_len + 6);
|
|
|
f9ed25 |
+ strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
|
|
|
f9ed25 |
+ sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
|
|
|
f9ed25 |
+ e = fscanf(pidfd, "%ld\n", &temp);
|
|
|
f9ed25 |
+ oldpid = (pid_t)temp;
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (e != 0 && e != EOF) {
|
|
|
f9ed25 |
+ if (oldpid) {
|
|
|
f9ed25 |
+ if (kill(oldpid, SIGTERM) == 0)
|
|
|
f9ed25 |
+ unlink(path_dhclient_pid);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ fclose(pidfd);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ free(new_path_dhclient_pid);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+ } else {
|
|
|
f9ed25 |
+ FILE *pidfp = NULL;
|
|
|
f9ed25 |
+ long temp = 0;
|
|
|
f9ed25 |
+ pid_t dhcpid = 0;
|
|
|
f9ed25 |
+ int dhc_running = 0;
|
|
|
f9ed25 |
+ char procfn[256] = "";
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
|
|
|
f9ed25 |
+ if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
|
|
|
f9ed25 |
+ snprintf(procfn,256,"/proc/%u",dhcpid);
|
|
|
f9ed25 |
+ dhc_running = (access(procfn, F_OK) == 0);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ fclose(pidfp);
|
|
|
f9ed25 |
+ }
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
+ if (dhc_running) {
|
|
|
f9ed25 |
+ log_fatal("dhclient(%u) is already running - exiting. ", dhcpid);
|
|
|
f9ed25 |
+ return(1);
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
}
|
|
|
f9ed25 |
|
|
|
f9ed25 |
+ write_client_pid_file();
|
|
|
f9ed25 |
+
|
|
|
f9ed25 |
if (!quiet) {
|
|
|
f9ed25 |
log_info("%s %s", message, PACKAGE_VERSION);
|
|
|
f9ed25 |
log_info(copyright);
|
|
|
f9ed25 |
--
|
|
|
f9ed25 |
2.14.5
|
|
|
f9ed25 |
|