~louis/crashdc/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# /bin/sh
# *****************************************************************
# *                                                               *
# *   Copyright 2009 Hewlett-Packard Development Company, L.P.    *
# *                                                               *
# *   crashdc may be copied only under the terms of the GNU       *
# *   General Public License, which may be found in the source    *
# *   kit.                                                        *
# *                                                               *
# *****************************************************************
#KDUMPSUCCESS=$1
#
# Changed for test
#
KDUMPSUCCESS=0
CRASHDCSUCCESS=0

if [[ -r /etc/sysconfig/crashdc ]];then
        . /etc/sysconfig/crashdc
else
        echo "The file /etc/sysconfig/crashdc is absent. Cannot run"
        exit 1
fi

. /etc/sysconfig/kdump
. /etc/rc.status

KDUMP_CLEANUP_DUMPS=/usr/sbin/kdump-cleanup_dumps
KDUMP_SAVE_DUMP=/usr/sbin/kdump-save_dump

# Clean up old stuff if necessary, check the free size
# and save the vmcore
save_core()
{
    $KDUMP_CLEANUP_DUMPS
    if [ "$?" -ne 0 ] ; then
	rc_status -v
	return 1
    fi

    $KDUMP_SAVE_DUMP /proc/vmcore
    rc_status -v

    return 0
}

#
# execute the save_core function similar to the one in
# /etc/init.d/kdump since it's not being done when
# KDUMP_TRANSFER is used.
#
save_core
KDUMPSUCCESS=$?

if [ $KDUMPSUCCESS == 0 ];then
	coredir=${VMCOREDIR}/`ls -rt ${VMCOREDIR} | cut -d\  -f2 | tail -1`
	readelf -n $coredir/vmcore | grep -q Xen
	is_not_xen=$?
	if (( is_not_xen ));then
		kver=$(uname -r)
		kver=${kver%-kdump}
		kname=$(strings -n3 /proc/vmcore | grep -m1 "^Linux version")
		set +a $kname
		kname=$3
		kname=${kname#$kver-}
	else
		kver=$(uname -r)
		kver=${kver%-kdump}
		kname=xen
	fi

	namelist=/boot/vmlinux-${kver}-${kname}
	if ! [ -r $namelist ];then
		#
		# namelist is delivered compressed 
		# might need to be uncompressed
		#
		if [ -f ${namelist}.gz ];then
			gzip -d -c ${namelist}.gz > $namelist
		else
			$LOGGER "Unable to locate $namelist. Verify that the \
			kernel-debuginfo packages are correctly installed \
			or uncompresed."
			false
			rc_status -v
			exit 1
		fi
	fi

	$CRASHDC $CRASHDCDEBUG $namelist $coredir/vmcore $coredir
	CRASHDCSUCCESS=$?
	if [ $CRASHDCSUCCESS == 0 ];then
		$LOGGER "generated a crash-data file to $coredir"
		rc_status -v
		exit 0
	else
		$LOGGER "Unable to generate a crash-data file"
		rc_status -v
		exit 1
	fi
fi