]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/dhcp-4.2.0-release-by-ifup.patch
openvpn: Fix wrong default port number.
[people/teissler/ipfire-2.x.git] / src / patches / dhcp-4.2.0-release-by-ifup.patch
1 diff -up dhcp-4.2.0/client/dhclient.c.ifup dhcp-4.2.0/client/dhclient.c
2 --- dhcp-4.2.0/client/dhclient.c.ifup 2010-07-21 13:30:10.000000000 +0200
3 +++ dhcp-4.2.0/client/dhclient.c 2010-07-21 13:37:03.000000000 +0200
4 @@ -497,9 +497,81 @@ main(int argc, char **argv) {
5 kill(oldpid, SIGTERM);
6 }
7 fclose(pidfd);
8 + } else {
9 + /* handle release for interfaces requested with Red Hat
10 + * /sbin/ifup - pidfile will be /var/run/dhclient-$interface.pid
11 + */
12 +
13 + if ((path_dhclient_pid == NULL) || (*path_dhclient_pid == '\0'))
14 + path_dhclient_pid = "/var/run/dhclient.pid";
15 +
16 + char *new_path_dhclient_pid;
17 + struct interface_info *ip;
18 + int pdp_len = strlen(path_dhclient_pid), pfx, dpfx;
19 +
20 + /* find append point: beginning of any trailing '.pid'
21 + * or '-$IF.pid' */
22 + for (pfx=pdp_len; (pfx >= 0) && (path_dhclient_pid[pfx] != '.') && (path_dhclient_pid[pfx] != '/'); pfx--);
23 + if (pfx == -1)
24 + pfx = pdp_len;
25 +
26 + if (path_dhclient_pid[pfx] == '/')
27 + pfx += 1;
28 +
29 + for (dpfx=pfx; (dpfx >= 0) && (path_dhclient_pid[dpfx] != '-') && (path_dhclient_pid[dpfx] != '/'); dpfx--);
30 + if ((dpfx > -1) && (path_dhclient_pid[dpfx] != '/'))
31 + pfx = dpfx;
32 +
33 + for (ip = interfaces; ip; ip = ip->next) {
34 + if (interfaces_requested && (ip->flags & (INTERFACE_REQUESTED))) {
35 + int n_len = strlen(ip->name);
36 +
37 + new_path_dhclient_pid = (char*) malloc(pfx + n_len + 6);
38 + strncpy(new_path_dhclient_pid, path_dhclient_pid, pfx);
39 + sprintf(new_path_dhclient_pid + pfx, "-%s.pid", ip->name);
40 +
41 + if ((pidfd = fopen(new_path_dhclient_pid, "r")) != NULL) {
42 + e = fscanf(pidfd, "%ld\n", &temp);
43 + oldpid = (pid_t)temp;
44 +
45 + if (e != 0 && e != EOF) {
46 + if (oldpid) {
47 + if (kill(oldpid, SIGTERM) == 0)
48 + unlink(path_dhclient_pid);
49 + }
50 + }
51 +
52 + fclose(pidfd);
53 + }
54 +
55 + free(new_path_dhclient_pid);
56 + }
57 + }
58 + }
59 + } else {
60 + FILE *pidfp = NULL;
61 + long temp = 0;
62 + pid_t dhcpid = 0;
63 + int dhc_running = 0;
64 + char procfn[256] = "";
65 +
66 + if ((pidfp = fopen(path_dhclient_pid, "r")) != NULL) {
67 + if ((fscanf(pidfp, "%ld", &temp)==1) && ((dhcpid=(pid_t)temp) > 0)) {
68 + snprintf(procfn,256,"/proc/%u",dhcpid);
69 + dhc_running = (access(procfn, F_OK) == 0);
70 + }
71 +
72 + fclose(pidfp);
73 + }
74 +
75 + if (dhc_running) {
76 + log_fatal("dhclient(%u) is already running - exiting. ", dhcpid);
77 + return(1);
78 }
79 }
80
81 + write_client_pid_file();
82 +
83 if (!quiet) {
84 log_info("%s %s", message, PACKAGE_VERSION);
85 log_info(copyright);