diff options
author | Li-Wen Hsu <lwhsu@FreeBSD.org> | 2010-08-22 01:15:32 +0000 |
---|---|---|
committer | Li-Wen Hsu <lwhsu@FreeBSD.org> | 2010-08-22 01:15:32 +0000 |
commit | fdde528fecb46d378da500b997ca8917a2311766 (patch) | |
tree | b6abf15f4eafef51f3a4ab382fa864ff54432848 | |
parent | e716b532616f5b5d763005ff359d20bacac7e761 (diff) | |
download | ports-fdde528fecb46d378da500b997ca8917a2311766.tar.gz ports-fdde528fecb46d378da500b997ca8917a2311766.zip |
Notes
-rw-r--r-- | net/ifstated/Makefile | 4 | ||||
-rw-r--r-- | net/ifstated/files/ifstated.in | 89 | ||||
-rw-r--r-- | net/ifstated/files/patch-ifstated.8 | 32 | ||||
-rw-r--r-- | net/ifstated/files/patch-ifstated.c | 91 | ||||
-rw-r--r-- | net/ifstated/files/pkg-message.in | 19 | ||||
-rw-r--r-- | net/ifstated/pkg-descr | 21 |
6 files changed, 210 insertions, 46 deletions
diff --git a/net/ifstated/Makefile b/net/ifstated/Makefile index 48d72aea8edf..bf4851182384 100644 --- a/net/ifstated/Makefile +++ b/net/ifstated/Makefile @@ -7,7 +7,7 @@ PORTNAME= ifstated PORTVERSION= 4.7 -PORTREVISION= 1 +PORTREVISION= 2 PORTEPOCH= 1 CATEGORIES= net MASTER_SITES= http://christianserving.org/ports/net/ifstated/ @@ -28,7 +28,7 @@ USE_RC_SUBR= ifstated post-patch: @${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|g' ${WRKSRC}/Makefile - @${REINPLACE_CMD} -e 's|/etc/|${PREFIX}/etc/|g' ${WRKSRC}/ifstated.c ${WRKSRC}/ifstated.8 ${WRKSRC}/ifstated.conf.5 + @${REINPLACE_CMD} -e 's|/etc/|${PREFIX}/etc/|g' ${WRKSRC}/ifstated.conf.5 do-install: ${INSTALL_PROGRAM} ${WRKSRC}/ifstated ${PREFIX}/sbin diff --git a/net/ifstated/files/ifstated.in b/net/ifstated/files/ifstated.in index 4e1480dc0348..b141c550f61e 100644 --- a/net/ifstated/files/ifstated.in +++ b/net/ifstated/files/ifstated.in @@ -10,22 +10,95 @@ # # Add the following lines to /etc/rc.conf to enable ifstated: -# ifstated_enable (bool): Set to "NO" by default. -# Set it to "YES" to enable ifstated -# ifstated_flags (str): Set to "-f %%PREFIX%%/etc/ifstated.conf" by default. -# Extra flags passed to start command # +# ifstated_enable (bool): Set to "NO" by default. +# Set it to "YES" to enable ifstated. +# ifstated_flags (str): Set to "" by default. +# Extra flags passed to start command. +# +# With no profiles defined, the default configuration file will be +# used (%%PREFIX%%/etc/ifstated.conf). +# +# For profiles (separate ifstated intances): +# +# ifstated_profiles (str): Set to "" by default. +# Define profile names (e.g. "dns +# http ssh"). +# ifstated_<name>_configfile (str): +# [Required] Path to the configuration +# file for profile <name>. +# ifstated_<name>_enable (bool): Set to ${ifstated_enable} by default. +# Set it to "YES" or "NO" to +# independently enable or disable +# profile <name>. +# ifstated_<name>_flags (str): Set to ${ifstated_flags} by default. +# Extra flags passed to start command +# for profile <name>. +# + . /etc/rc.subr name="ifstated" rcvar=`set_rcvar` command="%%PREFIX%%/sbin/ifstated" - -[ -z "$ifstated_enable" ] && ifstated_enable="NO" -[ -z "$ifstated_flags" ] && ifstated_flags="-f %%PREFIX%%/etc/ifstated.conf" +pidfile="/var/run/${name}.pid" +command_args="-p \"${pidfile}\"" load_rc_config $name -run_rc_command "$1" +: ${ifstated_enable:="NO"} +: ${ifstated_flags:=""} +: ${ifstated_profiles:=""} + +if [ -n "$2" ] +then + profile="$2" + if [ "x${ifstated_profiles}" != "x" ] + then + pidfile="/var/run/${name}.${profile}.pid" + eval ifstated_configfile="\${ifstated_${profile}_configfile:-}" + + if [ "x${ifstated_configfile}" = "x" ] + then + echo "You must define a configuration file (ifstated_${profile}_configile)." >&2 + exit 1 + fi + + required_files="${ifstated_configfile}" + command_args="-f \"${ifstated_configfile}\" -p \"${pidfile}\"" + eval ifstated_enable="\${ifstated_${profile}_enable:=${ifstated_enable}}" + eval ifstated_flags="\${ifstated_${profile}_flags:=${ifstated_flags}}" + else + echo "$0: extra argument ignored." >&2 + fi +else + if [ "x${ifstated_profiles}" != "x" -a "x$1" != "x" ] + then + for profile in ${ifstated_profiles} + do + eval ifstated_enable_tmp="\${ifstated_${profile}_enable:=${ifstated_enable}}" + + case "x${ifstated_enable_tmp}" + in + x|x[Nn][Oo]) + continue + ;; + x[Yy][Ee][Ss]) + ;; + *) + echo "Bad value \"${ifstated_enable_tmp}\" for ifstated_${profile}_enable. Profile ${profile} skipped." >&2 + continue + ;; + esac + + echo "===> ifstated profile: ${profile}" + '%%PREFIX%%/etc/rc.d/ifstated' "$1" "${profile}" + done + + exit 0 + fi +fi + +run_rc_command "$1" diff --git a/net/ifstated/files/patch-ifstated.8 b/net/ifstated/files/patch-ifstated.8 new file mode 100644 index 000000000000..e0514386a0f5 --- /dev/null +++ b/net/ifstated/files/patch-ifstated.8 @@ -0,0 +1,32 @@ +--- ifstated.8.orig 2010-06-11 12:20:08.000000000 -0500 ++++ ifstated.8 2010-07-30 22:15:08.518460671 -0500 +@@ -29,6 +29,7 @@ + .Ar macro Ns = Ns Ar value Oc + .Xc + .Op Fl f Ar file ++.Op Fl p Ar pidfile + .Ek + .Sh DESCRIPTION + The +@@ -61,6 +62,10 @@ + Specify an alternate location, + .Ar file , + for the configuration file. ++.It Fl p Ar pidfile ++Specify the location, ++.Ar pidfile , ++for the PID file. + .It Fl h + Print help message. + .It Fl i +@@ -78,8 +83,8 @@ + .Nm + reloads the configuration file. + .Sh FILES +-.Bl -tag -width "/etc/ifstated.conf" -compact +-.It Pa /etc/ifstated.conf ++.Bl -tag -width "/usr/local/etc/ifstated.conf" -compact ++.It Pa /usr/local/etc/ifstated.conf + .Nm + configuration file. + .El diff --git a/net/ifstated/files/patch-ifstated.c b/net/ifstated/files/patch-ifstated.c index 3114a0980233..20ba118f5bb9 100644 --- a/net/ifstated/files/patch-ifstated.c +++ b/net/ifstated/files/patch-ifstated.c @@ -1,5 +1,5 @@ --- ifstated.c.orig 2010-06-11 12:20:08.000000000 -0500 -+++ ifstated.c 2010-06-15 13:49:50.785704080 -0500 ++++ ifstated.c 2010-07-30 21:55:03.045444649 -0500 @@ -26,9 +26,11 @@ #include <sys/time.h> #include <sys/ioctl.h> @@ -12,7 +12,17 @@ #include <net/route.h> #include <netinet/in.h> -@@ -61,6 +63,8 @@ +@@ -47,7 +49,8 @@ + + int opts = 0; + int opt_inhibit = 0; +-char *configfile = "/etc/ifstated.conf"; ++char *configfile = "/usr/local/etc/ifstated.conf"; ++char *pidfile = NULL; + struct event rt_msg_ev, sighup_ev, startup_ev, sigchld_ev; + + void startup_handler(int, short, void *); +@@ -61,6 +64,8 @@ void external_evtimer_setup(struct ifsd_state *, int); void scan_ifstate(int, int, int); int scan_ifstate_single(int, int, struct ifsd_state *); @@ -21,7 +31,42 @@ void fetch_state(void); void usage(void); void adjust_expressions(struct ifsd_expression_list *, int); -@@ -159,7 +163,6 @@ +@@ -70,13 +75,14 @@ + void do_action(struct ifsd_action *); + void remove_action(struct ifsd_action *, struct ifsd_state *); + void remove_expression(struct ifsd_expression *, struct ifsd_state *); ++void remove_pidfile(int); + + void + usage(void) + { + extern char *__progname; + +- fprintf(stderr, "usage: %s [-dhinv] [-D macro=value] [-f file]\n", ++ fprintf(stderr, "usage: %s [-dhinv] [-D macro=value] [-f file] [-p pidfile]\n", + __progname); + exit(1); + } +@@ -90,7 +96,7 @@ + + log_init(1); + +- while ((ch = getopt(argc, argv, "dD:f:hniv")) != -1) { ++ while ((ch = getopt(argc, argv, "dD:f:p:hniv")) != -1) { + switch (ch) { + case 'd': + debug = 1; +@@ -112,6 +118,9 @@ + case 'i': + opt_inhibit = 1; + break; ++ case 'p': ++ pidfile = optarg; ++ break; + case 'v': + if (opts & IFSD_OPT_VERBOSE) + opts |= IFSD_OPT_VERBOSE2; +@@ -159,7 +168,6 @@ startup_handler(int fd, short event, void *arg) { int rt_fd; @@ -29,7 +74,7 @@ if ((rt_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) err(1, "no routing socket"); -@@ -169,11 +172,6 @@ +@@ -169,11 +177,24 @@ exit(1); } @@ -38,10 +83,28 @@ - &rtfilter, sizeof(rtfilter)) == -1) /* not fatal */ - log_warn("startup_handler: setsockopt"); - ++ if (pidfile != NULL) { ++ FILE* file = fopen(pidfile, "w"); ++ ++ if (file == NULL) { ++ log_warnx("unable to open pidfile"); ++ } ++ else { ++ fprintf(file, "%ld\n", (long)getpid()); ++ fclose(file); ++ log_debug("wrote pidfile %s", pidfile); ++ ++ signal(SIGINT, remove_pidfile); ++ signal(SIGQUIT, remove_pidfile); ++ signal(SIGABRT, remove_pidfile); ++ signal(SIGTERM, remove_pidfile); ++ } ++ } ++ event_set(&rt_msg_ev, rt_fd, EV_READ|EV_PERSIST, rt_msg_handler, NULL); event_add(&rt_msg_ev, NULL); -@@ -406,6 +404,8 @@ +@@ -406,6 +427,8 @@ } } @@ -50,7 +113,7 @@ #define LINK_STATE_IS_DOWN(_s) \ (!LINK_STATE_IS_UP((_s)) && (_s) != LINK_STATE_UNKNOWN) -@@ -584,6 +584,44 @@ +@@ -584,6 +607,44 @@ } } @@ -95,7 +158,7 @@ /* * Fetch the current link states. */ -@@ -593,26 +631,31 @@ +@@ -593,26 +654,31 @@ struct ifaddrs *ifap, *ifa; char *oname = NULL; int sock = socket(AF_INET, SOCK_DGRAM, 0); @@ -135,3 +198,17 @@ } freeifaddrs(ifap); close(sock); +@@ -707,3 +773,13 @@ + } + free(expression); + } ++ ++void ++remove_pidfile(int code) ++{ ++ if ((pidfile != NULL) && unlink(pidfile)) { ++ log_warnx("could not remove pidfile"); ++ } ++ ++ exit(code); ++} diff --git a/net/ifstated/files/pkg-message.in b/net/ifstated/files/pkg-message.in index 7cba34aa27fd..5453621ac91a 100644 --- a/net/ifstated/files/pkg-message.in +++ b/net/ifstated/files/pkg-message.in @@ -1,16 +1,7 @@ -*** ATTENTION *** - -You must create a %%PREFIX%%/etc/ifstated.conf file (a sample is -provided). To run ifstated from startup, add the following to /etc/rc.conf: - -ifstated_enable="YES" - - -Available variables you can set in /etc/rc.conf: - -- ifstated_enable (bool): Set to "NO" by default. - Set it to "YES" to enable ifstated. -- ifstated_flags (str): Set to "-f %%PREFIX%%/etc/ifstated.conf" by default. - Extra flags passed to start command. +To use ifstated, you must create one or more configration files (a +sample is provided). This version of ifstated allows for multiple +"profiles" or instances, each with its own configuration. Please see +the comments in %%PREFIX%%/etc/rc.d/ifstated for the variables to set +in /etc/rc.conf. diff --git a/net/ifstated/pkg-descr b/net/ifstated/pkg-descr index 5fc9afda3958..5440a1e14f82 100644 --- a/net/ifstated/pkg-descr +++ b/net/ifstated/pkg-descr @@ -1,15 +1,6 @@ - -This is a port of ifstated(8) from OpenBSD by Matthew George. - -From the manpage: - -*** -The ifstated daemon runs commands in response to network state changes, -which it determines by monitoring interface link state or running exter- -nal tests. For example, it can be used with carp(4) to change running -services or to ensure that carp(4) interfaces stay in sync, or with pf(4) -to test server or link availability and modify translation or routing -rules. -*** - -It has been modified to use FreeBSD's kqueue/kevent mechanism and sysctl. +The ifstated daemon runs commands in response to network state +changes, which it determines by monitoring interface link state or +running external tests. For example, it can be used with carp(4) to +change running services or to ensure that carp(4) interfaces stay in +sync, or with pf(4) to test server or link availability and modify +translation or routing rules. |