Subject: Re: rc.d boot log [was: Re: Cosmetic changes to rc.d scripts]
To: mouss <usebsd@free.fr>
From: Mike M. Volokhov <mishka@apk.od.ua>
List: tech-userlevel
Date: 10/19/2004 17:40:04
This is a multi-part message in MIME format.

--Multipart=_Tue__19_Oct_2004_17_40_04_+0300_3rCco+WBMS7jxiAQ
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

On Fri, 15 Oct 2004 18:46:27 +0200 mouss <usebsd@free.fr> wrote:

> Mike M. Volokhov wrote:
> 
> > However, I meant a single log, i.e. when at a boot time the output will
> > grew too much (for example up to few megabytes). In this case variables
> > will store huge sets of data. Is it ok?
> > 
> 
> I tested your modifs with a dummy script (that outputs about 20M) and 
> noticed no special problem (except that _rclogbuf initialization causes 
> a blank line to be appended but that's not a serious problem). However, 
> this may be an issue for small systems.

In any case we must decide what way we're using (tee or var) *before*
command execution. There is possible situation where we use tee method
and some rc.d script creates behaviour where /var/log/rc.log becomes
unavailable. This means that tee will fail. It possible to workaround by
buffering any output and then flushing buffer after each rc.d script
when /var/log/rc.log becomes available.

Relative to blank lines - it has been fixed.

> 
> Now there is a third approach: add an rc.d/rclog script that is run 
> after /var and /usr are mounted, and that changes the behaviour of 
> rclog() to use tee instead of buffering.

Having reread the whole thread once more, I use the following way:

- Log via tee(1) when it available, and accumulate log in buffer, when
  it is not.
- If tee can be used again, rclog() flushes buffer to log file and
  restores tee logging. Thus, logging methods may be switched unlimited
  times during both rc and rc.shutdown execution.
- If all rc.d scripts are finished and buffer still contain any data, I
  assume this data cannot be saved to /var/log/rc.log and thus I try to
  append it to /etc/rclog.tmp (see also my notes about buffering).
- As soon as log files becomes available rclog() rotate logs. Any further
  rclog() calls doesn't affected on log rotation.

> One potential issue with buffering is that output is printed after the 
> script terminates. If the script is verbose (that's bad but...), it's 
> output is delayed and once the script terminates, you get it all at 
> once. Fortunately, the log is here!

Partially fixed (will be delayed for one line only). In many verbose
scripts such as rc.d/network it looks good enough.

> PS. shutdown log should go to another place (shutdown.log?).
> Otherwise, it gets moved to rc.prev after reboot, so you lose the 
> previous startup logs (which may be useful for comparisons).

Please see above.

Well, could you test, please, my yet another patch to rc, rc.shutdown,
and rc.subr (in attachment)?

--
Best wishes,
Mishka.

--Multipart=_Tue__19_Oct_2004_17_40_04_+0300_3rCco+WBMS7jxiAQ
Content-Type: text/plain;
 name="rclog.patch"
Content-Disposition: attachment;
 filename="rclog.patch"
Content-Transfer-Encoding: base64

LS0tIHJjLm9yaWcJMjAwNC0xMC0xOSAxNzoyMjoyMC4wMDAwMDAwMDAgKzAzMDAKKysrIHJjCTIw
MDQtMTAtMTkgMTc6MjM6MDguMDAwMDAwMDAwICswMzAwCkBAIC0xNyw2ICsxNyw4IEBACiAuIC9l
dGMvcmMuY29uZgogX3JjX2NvbmZfbG9hZGVkPXRydWUKIAorX3JjX3N0YXRlPWJvb3QKKwogaWYg
ISBjaGVja3llc25vIHJjX2NvbmZpZ3VyZWQ7IHRoZW4KIAllY2hvICIvZXRjL3JjLmNvbmYgaXMg
bm90IGNvbmZpZ3VyZWQuICBNdWx0aXVzZXIgYm9vdCBhYm9ydGVkLiIKIAlleGl0IDEKQEAgLTM1
LDEzICszNywxOSBAQAogdHJhcCA6IElOVAogdHJhcCAiZWNobyAnQm9vdCBpbnRlcnJ1cHRlZC4n
OyBleGl0IDEiIFFVSVQKIAotZGF0ZQorcmNsb2cgImVjaG8gU3RhcnRpbmcgdXAgYXQgYGRhdGVg
IgogCiBmaWxlcz0kKHJjb3JkZXIgLXMgbm9zdGFydCAke3JjX3Jjb3JkZXJfZmxhZ3N9IC9ldGMv
cmMuZC8qKQogCiBmb3IgX3JjX2VsZW0gaW4gJGZpbGVzOyBkbwotCXJ1bl9yY19zY3JpcHQgJF9y
Y19lbGVtIHN0YXJ0CisJcmNsb2cgInJ1bl9yY19zY3JpcHQgJF9yY19lbGVtIHN0YXJ0IgogZG9u
ZQogCi1kYXRlCityY2xvZyAiZWNobyBTeXN0ZW0gd2FzIHN0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