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