ubuntuusers.de

Titel:
/usr/lib/pm-utils/bin/pm-action
Autor:
Taomon
Datum:
14. Mai 2018 11:15
Aktionen:
Code:
 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
# The rule here? Simplicity.
export STASHNAME=pm-suspend
export METHOD="$(echo ${0##*pm-} |tr - _)"
. "/usr/lib/pm-utils/pm-functions"

# return code tracking for when suspend fails
r=0

help()
{
	echo "${0##*/} [options]"
	echo
	echo "Options can change how suspend or hibernate is done."
	run_hooks sleep help
	sleep_module_help
	exit 0
}

if [ "$(id -u)" != "0" ]; then
	echo This utility may only be run by the root user. 1>&2
	exit 1
fi

remove_suspend_lock()
{
	release_lock "${STASHNAME}.lock"
}

try_lock "${STASHNAME}.lock" || exit 1

# make sure we release the lock no matter how we exit
trap remove_suspend_lock 0

# clean up from the last run
rm -rf "${STORAGEDIR}"
mkdir -p "${STORAGEDIR}"
# save our parameter list.
[ -f "$PARAMETERS" ] || echo '' >"$PARAMETERS"
add_parameters $PM_CMDLINE
update_parameters

while [ $# -gt 0 ]
do
	[ "$1" = "--help" ] && help
	shift
done


command_exists "check_$METHOD" && command_exists "do_$METHOD" || {
	log "pm-utils does not know how to $METHOD on this system."
	exit 1
}

"check_$METHOD" || {
	log "This system does not support $METHOD as a sleep method."
	exit 1
}

case "$METHOD" in
	suspend*) 	ACTION=suspend;   REVERSE=resume ;;
	hibernate) 	ACTION=hibernate; REVERSE=thaw ;;
	*)		echo "Cannot happen.  Please file a bug against pm-utils."
			exit 1 ;;
esac

init_logfile "${PM_LOGFILE}"
log "Initial commandline parameters: $PM_CMDLINE"
load_hook_blacklist
load_hook_parameters

# run the sleep hooks
log "$(date): Running hooks for $ACTION."
if run_hooks sleep "$ACTION $METHOD"; then
        # Sleep only if we know how and if a hook did not inhibit us.
	log "$(date): performing $METHOD"
	sync
	"do_$METHOD" || r=128
	log "$(date): Awake."
else
	log "$(date): Inhibit found, will not perform $METHOD"
fi
log "$(date): Running hooks for $REVERSE"
# run the sleep hooks in reverse with the wakeup action
if run_hooks sleep "$REVERSE $METHOD" reverse; then
        log "$(date): Finished."
else 
        exit $((r+1))
fi
exit $r
alex@beelzemon:~$