aboutsummaryrefslogtreecommitdiff
path: root/package/ltt/init-tracer
blob: 3dee49211b8ad78fe8aa69b7361e2a24607a372c (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
#!/bin/sh
#
# Load tracer module and create tracer device node.
#

MODULE="tracer"
MAIN_DEVICE="tracer"
USER_DEVICE="tracerU"
GROUP="root"
MODE="664"

start() {
	if [ -e /dev/${MAIN_DEVICE} -o -e /dev/${USER_DEVICE} ]
	then
	    # tell the user about what we are doing
	    echo "Deleting old tracer nodes: /dev/tracer and /dev/tracerU"

	    # remove stale nodes
	    rm -f /dev/${MAIN_DEVICE}
	    rm -f /dev/${USER_DEVICE}
	fi

	# look for the major number
	MAJOR=`/bin/grep " ${MODULE}$" /proc/devices | cut -d" " -f1`

	# does the device exist?
	if [ ${MAJOR} ]
	then
	    echo "Found tracer device with major number:" ${MAJOR}
	else
 	    echo "Loading tracer kernel module: "
	    # invoke modprobe
	    /sbin/modprobe ${MODULE}
	    MAJOR=`/bin/grep " ${MODULE}$" /proc/devices | cut -d" " -f1`
	    if [ ${MAJOR} ]
	    then
		echo "Found tracer device with major number:" ${MAJOR}
	    else
		echo "Did not find tracer device ... /dev entries not created ..."
		exit 1
	    fi
	fi

	# tell the user about what we are doing
	echo "Creating new tracer nodes: /dev/tracer and /dev/tracerU"

	# create the character special file
	/bin/mknod /dev/${MAIN_DEVICE} c ${MAJOR} 0
	/bin/mknod /dev/${USER_DEVICE} c ${MAJOR} 1

	# set permissions and ownership
	/bin/chgrp ${GROUP} /dev/${MAIN_DEVICE}
	/bin/chmod ${MODE}  /dev/${MAIN_DEVICE}
	/bin/chgrp ${GROUP} /dev/${USER_DEVICE}
	/bin/chmod ${MODE}  /dev/${USER_DEVICE}
}
stop() {
	# tell the user about what we are doing
	echo "Deleting tracer nodes: /dev/tracer and /dev/tracerU"

	# remove nodes
	rm -f /dev/${MAIN_DEVICE}
	rm -f /dev/${USER_DEVICE}

	if lsmod | /bin/grep "^${MODULE} "
	then
	    echo -n "Removing tracer kernel module: "
	    # invoke modprobe -r
	    /sbin/modprobe -r ${MODULE}
	    echo "OK"
	fi
}
restart() {
	stop
	start
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?