Created
March 15, 2017 11:39
-
-
Save iamahuman/de325cc7030bd618055f4f0669e8bc5e to your computer and use it in GitHub Desktop.
Linux ACPI debugger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
path=/sys/kernel/debug/acpi/acpidbg | |
history -r ~/.acpidbg_history 2> /dev/null || true | |
if ! [ -r "$path" -a -w "$path" ] | |
then | |
echo >&2 "acpidbg: not enough privileges" | |
exit 1 | |
fi | |
cat "$path" & out_pid=$! | |
terminate() { | |
exit_code=$? | |
echo "Exit" > "$path" || true | |
on_exit || true | |
exit $exit_code | |
} | |
on_exit() { | |
wait $out_pid || true | |
history -a ~/.acpidbg_history || true | |
} | |
trap terminate INT TERM | |
while sleep .05 && kill -0 $out_pid 2> /dev/null | |
do | |
if echo -ne '\r' && read -p '- ' -er REPLY | |
then | |
if [ -n "$REPLY" ] | |
then | |
history -s "$REPLY" || true | |
echo "$REPLY" > "$path" || break | |
fi | |
else | |
terminate | |
fi | |
done | |
on_exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment