vsudd: Log over syslog

This means that with the previous patches normal vsudd logging will be logged
on the console. The exceptional case of error logging during syslog forwarding
established in the previous patch remains in place.

Prior to this the vsudd.log was actually in /run/vsudd.log and not in /var/log/
(exported to the host) as expected. Prior to c5940b3479 ("Bind the original
/var/log onto /run/log") the log was simply shadowed under the fuse mount over
/var/log.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
Ian Campbell 2016-07-01 13:44:32 +01:00
parent 7dd7b0c0da
commit ad7f4c74b2
2 changed files with 15 additions and 6 deletions

View File

@ -20,7 +20,6 @@ start()
fi
[ -n "${PIDFILE}" ] || PIDFILE=/var/run/vsudd.pid
[ -n "${LOGFILE}" ] || LOGFILE=/var/log/vsudd.log
if [ -n "$SYSLOG_PORT" ] ; then
# Can be inlined below once Windows defines syslog port
@ -31,9 +30,9 @@ start()
--background \
--exec /sbin/vsudd \
--make-pidfile --pidfile ${PIDFILE} \
--stderr "${LOGFILE}" --stdout "${LOGFILE}" \
-- -inport "${DOCKER_PORT}:unix:/var/run/docker.sock" \
${SYSLOG_OPT}
${SYSLOG_OPT} \
-detach
eend $? "Failed to start vsudd"
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"log/syslog"
"net"
"os"
"strconv"
@ -66,15 +67,24 @@ func main() {
flag.Parse()
if detach {
logFile, err := os.Create("/var/log/vsudd.log")
syslog, err := syslog.New(syslog.LOG_INFO|syslog.LOG_DAEMON, "vsudd")
if err != nil {
log.Fatalln("Failed to open log file", err)
log.Fatalln("Failed to open syslog", err)
}
log.SetOutput(logFile)
null, err := os.OpenFile("/dev/null", os.O_RDWR, 0)
if err != nil {
log.Fatalln("Failed to open /dev/null", err)
}
/* Don't do this above since we aren't yet forwarding
/* syslog (if we've been asked to) so the above error
/* reporting wants to go via the default path
/* (stdio). */
log.SetOutput(syslog)
log.SetFlags(0)
fd := null.Fd()
syscall.Dup2(int(fd), int(os.Stdin.Fd()))
syscall.Dup2(int(fd), int(os.Stdout.Fd()))