1 From 692fd8b16ef6f12a57596351e930c65c68597bac Mon Sep 17 00:00:00 2001
2 From: Pavel Zhukov <pzhukov@redhat.com>
3 Date: Thu, 21 Feb 2019 10:21:14 +0100
4 Subject: [PATCH 03/21] Handle releasing interfaces requested by /sbin/ifup
8 client/dhclient.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 1 file changed, 72 insertions(+)
11 diff --git a/client/dhclient.c b/client/dhclient.c
12 index 26a333c..2a2e9e6 100644
13 --- a/client/dhclient.c
14 +++ b/client/dhclient.c
15 @@ -787,9 +787,81 @@ main(int argc, char **argv) {
20 + /* handle release for interfaces requested with Red Hat
21 + * /sbin/ifup - pidfile will be /var/run/dhclient-$interface.pid
24 + if ((path_dhclient_pid == NULL) || (*path_dhclient_pid == '\0'))
25 + path_dhclient_pid = "/var/run/dhclient.pid";
27 + char *new_path_dhclient_pid;
28 + struct interface_info *ip;
29 + int pdp_len = strlen(path_dhclient_pid), pfx, dpfx;
31 + /* find append point: beginning of any trailing '.pid'
33 + for (pfx=pdp_len; (pfx >= 0) && (path_dhclient_pid[pfx] != '.') && (path_dhclient_pid[pfx] != '/'); pfx--);
37 + if (path_dhclient_pid[pfx] == '/')
40 + for (dpfx=pfx; (dpfx >= 0) && (path_dhclient_pid[dpfx] != '-') && (path_dhclient_pid[dpfx] != '/'); dpfx--);
41 + if ((dpfx > -1) && (path_dhclient_pid[dpfx] != '/'))
44 + for (ip = interfaces; ip; ip = ip->next) {
45 + if (interfaces_requested && (ip->flags & (INTERFACE_REQUESTED))) {
46 + int n_len = strlen(ip->name);
48 + new_path_dhclient_pid = (char*) malloc(pfx + n_len + 6);
49 + strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
50 + sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
52 + if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
53 + e = fscanf(pidfd, "%ld\n", &temp);
54 + oldpid = (pid_t)temp;
56 + if (e != 0 && e != EOF) {
58 + if (kill(oldpid, SIGTERM) == 0)
59 + unlink(path_dhclient_pid);
66 + free(new_path_dhclient_pid);
74 + int dhc_running = 0;
75 + char procfn[256] = "";
77 + if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
78 + if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
79 + snprintf(procfn,256,"/proc/%u",dhcpid);
80 + dhc_running = (access(procfn, F_OK) == 0);
87 + log_fatal("dhclient(%u) is already running - exiting. ", dhcpid);
92 + write_client_pid_file();
95 log_info("%s %s", message, PACKAGE_VERSION);