#ident	"@(#)initpkg:common/cmd/initpkg/init.d/cron	1.3.14.10"

if [ -z "$LC_ALL" -a -z "$LC_MESSAGES" ]
then
	if [ -z "$LANG" ]
	then
		LNG=`defadm locale LANG 2>/dev/null`
		if [ "$?" != 0 ]
		then LANG=C
		else eval $LNG
		fi
	fi
	export LANG
fi
LABEL="UX:$0"
CAT=uxrc

USAGE="/etc/init.d/cron {start|stop}" 

# Cron control
# Clear working privileges.

priv -allprivs work

case $1 in
'start')
	pid=
	if [ -z "$_AUTOBOOT" ]
	then
		pid=`/usr/bin/ps -e | /usr/bin/grep cron | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`
	fi

	if [ -z "${pid}" ]
	then
		# The directory '/var/cron' is at SYS_PUBLIC.  If cron is started
		# on a secure system (running at SYS_PRIVATE) without /var/cron/log 
		# already existing, it will abort because it will not be able to
		# write into this directory -- create it here.

		priv +macwrite work
		if [ ! -f /var/cron/log ] 
		then
			>/var/cron/log >/dev/null 2>&1
			if [ $? -ne 0 ]
			then
				command=`/usr/bin/basename $0`
				pfmt -l $LABEL -s error -g $CAT:15 "Cannot create /var/cron/log - cron not started.\n"
				exit 1
			fi
		fi
		priv -macwrite work

		# Change level before starting cron in case it was started
		# originally in SUM and files it accesses are at wrong level
		# for accessing under LPM.  If this is the first time we're
		# starting cron, LCK_CRON and the backup logfile do not exist
		# yet so we redirect stderr when using chlvl.

		if [ -x /sbin/chlvl ]
		then
			priv +setflevel work
			/sbin/chlvl SYS_PRIVATE /var/cron/* >/dev/null 2>&1
			/sbin/chlvl SYS_PRIVATE /etc/cron.d/LCK_CRON >/dev/null 2>&1
			/usr/bin/chmod 664 /var/cron/log >/dev/null 2>&1
			/usr/bin/chgrp sys /var/cron/log >/dev/null 2>&1
			priv -setflevel work
		else
			/usr/bin/chmod 664 /var/cron/log >/dev/null 2>&1
			/usr/bin/chgrp sys /var/cron/log >/dev/null 2>&1
		fi

		/usr/sbin/cron
	fi
	;;
'stop')
	# do nothing:  cron will be killed by shutdown procedures
	;;
*)
	pfmt -l $LABEL -s action -g $CAT:4 "Usage: %s\n" "$USAGE"
	;;
esac
