File: digimend-debug

package info (click to toggle)
digimend-dkms 13-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 952 kB
  • sloc: ansic: 4,536; sh: 142; makefile: 128
file content (73 lines) | stat: -rwxr-xr-x 1,940 bytes parent folder | download | duplicates (4)
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
#!/bin/bash
#
# Enable/disable debug code in DIGImend kernel drivers.
# Author: Nikolai Kondrashov <spbnick@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

set -e -u -o pipefail

function usage() {
	local progname=`basename "$0"`
	echo "Usage: $progname STATUS"
	echo "Enable/disable debug code in DIGImend kernel drivers,"
	echo "making sure affected modules are loaded."
	echo ""
	echo "Arguments:"
	echo "	STATUS	1/on/enable to enable, 0/off/disable to disable"
	echo ""
}

declare -r CONTROL_FILE="/sys/kernel/debug/dynamic_debug/control"
declare -r -a MODULE_LIST=("hid_uclogic")

if [ "$#" != 1 ]; then
	echo "Invalid number of arguments" >&2
	echo "" >&2
	usage >&2
	exit 1
fi

case "${1,,}" in
	0|off|disable)
		op="-"
		;;
	1|on|enable)
		op="+"
		;;
	*)
		echo "Unknown status: $1" >&2
		echo "" >&2
		usage >&2
		exit 1
		;;
esac

# Make sure modules are loaded, otherwise enabling will have no effect
if ! modprobe -a "${MODULE_LIST[@]}"; then
	echo "Failed loading DIGImend modules." >&2
	echo "Make sure they're installed, and you're root or using sudo." >&2
	exit 1
fi

if ! [ -r "$CONTROL_FILE" -a -w "$CONTROL_FILE" ]; then
	echo "Cannot access control file." >&2
	echo "Make sure you're root or using sudo." >&2
	exit 1
fi

for MODULE in "${MODULE_LIST[@]}"; do
	echo "module ${MODULE} ${op}pmfl" > "$CONTROL_FILE"
done