rc.conf sanity check in reboot or better parsing?

I thought I would post this to get some comments.

The rc scripts do a . (aka source) import of /etc/rc.conf which means any syntax error makes the machine unusable.

A simple `sh /etc/rc.conf` will show these errors but kills the shell that runs it.
Is there a way that /sbin/reboot could do that test and ask if it should reboot a broken system?
Another option would be fix rc to do checking and fallback to something like /etc/rc.conf.safe or a line by line parsing to keep some of the system running like bringing up interfaces and sshd. Most rc.conf files could be split -l 1 and then sourced independently.

Simply sourcing the rc.conf in a subshell does work:
Code:
#!/bin/sh
`. ./rc.test || echo bad1` || echo Bad2
Will claim "Bad2" if given bad input such as:
Code:
#syntax error double double quote at end:
foo_enable="YES""

Perhaps the best option is if `. rc.conf` then . rc.conf else . rc.conf.safe? Or split and do that per line?
The problem is reboot is sometimes scripted with no human interaction so "rc.conf is borked, no reboot for you" isn't an option and splitting the rc.conf needs safe place to do it that is writable very early in the boot process way before things are set up nice and sane.
 
Use sysrc(8). You can check the config with sysrc -c. And your machine is not unusable. You can boot single user mode where you can mount the root filesystem read-write and edit the file manually.
 
Use sysrc(8). You can check the config with sysrc -c. And your machine is not unusable. You can boot single user mode where you can mount the root filesystem read-write and edit the file manually.
If it is remote and I have to go visit it, it is unusable in my opinion.
sysrc's check feature isn't intuitive and sysrc -f rc.test -a works the same as sh rc.test. Perhaps a new sysrc -t should default to useful defaults for testing mirroring apachectl -t. Either way having reboot do a check (maybe only when run from a tty) seems to be a sane thing to me.
 
Back
Top