AnsweredAssumed Answered

rc, stdout, stderr (and everything else) to syslog?

Question asked by illishar on Apr 19, 2012
Latest reply on Apr 26, 2012 by illishar

How are you normally dealing with this scenario?

 

“I want to log everything to Syslog”

 

I want to do so because embedded system (and servers in general) doesn't have consoles. Eg. I want to log the stdout and stderr from rc, inittab and all the programs that they may start. This is a rather common thing to want. (Most big distributions like Ubuntu and Debian have ways to log rc output and everything else.)

 

But if you're using the simpleinit (default choice for Analog dist) and starts the syslog through the inittab. Then rc will run before Syslog. Meaning that output from rc and sub processes cannot be logged to Syslog. (The subprocesses can be logged if they all wait for syslog to be fully started. But rc output can never be logged this way.)

 

So I was thinking: "I'll edit the simpleinit and start the syslog before rc". But that won't do, since rc is mounting the ramfs and /var/log.

 

Ok, then I'll start the syslog in the rc and thereby loose the inittab "respawn" feature, wait for it to be fully started, devide the rc into several and then pipe stdout to "logger". And from inittab I'll make sure that all entries also pipes to logger. I won’t get all rc output though. (But I'll get the important part I hope.)

But piping doesn't seem to catch output from child processes (programs started by rc) and piping from inittab doesn't seem to work. (It also took me a while to realize that the first argument in inittab should be "console" in simpleinit, in you want the output). But if I make sure that all rc programs are explicitly piped to "logger", it might work.

 

Ok, then I'll redirect (append) stdout and stderr in the inittab entries to the /var/log/messages. Doesn't work either. And it would also create a problem when syslog are rotating the log files. (Yes, you have to rotate the log files for obvious reasons.)

 

I would also still have to make custom hacks in the simpleinit if I would keep the "respawn" feature. (But then I could just use my watchdog to respawn the syslog instead? But no, that would cause the system to reboot even though it supports watching pid files.)

 

Ok, when seraching Google it comes up with a solution. You can create a custom stream with fwopen/fopencookie and use that to bind to stdout and have it write to syslog. But no, uclibc doesn't support fopencookie. It could be made to do so if I recompile the toolchain and thereby blowing up the whole dist. I'd rather avoid doing that.

 

Ok, then I could switch out the simpleinit with the Busybox init to see if that one will help me. I've tried that though and even though it supports more than simpleinit, it doesn't solve the problem. And I'd rather hack simpleinit than Busybox, if I need custom functions.

 

Ok, then I'll hack the simpleinit and bind stderr and stdout to the udp socket "/dev/log"... That might work, I haven't tried it yet.

 

So to sum up:

- Start syslog from rc

- Wait for it to be fully started

- Devide rc into subs and pipe those to "logger"

- Explicitly pipe all programs started from rc to "logger"

- Hack simpleinit to support respawning syslog, even though it was started from rc.

- Hack simpleinit to support a special "log" that will bind to the udp port "/dev/log".

 

 

That might work. But it's really troublesome. How did the rest of you solve the issue?

(One could ofc just ignore stdout and hope that nothing useful will ever come from there. But it seems a bit naive in a cli based system?)

Outcomes