View | Details | Raw Unified | Return to bug 149727
Collapse All | Expand All

(-)/usr/home/jhriggs/ifstated/Makefile (-2 / +2 lines)
Lines 7-13 Link Here
7
7
8
PORTNAME=	ifstated
8
PORTNAME=	ifstated
9
PORTVERSION=	4.7
9
PORTVERSION=	4.7
10
PORTREVISION=	1
10
PORTREVISION=	2
11
PORTEPOCH=	1
11
PORTEPOCH=	1
12
CATEGORIES=	net
12
CATEGORIES=	net
13
MASTER_SITES=	http://christianserving.org/ports/net/ifstated/
13
MASTER_SITES=	http://christianserving.org/ports/net/ifstated/
Lines 28-34 Link Here
28
28
29
post-patch:
29
post-patch:
30
	@${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|g' ${WRKSRC}/Makefile
30
	@${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|g' ${WRKSRC}/Makefile
31
	@${REINPLACE_CMD} -e 's|/etc/|${PREFIX}/etc/|g' ${WRKSRC}/ifstated.c ${WRKSRC}/ifstated.8 ${WRKSRC}/ifstated.conf.5
31
	@${REINPLACE_CMD} -e 's|/etc/|${PREFIX}/etc/|g' ${WRKSRC}/ifstated.conf.5
32
32
33
do-install:
33
do-install:
34
	${INSTALL_PROGRAM} ${WRKSRC}/ifstated ${PREFIX}/sbin
34
	${INSTALL_PROGRAM} ${WRKSRC}/ifstated ${PREFIX}/sbin
(-)/usr/home/jhriggs/ifstated/files/ifstated.in (-8 / +81 lines)
Lines 10-31 Link Here
10
10
11
#
11
#
12
# Add the following lines to /etc/rc.conf to enable ifstated:
12
# Add the following lines to /etc/rc.conf to enable ifstated:
13
# ifstated_enable (bool):     Set to "NO" by default.
14
#                             Set it to "YES" to enable ifstated
15
# ifstated_flags (str):       Set to "-f %%PREFIX%%/etc/ifstated.conf" by default.
16
#                             Extra flags passed to start command
17
#
13
#
14
# ifstated_enable (bool):        Set to "NO" by default.
15
#                                Set it to "YES" to enable ifstated.
16
# ifstated_flags (str):          Set to "" by default.
17
#                                Extra flags passed to start command.
18
#
19
# With no profiles defined, the default configuration file will be
20
# used (%%PREFIX%%/etc/ifstated.conf).
21
#
22
# For profiles (separate ifstated intances):
23
#
24
# ifstated_profiles (str):       Set to "" by default.
25
#                                Define profile names (e.g. "dns
26
#                                http ssh").
27
# ifstated_<name>_configfile (str):
28
#                                [Required] Path to the configuration
29
#                                file for profile <name>.
30
# ifstated_<name>_enable (bool): Set to ${ifstated_enable} by default.
31
#                                Set it to "YES" or "NO" to
32
#                                independently enable or disable
33
#                                profile <name>.
34
# ifstated_<name>_flags (str):   Set to ${ifstated_flags} by default.
35
#                                Extra flags passed to start command
36
#                                for profile <name>.
37
#
38
18
. /etc/rc.subr
39
. /etc/rc.subr
19
40
20
name="ifstated"
41
name="ifstated"
21
rcvar=`set_rcvar`
42
rcvar=`set_rcvar`
22
43
23
command="%%PREFIX%%/sbin/ifstated"
44
command="%%PREFIX%%/sbin/ifstated"
24
45
pidfile="/var/run/${name}.pid"
25
[ -z "$ifstated_enable" ]       && ifstated_enable="NO"
46
command_args="-p \"${pidfile}\""
26
[ -z "$ifstated_flags" ]        && ifstated_flags="-f %%PREFIX%%/etc/ifstated.conf"
27
47
28
load_rc_config $name
48
load_rc_config $name
29
49
30
run_rc_command "$1"
50
: ${ifstated_enable:="NO"}
51
: ${ifstated_flags:=""}
52
: ${ifstated_profiles:=""}
53
54
if [ -n "$2" ]
55
then
56
  profile="$2"
57
58
  if [ "x${ifstated_profiles}" != "x" ]
59
  then
60
    pidfile="/var/run/${name}.${profile}.pid"
61
    eval ifstated_configfile="\${ifstated_${profile}_configfile:-}"
62
63
    if [ "x${ifstated_configfile}" = "x" ]
64
    then
65
      echo "You must define a configuration file (ifstated_${profile}_configile)." >&2
66
      exit 1
67
    fi
68
69
    required_files="${ifstated_configfile}"
70
    command_args="-f \"${ifstated_configfile}\" -p \"${pidfile}\""
71
    eval ifstated_enable="\${ifstated_${profile}_enable:=${ifstated_enable}}"
72
    eval ifstated_flags="\${ifstated_${profile}_flags:=${ifstated_flags}}"
73
  else
74
    echo "$0: extra argument ignored." >&2
75
  fi
76
else
77
  if [ "x${ifstated_profiles}" != "x" -a "x$1" != "x" ]
78
  then
79
    for profile in ${ifstated_profiles}
80
    do
81
      eval ifstated_enable_tmp="\${ifstated_${profile}_enable:=${ifstated_enable}}"
82
83
      case "x${ifstated_enable_tmp}"
84
      in
85
        x|x[Nn][Oo])
86
          continue
87
          ;;
88
        x[Yy][Ee][Ss])
