relayd doesn't verify a config file before it tries to load it, unlike many
of the other daemons (for instance, bgpd). This leads to all of the relays,
etc., being dropped if you forget to manually check the file with 'relayd
-n' before issuing a reload request. It looks to be a trivial change to
make it act more like bgpd and stop processing if the config file is bad.
A diff is at the end of this mail. As trivial as it is, this is my
biggest patch submission so far, so if it's not right let me know how I
can improve it. Thanks!
Seth
Original:
---------------------------------
# relayctl show summary
Id Type Name Avlblty Status
1 relay test_exchange_http active
1 table test_hubs:80 empty
1 host 134.126.52.201 0.00% down
2 host 134.126.52.202 0.00% down
2 relay www_jmu_edu active
2 table www:80 active (1 hosts)
3 host 134.126.10.50 100.00% up
# relayctl load relayd.conf.bad
# relayctl show summary
Id Type Name Avlblty Status
---------------------------------
Original's logging bits:
---------------------------------
parent_reload: level 0 config file relayd.conf.bad
relayd.conf.bad:25: macro 'local' not defined
relayd.conf.bad:25: syntax error
relayd.conf.bad:32: macro 'local' not defined
relayd.conf.bad:32: syntax error
warning: macro '1local' not used
no actions, nothing to do
unused protocol: www
unused protocol: owa
parent_reload: failed to load config file relayd.conf.bad
---------------------------------
Modified:
---------------------------------
# obj/relayctl show summary
Id Type Name Avlblty Status
1 relay test_exchange_http active
1 table test_hubs:80 active (2 hosts)
1 host 134.126.52.201 100.00% up
2 host 134.126.52.202 100.00% up
2 relay www_jmu_edu active
2 table www:80 active (1 hosts)
3 host 134.126.10.50 100.00% up
# obj/relayctl load relayd.conf.bad
load request sent.
# obj/relayctl show summary
Id Type Name Avlblty Status
1 relay test_exchange_http active
1 table test_hubs:80 active (2 hosts)
1 host 134.126.52.201 100.00% up
2 host 134.126.52.202 100.00% up
2 relay www_jmu_edu active
2 table www:80 active (1 hosts)
3 host 134.126.10.50 100.00% up
---------------------------------
Modified's logging bits:
---------------------------------
parent_reload: level 0 config file relayd.conf.bad
relayd.conf.bad:25: macro 'local' not defined
relayd.conf.bad:25: syntax error
relayd.conf.bad:32: macro 'local' not defined
relayd.conf.bad:32: syntax error
config file relayd.conf.bad has errors, not reloading
---------------------------------
Index: relayctl/relayctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/relayctl/relayctl.c,v
retrieving revision 1.45
diff -u -p -r1.45 relayctl.c
--- relayctl/relayctl.c 20 May 2011 09:43:53 -0000 1.45
+++ relayctl/relayctl.c 11 Nov 2011 15:30:14 -0000
@@ -182,10 +182,12 @@ main(int argc, char *argv[])
case LOAD:
imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1,
res->path, strlen(res->path));
+ printf("load request sent.\n");
done = 1;
break;
case RELOAD:
imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1, NULL, 0);
+ printf("reload request sent.\n");
done = 1;
break;
case MONITOR:
Index: relayd/relayd.c
===================================================================
RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v
retrieving revision 1.104
diff -u -p -r1.104 relayd.c
--- relayd/relayd.c 4 Sep 2011 20:26:58 -0000 1.104
+++ relayd/relayd.c 10 Nov 2011 16:53:20 -0000
@@ -335,6 +335,12 @@ parent_reload(struct relayd *env, u_int
log_debug("%s: level %d config file %s", __func__, reset, filename);
+ if (parse_config(filename, env) == -1) {
+ log_warnx("config file %s has errors, not reloading",
+ filename);
+ return;
+ }
+
config_purge(env, CONFIG_ALL);
if (reset == CONFIG_RELOAD) {