#!/bin/bash
#
# syslog        Starts syslogd/klogd.
#
#
# chkconfig: 2345 12 88
# description: Syslog is the facility by which many daemons use to log \
# messages to various system log files.  It is a good idea to always \
# run syslog.

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

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

# Source config
if [ -f /etc/sysconfig/syslog ] ; then
	. /etc/sysconfig/syslog
else
	SYSLOGD_OPTIONS="-m 0"
	KLOGD_OPTIONS="-2"
fi

RETVAL=0

umask 077

# [Pixel] shadow the initlog program
# => try to find the command when called as "initlog ...options... -c command args"
#    (hopefully the way to call initlog won't change!)
#
# why doing this: the pb of initlog being called when syslog is being
# restarted is that minilogd is started to keep the logs waiting for syslog to
# really treat them. Alas with devfs mounted (with or without devfsd),
# minilogd do not exit as it should. I don't know why.
#
# minilogd keeping the logs means its memory usage grows a lot as time goes.
# Restarting syslog mainly happens when upgrading glibc.
#
initlog() {
    while [ "$1" != "-c" ]; do 
	[ -n "$1" ] || return
	shift
    done
    shift ; $*
}


start() {
 	gprintf "Starting system logger: "
	daemon syslogd $SYSLOGD_OPTIONS
	RETVAL=$?
	echo
	gprintf "Starting kernel logger: "
	daemon klogd $KLOGD_OPTIONS
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/syslog
	return $RETVAL
}	
stop() {
	gprintf "Shutting down kernel logger: "
	killproc klogd
	echo
	gprintf "Shutting down system logger: "
	killproc syslogd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/syslog
	return $RETVAL
}
rhstatus() {
	status syslogd
	status klogd
}
restart() {
	stop
	start
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
  	rhstatus
	;;
  restart|reload)
  	restart
	;;
  condrestart)
  	[ -f /var/lock/subsys/syslog ] && restart || :
	;;
  *)
	gprintf "Usage: %s {start|stop|status|restart|condrestart}\n" "$0"
	exit 1
esac

exit $?