89
          ;;
90
        *)
91
          echo "Bad value \"${ifstated_enable_tmp}\" for ifstated_${profile}_enable. Profile ${profile} skipped." >&2
92
          continue
93
          ;;
94
      esac
95
96
      echo "===> ifstated profile: ${profile}"
97
      '%%PREFIX%%/etc/rc.d/ifstated' "$1" "${profile}"
98
    done
99
100
    exit 0
101
  fi
102
fi
31
103
104
run_rc_command "$1"
(-)/usr/home/jhriggs/ifstated/files/patch-ifstated.8 (+32 lines)
Line 0 Link Here
1
--- ifstated.8.orig	2010-06-11 12:20:08.000000000 -0500
2
+++ ifstated.8	2010-07-30 22:15:08.518460671 -0500
3
@@ -29,6 +29,7 @@
4
 .Ar macro Ns = Ns Ar value Oc
5
 .Xc
6
 .Op Fl f Ar file
7
+.Op Fl p Ar pidfile
8
 .Ek
9
 .Sh DESCRIPTION
10
 The
11
@@ -61,6 +62,10 @@
12
 Specify an alternate location,
13
 .Ar file ,
14
 for the configuration file.
15
+.It Fl p Ar pidfile
16
+Specify the location,
17
+.Ar pidfile ,
18
+for the PID file.
19
 .It Fl h
20
 Print help message.
21
 .It Fl i
22
@@ -78,8 +83,8 @@
23
 .Nm
24
 reloads the configuration file.
25
 .Sh FILES
26
-.Bl -tag -width "/etc/ifstated.conf" -compact
27
-.It Pa /etc/ifstated.conf
28
+.Bl -tag -width "/usr/local/etc/ifstated.conf" -compact
29
+.It Pa /usr/local/etc/ifstated.conf
30
 .Nm
31
 configuration file.
32
 .El
(-)/usr/home/jhriggs/ifstated/files/patch-ifstated.c (-7 / +84 lines)
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
+}
(-)/usr/home/jhriggs/ifstated/files/pkg-message.in (-14 / +5 lines)
Lines 1-16 Link Here
1
1
2
*** ATTENTION ***
2
To use ifstated, you must create one or more configration files (a
3
3
sample is provided).  This version of ifstated allows for multiple
4
You must create a %%PREFIX%%/etc/ifstated.conf file (a sample is
4
"profiles" or instances, each with its own configuration.  Please see
5
provided).  To run ifstated from startup, add the following to /etc/rc.conf:
5
the comments in %%PREFIX%%/etc/rc.d/ifstated for the variables to set
6
6
in /etc/rc.conf.
7
ifstated_enable="YES"
8
9
10
Available variables you can set in /etc/rc.conf:
11
12
- ifstated_enable (bool):      Set to "NO" by default.
13
                               Set it to "YES" to enable ifstated.
14
- ifstated_flags (str):        Set to "-f %%PREFIX%%/etc/ifstated.conf" by default.
15
                               Extra flags passed to start command.
16
7
(-)/usr/home/jhriggs/ifstated/pkg-descr (-15 / +6 lines)
Lines 1-15 Link Here
1
1
The ifstated daemon runs commands in response to network state
2
This is a port of ifstated(8) from OpenBSD by Matthew George.
2
changes, which it determines by monitoring interface link state or
3
3
running external tests.  For example, it can be used with carp(4) to
4
From the manpage:
4
change running services or to ensure that carp(4) interfaces stay in
5
5
sync, or with pf(4) to test server or link availability and modify
6
***
6
translation or routing rules.
7
The ifstated daemon runs commands in response to network state changes,
8
which it determines by monitoring interface link state or running exter-
9
nal tests.  For example, it can be used with carp(4) to change running
10
services or to ensure that carp(4) interfaces stay in sync, or with pf(4)
11
to test server or link availability and modify translation or routing
12
rules.
13
***
14
15
It has been modified to use FreeBSD's kqueue/kevent mechanism and sysctl.

Return to bug 149727