#!/bin/bash
#
# rc.halt       This file is executed by init when it goes into runlevel
#               0 (halt) or runlevel 6 (reboot). It kills all processes,
#               unmounts file systems and then either halts or reboots.
#
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#               Modified for RHS Linux by Damien Neil
#				Modified for Seyeon Embedded Linux by ChanYoon Jung
#

# Set the path.
PATH=/sbin:/bin:/usr/bin:/usr/sbin

. /etc/init.d/functions

runcmd() {
   echo -n "$1 "
   shift
   if [ "$BOOTUP" = "color" ]; then
      $* && echo_success || echo_failure
   else
      $*
   fi
   echo
}

# See how we were called.
case "$0" in
  *halt)
	message="The system is halted"
	command="halt"
	;;
  *reboot)
	message="Please stand by while rebooting the system..."
	command="reboot"
	;;
  *)
	echo "$0: call me as \"rc.halt\" or \"rc.reboot\" please!"
	exit 1
	;;
esac

#####################################################################

# Kill all processes.
[ "${BASH+bash}" = bash ] && enable kill

runcmd "Syncing hardware clock to system time..." /sbin/hwclock --systohc --utc

#runcmd "Sending all processes the TERM signal..." /sbin/killall5 -15
#sleep 1
#runcmd "Sending all processes the KILL signal..."  /sbin/killall5 -9

#####################################################################

# Write to wtmp file before unmounting /var
halt -w

# Unmount
# Fallowing is in case of x86
#runcmd "Unmounting file systems"  umount -a -f -t noproc
# Fallowing is in case of IT8172
runcmd "Unmounting file systems"  umount -a -f

mount -n -o remount,ro / 2>/dev/null

#runcmd "Unmounting proc file system: " umount /proc

#####################################################################

eval $command -i -d -p 
