#!/bin/sh
#
# syslog        Starts syslogd/klogd.
#
#

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

[ -f /usr/sbin/syslogd ] || exit 0

if [ -f /usr/local/etc/syslog.conf ]; then
    cp -f /usr/local/etc/syslog.conf /etc
fi  

if [ -f /etc/config/network ]; then
    configfile='/etc/config/network'
    configfile_secured='/etc/config/network'
    # check if the file contains something we don't want 
    if egrep -q -v '^#|^[^ ]*=[^;]*' "$configfile"; then
        # filter the original to a new file 
        egrep '^#|^[^ ]*=[^;&]*'  "$configfile" > "$configfile_secured"
        configfile="$configfile_secured"
    fi
    source "$configfile"
    if [ x"$SYSLOG" != x"" ]; then
        echo "# forward log messages to remote syslog"    >> /etc/syslog.conf;
        echo "user.*				@$SYSLOG" >> /etc/syslog.conf;
    fi;
fi                                                                        

# See how we were called.
case "$1" in
  start)
	echo -n "Starting system logger: "
	# we don't want the MARK ticks
	daemon syslogd -m 0 -h -r -s localhost
	echo
	echo -n "Starting kernel logger: "	
	daemon klogd
	echo 
	touch /var/lock/syslog
	;;
  stop)
	echo -n "Shutting down system logger: "
	killproc klogd
	echo
	echo -n "Shutting down kernel logger: "
	killproc syslogd
	echo
	rm -f /var/lock/syslog
	;;
  status)
	status syslogd
	;;
  restart)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: syslog {start|stop|status|restart}"
	exit 1
esac

exit 0
