]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-release-by-ifup.patch
- updated to 4.4.3-P1
[packages/dhcp.git] / dhcp-release-by-ifup.patch
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
5
6 ---
7  client/dhclient.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++
8  1 file changed, 72 insertions(+)
9
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) {
15                                 }
16                         }
17                         fclose(pidfd);
18 +               } else {
19 +                       /* handle release for interfaces requested with Red Hat
20 +                        * /sbin/ifup - pidfile will be /var/run/dhclient-$interface.pid
21 +                        */
22 +
23 +                       if ((path_dhclient_pid == NULL) || (*path_dhclient_pid == '\0'))
24 +                               path_dhclient_pid = "/var/run/dhclient.pid";
25 +
26 +                       char *new_path_dhclient_pid;
27 +                       struct interface_info *ip;
28 +                       int pdp_len = strlen(path_dhclient_pid), pfx, dpfx;
29 +
30 +                       /* find append point: beginning of any trailing '.pid'
31 +                        * or '-$IF.pid' */
32 +                       for (pfx=pdp_len; (pfx >= 0) && (path_dhclient_pid[pfx] != '.') && (path_dhclient_pid[pfx] != '/'); pfx--);
33 +                               if (pfx == -1)
34 +                                       pfx = pdp_len;
35 +
36 +                       if (path_dhclient_pid[pfx] == '/')
37 +                               pfx += 1;
38 +
39 +                       for (dpfx=pfx; (dpfx >= 0) && (path_dhclient_pid[dpfx] != '-') && (path_dhclient_pid[dpfx] != '/'); dpfx--);
40 +                               if ((dpfx > -1) && (path_dhclient_pid[dpfx] != '/'))
41 +                                       pfx = dpfx;
42 +
43 +                       for (ip = interfaces; ip; ip = ip->next) {
44 +                               if (interfaces_requested && (ip->flags & (INTERFACE_REQUESTED))) {
45 +                                       int n_len = strlen(ip->name);
46 +
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);
50 +
51 +                                       if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
52 +                                               e = fscanf(pidfd, "%ld\n", &temp);
53 +                                               oldpid = (pid_t)temp;
54 +
55 +                                               if (e != 0 && e != EOF) {
56 +                                                       if (oldpid) {
57 +                                                               if (kill(oldpid, SIGTERM) == 0)
58 +                                                                       unlink(path_dhclient_pid);
59 +                                                       }
60 +                                               }
61 +
62 +                                               fclose(pidfd);
63 +                                       }
64 +
65 +                                       free(new_path_dhclient_pid);
66 +                               }
67 +                       }
68 +               }
69 +       } else {
70 +               FILE *pidfp = NULL;
71 +               long temp = 0;
72 +               pid_t dhcpid = 0;
73 +               int dhc_running = 0;
74 +               char procfn[256] = "";
75 +
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);
80 +                       }
81 +
82 +                       fclose(pidfp);
83 +               }
84 +
85 +               if (dhc_running) {
86 +                       log_fatal("dhclient(%u) is already running - exiting. ", dhcpid);
87 +                       return(1);
88                 }
89         }
90  
91 +       write_client_pid_file();
92 +
93         if (!quiet) {
94                 log_info("%s %s", message, PACKAGE_VERSION);
95                 log_info(copyright);
96 -- 
97 2.35.1
98
This page took 0.04495 seconds and 4 git commands to generate.