Previous Next Contents

6. Syslog

6.1 Problem

Syslog is the system logging utility commonly used on UNIX systems. Syslog is a daemon that opens a special file called a FIFO. A FIFO is a special file that is like a pipe. Anything that is written to the write side will come out the read side. The syslog daemon waits for data from the read side. There are C functions that write to the write side. If you write your program with these C functions your output will go to syslog. Remember that we have used a chroot environment and the FIFO /dev/log is not in the virtual environment. That means all the virtual environments will not log to syslog. We cannot simply copy the file since the programs use /dev/log instead of the new one we would create.

Beware that certain versions of syslog use a udp socket instead of the FIFO. However, this is usually not the case.

6.2 Solution

Syslog can look to a different FIFO if you tell it on the command line so run syslog with the argument:

syslog -p /virtual/log

Then link /dev/log to /virtual/log by (Note it is a SYMLINK):

ln -sf /virtual/log /dev/log

Then link all the /dev/log copies to this file by running (Note it is a hard link and NOT a symlink):

ln /virtual/log /virtual/ 

The virtfs script above already does this. Since /virtual is one contiguous disk and the /dev/log's are linked they have the same inode number and point to the same data. The chroot cannot stop this so all your virtual /dev/log's will now function. Note that all the messages from all the environments will be logged in one place. However, you can write separate programs to filter out the data. If you do not want to write a program and require separate log files you can use a separate syslog for each virtual filesystem by running:

syslog -p /virtual/ 
syslog -p /virtual/ 

However that wastes process id's so I do not recommend it. This version of the syslog.init file relinks the /dev/log's each time you start it in case they have been improperly set up. Here is a modified syslog.init file:


# Source function library.
. /etc/rc.d/init.d/functions

case "$1" in
        echo -n "Starting dev log: "
        ln -sf /virtual/log /dev/log
        echo done
        echo -n "Starting system loggers: "
        daemon syslogd -p /virtual/log
        daemon klogd
        echo -n "Starting virtual dev log: "
        for i in /virtual/*
                if [ ! -d "$i" ]
                if [ "$i" = "/virtual/lost+found" ]
                ln -f /virtual/log $i/dev/log
                echo -n "."
        echo " done"
        touch /var/lock/subsys/syslog
        echo -n "Shutting down system loggers: "
        killproc syslogd
        killproc klogd
        rm -f /var/lock/subsys/syslog
        echo "Usage: syslog {start|stop}"
        exit 1

exit 0

Note that you do not have to put all the virtual filesystems on one disk. However, you will have to run a different syslog for each partition that has virtual filesystems on it.

Previous Next Contents