I'm trying to build an embedded system with linux. (Means very few resources and not much else than busybox.) I'd like to make sure, that everything is going to syslog. I'm using the newest version of busybox (v.1.21.1), with the builtin init and syslogd.
There's a few issues though. First the inittab:
.... null::sysinit:/bin/sh /etc/rc null::sysinit:/bin/touch /var/log/messages null::respawn:/sbin/syslogd -n -S -s 12 -b 8 null::respawn:/sbin/klogd -n ....
The rc script is run before syslog, which means that all usefull information from rc is lost. (I'm not sure, what the touch command is for btw.) I could start syslog before rc (null::sysinit:/sbin/syslogd...), but that would remove the very important 'respawn'.
Also when 3rd party daemons are starting up, it could look like this:
... null::respawn:/bin/modbus ...
If the daemon doesn't support syslog or if something slips (eg. a print to stderr) it is lost. I cannot seem to redirect output to syslog. Eg.
... console::respawn:/bin/modbus|logger 2>1 ...
I've tried a number of different combinations. Nothing seems to work well. Ofc, I could edit all the daemons and make them support syslog. (But what if something slips?) It could be solved if I could write something like this:
And actually, there is a /dev/log. But it's a socket, normal redirects won't work. ... so I could make it work through a custom kernel module. Eg. I could create a module that creates a /dev/syslog_link that writes everything to printk. Problem is that the syslog would mark all messages from that one as 'kernel'. Very wrong.
So now I'm thinking that I could create a kernel module that writes to the /dev/log: https://stackoverflow.com/questions/1184274/how-to-read-write-files-within-a-linux-kernel-module https://www.cs.drexel.edu/~jjohnson/2012-13/fall/cs543/project/reading/kernel_fileio.pdf
I don't know if it's possible though and writing to files from kernel space hurts my fragile sence of right and wrong.