Subject: Re: rc.d boot log [was: Re: Cosmetic changes to rc.d scripts]
To: Mike M. Volokhov <mishka@apk.od.ua>
From: mouss <usebsd@free.fr>
List: tech-userlevel
Date: 10/14/2004 15:20:42
Mike M. Volokhov wrote:

> 
> I've thinking about this way. But it takes more effort to handle this
> (checking if /var/log was mounted or not, switching between two logging
> scenaries, etc.) when there are no big advantages. Of course, using tee
> it would be possible handle logs with arbitrary size, but what's more?

- tee way
There is an additionnal problem with tee. It is in /usr/bin, so
one would need to check for /usr being mounted and for tee to exist.
That said, err() and warn() check for /usr/bin/logger. So
that is just an additionnal test. if you don't like calling -d /var/log 
all the time, you can do it only before it exists:
	_rctmplog=/etc/_rclog.tmp
	_teelog=
	_teecmd="/usr/bin/tee -a $_rctmplog"
...
	if [ -n $_teelog ] && [ -x /usr/bin/tee ]; then
		_teelog="| $teecmd 2>/dev/null"
	fi
	run... $_teelog
...
	if [ -d /var/log ]; then
		mv /var/log/rc.log /var/log/rc.prev 2>/dev/null
		mv $_rctmplog /var/log/rc.log
	else
		warn "boot log has been saved to $_rctmplog"
	fi

Of course, output produced before /usr and /var is mounted won't be 
logged. we can replace /var with / by first writing to /etc/rclog.tmp 
and moving this at the end of rc. This way, as soon as / is writable and 
/usr is mouned (tee is found), rc output will be logged.

- var way
one issue I see is that rclogvar may be (accidentally) used in rc 
scripts. so you should call it _rclogbuf instead.

Also, as rclog() is not supposed to used by other scripts, it is better 
to put the definition in /etc/rc directly.
Note that people who modified rc.local to run pkg scripts do not need to 
call rclog() as it rc.local is called by rc.


- just too boot logs?
I think we only need two boot logs: the current and previous, so
at end, do
	mv /var/log/rc.log /var/log/rc.prev
	echo $var > /var/log/rc.log

- if /var/log can't be found, write to /etc so that one can find out 
what the problem was.
if [ -d /var/log ]; then
	echo "${rclogvar}" >> /var/log/boot.log
else
	echo "${rclogvar}" > /etc/rclog.tmp
	warn "boot log has been saved in /etc/rclog.tmp"
fi