summaryrefslogtreecommitdiff
path: root/archivers/rar/files/check-ksyms.sh
blob: 8e1fb3b569d0245b927454a0349db16bdd9c88d9 (plain)
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
#!/bin/sh
#
# $NetBSD: check-ksyms.sh,v 1.1 2007/08/22 16:43:36 jlam Exp $
#
# check-ksyms.sh verifies that the given symbols are found in the booted
# kernel file.
#

: ${ECHO=echo}
: ${GREP=grep}
: ${GZIP_CMD=gzip}
: ${NM=nm}
: ${RM=rm}
: ${TMPDIR=/tmp}

self="check-ksyms"

verbose=
while [ $# -gt 0 ]; do
	case $1 in
	-v)	verbose=yes; shift ;;
	--)	shift; break ;;
	-*)	${ECHO} 1>&2 "$self [-v] symbol ..."; exit 2 ;;
	*)	break ;;
	esac
done

# Locate kernel.
PATH=/sbin:/usr/sbin:${PATH}; export PATH

booted_kernel=
kernlist="/netbsd /netbsd.gz /onetbsd /onetbsd.gz"
kern=`sysctl -n machdep.booted_kernel 2>/dev/null`
if [ -z "$kern" ]; then
	kernlist="$kern $kernlist"
fi
for k in $kernlist; do
	if [ -f "$k" ]; then
		booted_kernel="$k"
		break
	fi
done

if [ -z "$booted_kernel" ]; then
	${ECHO} 1>&2 "$self: could not determine the booted kernel."
	exit 2
fi

pattern=
for symbol	# in command-line arguments
do
	if [ -z "$pattern" ]; then
		pattern="$symbol"
	else
		pattern="$pattern\|$symbol"
	fi
done

# If there are no symbols to check, then exit with success.
[ -n "$pattern" ] || exit 0

if [ ! -d "${TMPDIR}" ]; then
	${ECHO} 1>&2 "$self: ${TMPDIR} does not exist."
	exit 2
fi

ksymsfile="${TMPDIR}/ksyms.$self.$$"

# Clean up when we receive the following signals: INT QUIT ABRT KILL TERM.
trap "${RM} -f \"$ksymsfile\"" 2 3 6 9 15

case $booted_kernel in
*.gz)	${GZIP_CMD} -d < "$booted_kernel" | ${NM} > "$ksymsfile" ;;
*)	${NM} "$booted_kernel" > "$ksymsfile" ;;
esac

# Loop through the symbols and check that each of them are in $ksymsfile.
exitcode=0
while [ $# -gt 0 ]; do
	symbol="$1"; shift
	if [ x"$verbose" = xyes ]; then
		cmd="${GREP} \"$symbol\" \"$ksymsfile\" 2>/dev/null"
	else
		cmd="${GREP} \"$symbol\" \"$ksymsfile\" >/dev/null 2>&1"
	fi
	if eval $cmd; then
		:
	else
		${ECHO} 1>&2 "$self: symbol $symbol not found in $booted_kernel"
		exitcode=1
		break
	fi
done

${RM} -f "$ksymsfile"
exit $exitcode