#! /bin/sh
#
# |-----------------------------------------------------------|
# | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
# | All Rights Reserved                                       |
# |-----------------------------------------------------------|
# |          Restricted Rights Legend                         |
# | Use, duplication, or disclosure by the Government is      |
# | subject to restrictions as set forth in                   |
# | subparagraph (c)(1)(ii) of the Rights in Technical        |
# | Data and Computer Software Clause of DFARS 252.227-7013.  |
# |         MIPS Computer Systems, Inc.                       |
# |         950 DeGuigne Avenue                               |
# |         Sunnyvale, California 94088-3650, USA             |
# |-----------------------------------------------------------|
#
# $Header: savecore,v 1.5.2.1 92/06/24 13:35:03 marker Exp $

#
# Save core from kernel
#

Crashdir=/usr/adm/crash

main()
{
	case "$1" in
		start)
			save_core
			;;
		stop)
			;;
		*)
			echo "$0: usage: $0 [start|stop]"
			exit 1
			;;
	esac
}

save_core()
{
	if [ -d "$Crashdir" ]
	then
		echo "checking for system core dump..."
		Newcore=""
		if [ -s "$Crashdir/bounds" ]
		then
			Newnum=`cat "$Crashdir/bounds"`
		fi
		/etc/savecore "$Crashdir"
		case "$Newnum" in
			"")
				;;
			*)
				( link_unix "$Crashdir" $Newnum )
				;;
		esac
	else
		echo "No directory for saving core dumps"
	fi
}

#
# Look for unix.* files in the crash directory that are the same as the
# current unix file, and link these together to save space.
#

link_unix()
{
	cd "$1"
	if [ -f "unix.$2" ]
	then
		for unix in unix.*
		{
			case "$unix" in
				"unix.$2")
					continue
					;;
			esac
			if cmp -s "unix.$2" "$unix" >/dev/null 2>&1
			then
				rm -f "unix.$2"
				ln "$unix" "unix.$2"
				return
			fi
		}
	fi
}

main ${1+"$@"}
exit 0
