1 From be8f73c399c0f89192e57453db153aaa48fcbb2e 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/28] Handle releasing interfaces requested by /sbin/ifup
7 client/dhclient.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++
8 1 file changed, 72 insertions(+)
10 diff --git a/client/dhclient.c b/client/dhclient.c
11 index 6c1c09a..07679a7 100644
12 --- a/client/dhclient.c
13 +++ b/client/dhclient.c
14 @@ -793,9 +793,81 @@ main(int argc, char **argv) {
19 + /* handle release for interfaces requested with Red Hat
20 + * /sbin/ifup - pidfile will be /var/run/dhclient-$interface.pid
23 + if ((path_dhclient_pid == NULL) || (*path_dhclient_pid == '\0'))
24 + path_dhclient_pid = "/var/run/dhclient.pid";
26 + char *new_path_dhclient_pid;
27 + struct interface_info *ip;
28 + int pdp_len = strlen(path_dhclient_pid), pfx, dpfx;
30 + /* find append point: beginning of any trailing '.pid'
32 + for (pfx=pdp_len; (pfx >= 0) && (path_dhclient_pid[pfx] != '.') && (path_dhclient_pid[pfx] != '/'); pfx--);
36 + if (path_dhclient_pid[pfx] == '/')
39 + for (dpfx=pfx; (dpfx >= 0) && (path_dhclient_pid[dpfx] != '-') && (path_dhclient_pid[dpfx] != '/'); dpfx--);
40 + if ((dpfx > -1) && (path_dhclient_pid[dpfx] != '/'))
43 + for (ip = interfaces; ip; ip = ip->next) {
44 + if (interfaces_requested && (ip->flags & (INTERFACE_REQUESTED))) {
45 + int n_len = strlen(ip->name);
47 + new_path_dhclient_pid = (char*) malloc(pfx + n_len + 6);
48 + strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
49 + sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
51 + if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
52 + e = fscanf(pidfd, "%ld\n", &temp);
53 + oldpid = (pid_t)temp;
55 + if (e != 0 && e != EOF) {
57 + if (kill(oldpid, SIGTERM) == 0)
58 + unlink(path_dhclient_pid);
65 + free(new_path_dhclient_pid);
73 + int dhc_running = 0;
74 + char procfn[256] = "";
76 + if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
77 + if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
78 + snprintf(procfn,256,"/proc/%u",dhcpid);
79 + dhc_running = (access(procfn, F_OK) == 0);
86 + log_fatal("dhclient(%u) is already running - exiting. ", dhcpid);
91 + write_client_pid_file();
94 log_info("%s %s", message, PACKAGE_VERSION);