Lines 1-5
Link Here
|
1 |
--- ifstated.c.orig 2010-06-11 12:20:08.000000000 -0500 |
1 |
--- ifstated.c.orig 2010-06-11 12:20:08.000000000 -0500 |
2 |
+++ ifstated.c 2010-06-15 13:49:50.785704080 -0500 |
2 |
+++ ifstated.c 2010-07-30 21:55:03.045444649 -0500 |
3 |
@@ -26,9 +26,11 @@ |
3 |
@@ -26,9 +26,11 @@ |
4 |
#include <sys/time.h> |
4 |
#include <sys/time.h> |
5 |
#include <sys/ioctl.h> |
5 |
#include <sys/ioctl.h> |
Lines 12-18
Link Here
|
12 |
#include <net/route.h> |
12 |
#include <net/route.h> |
13 |
#include <netinet/in.h> |
13 |
#include <netinet/in.h> |
14 |
|
14 |
|
15 |
@@ -61,6 +63,8 @@ |
15 |
@@ -47,7 +49,8 @@ |
|
|
16 |
|
17 |
int opts = 0; |
18 |
int opt_inhibit = 0; |
19 |
-char *configfile = "/etc/ifstated.conf"; |
20 |
+char *configfile = "/usr/local/etc/ifstated.conf"; |
21 |
+char *pidfile = NULL; |
22 |
struct event rt_msg_ev, sighup_ev, startup_ev, sigchld_ev; |
23 |
|
24 |
void startup_handler(int, short, void *); |
25 |
@@ -61,6 +64,8 @@ |
16 |
void external_evtimer_setup(struct ifsd_state *, int); |
26 |
void external_evtimer_setup(struct ifsd_state *, int); |
17 |
void scan_ifstate(int, int, int); |
27 |
void scan_ifstate(int, int, int); |
18 |
int scan_ifstate_single(int, int, struct ifsd_state *); |
28 |
int scan_ifstate_single(int, int, struct ifsd_state *); |
Lines 21-27
Link Here
|
21 |
void fetch_state(void); |
31 |
void fetch_state(void); |
22 |
void usage(void); |
32 |
void usage(void); |
23 |
void adjust_expressions(struct ifsd_expression_list *, int); |
33 |
void adjust_expressions(struct ifsd_expression_list *, int); |
24 |
@@ -159,7 +163,6 @@ |
34 |
@@ -70,13 +75,14 @@ |
|
|
35 |
void do_action(struct ifsd_action *); |
36 |
void remove_action(struct ifsd_action *, struct ifsd_state *); |
37 |
void remove_expression(struct ifsd_expression *, struct ifsd_state *); |
38 |
+void remove_pidfile(int); |
39 |
|
40 |
void |
41 |
usage(void) |
42 |
{ |
43 |
extern char *__progname; |
44 |
|
45 |
- fprintf(stderr, "usage: %s [-dhinv] [-D macro=value] [-f file]\n", |
46 |
+ fprintf(stderr, "usage: %s [-dhinv] [-D macro=value] [-f file] [-p pidfile]\n", |
47 |
__progname); |
48 |
exit(1); |
49 |
} |
50 |
@@ -90,7 +96,7 @@ |
51 |
|
52 |
log_init(1); |
53 |
|
54 |
- while ((ch = getopt(argc, argv, "dD:f:hniv")) != -1) { |
55 |
+ while ((ch = getopt(argc, argv, "dD:f:p:hniv")) != -1) { |
56 |
switch (ch) { |
57 |
case 'd': |
58 |
debug = 1; |
59 |
@@ -112,6 +118,9 @@ |
60 |
case 'i': |
61 |
opt_inhibit = 1; |
62 |
break; |
63 |
+ case 'p': |
64 |
+ pidfile = optarg; |
65 |
+ break; |
66 |
case 'v': |
67 |
if (opts & IFSD_OPT_VERBOSE) |
68 |
opts |= IFSD_OPT_VERBOSE2; |
69 |
@@ -159,7 +168,6 @@ |
25 |
startup_handler(int fd, short event, void *arg) |
70 |
startup_handler(int fd, short event, void *arg) |
26 |
{ |
71 |
{ |
27 |
int rt_fd; |
72 |
int rt_fd; |
Lines 29-35
Link Here
|
29 |
|
74 |
|
30 |
if ((rt_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) |
75 |
if ((rt_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) |
31 |
err(1, "no routing socket"); |
76 |
err(1, "no routing socket"); |
32 |
@@ -169,11 +172,6 @@ |
77 |
@@ -169,11 +177,24 @@ |
33 |
exit(1); |
78 |
exit(1); |
34 |
} |
79 |
} |
35 |
|
80 |
|
Lines 38-47
Link Here
|
38 |
- &rtfilter, sizeof(rtfilter)) == -1) /* not fatal */ |
83 |
- &rtfilter, sizeof(rtfilter)) == -1) /* not fatal */ |
39 |
- log_warn("startup_handler: setsockopt"); |
84 |
- log_warn("startup_handler: setsockopt"); |
40 |
- |
85 |
- |
|
|
86 |
+ if (pidfile != NULL) { |
87 |
+ FILE* file = fopen(pidfile, "w"); |
88 |
+ |
89 |
+ if (file == NULL) { |
90 |
+ log_warnx("unable to open pidfile"); |
91 |
+ } |
92 |
+ else { |
93 |
+ fprintf(file, "%ld\n", (long)getpid()); |
94 |
+ fclose(file); |
95 |
+ log_debug("wrote pidfile %s", pidfile); |
96 |
+ |
97 |
+ signal(SIGINT, remove_pidfile); |
98 |
+ signal(SIGQUIT, remove_pidfile); |
99 |
+ signal(SIGABRT, remove_pidfile); |
100 |
+ signal(SIGTERM, remove_pidfile); |
101 |
+ } |
102 |
+ } |
103 |
+ |
41 |
event_set(&rt_msg_ev, rt_fd, EV_READ|EV_PERSIST, rt_msg_handler, NULL); |
104 |
event_set(&rt_msg_ev, rt_fd, EV_READ|EV_PERSIST, rt_msg_handler, NULL); |
42 |
event_add(&rt_msg_ev, NULL); |
105 |
event_add(&rt_msg_ev, NULL); |
43 |
|
106 |
|
44 |
@@ -406,6 +404,8 @@ |
107 |
@@ -406,6 +427,8 @@ |
45 |
} |
108 |
} |
46 |
} |
109 |
} |
47 |
|
110 |
|
Lines 50-56
Link Here
|
50 |
#define LINK_STATE_IS_DOWN(_s) \ |
113 |
#define LINK_STATE_IS_DOWN(_s) \ |
51 |
(!LINK_STATE_IS_UP((_s)) && (_s) != LINK_STATE_UNKNOWN) |
114 |
(!LINK_STATE_IS_UP((_s)) && (_s) != LINK_STATE_UNKNOWN) |
52 |
|
115 |
|
53 |
@@ -584,6 +584,44 @@ |
116 |
@@ -584,6 +607,44 @@ |
54 |
} |
117 |
} |
55 |
} |
118 |
} |
56 |
|
119 |
|
Lines 95-101
Link Here
|
95 |
/* |
158 |
/* |
96 |
* Fetch the current link states. |
159 |
* Fetch the current link states. |
97 |
*/ |
160 |
*/ |
98 |
@@ -593,26 +631,31 @@ |
161 |
@@ -593,26 +654,31 @@ |
99 |
struct ifaddrs *ifap, *ifa; |
162 |
struct ifaddrs *ifap, *ifa; |
100 |
char *oname = NULL; |
163 |
char *oname = NULL; |
101 |
int sock = socket(AF_INET, SOCK_DGRAM, 0); |
164 |
int sock = socket(AF_INET, SOCK_DGRAM, 0); |
Lines 135-137
Link Here
|
135 |
} |
198 |
} |
136 |
freeifaddrs(ifap); |
199 |
freeifaddrs(ifap); |
137 |
close(sock); |
200 |
close(sock); |
|
|
201 |
@@ -707,3 +773,13 @@ |
202 |
} |
203 |
free(expression); |
204 |
} |
205 |
+ |
206 |
+void |
207 |
+remove_pidfile(int code) |
208 |
+{ |
209 |
+ if ((pidfile != NULL) && unlink(pidfile)) { |
210 |
+ log_warnx("could not remove pidfile"); |
211 |
+ } |
212 |
+ |
213 |
+ exit(code); |
214 |
+} |