xref: /OK3568_Linux_fs/buildroot/package/pm-utils/00pm-utils (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2# vim: noexpandtab
3#
4# Copyright (C) 2022, Rockchip Electronics Co., Ltd
5#
6# Based on pm-utils-1.4.1's pm-action.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of version 2 of the GNU General Public License as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20#
21
22[ -d "/usr/lib/pm-utils/" ] || exit 0
23
24# The rule here? Simplicity.
25export STASHNAME=pm-suspend
26export STAGE="${1:-pre}"
27export METHOD="${2:-suspend}"
28. "/usr/lib/pm-utils/pm-functions"
29
30case "$METHOD" in
31	suspend*)	ACTION=suspend;   REVERSE=resume ;;
32	hibernate) 	ACTION=hibernate; REVERSE=thaw ;;
33	*)		exit 1 ;;
34esac
35
36remove_suspend_lock()
37{
38	release_lock "${STASHNAME}.lock"
39}
40
41try_lock "${STASHNAME}.lock" || exit 1
42
43# make sure we release the lock no matter how we exit
44trap remove_suspend_lock 0
45
46# clean up from the last run
47rm -rf "${STORAGEDIR}"
48mkdir -p "${STORAGEDIR}"
49# save our parameter list.
50[ -f "$PARAMETERS" ] || echo '' >"$PARAMETERS"
51add_parameters $PM_CMDLINE
52update_parameters
53
54init_logfile "${PM_LOGFILE}"
55log "Initial commandline parameters: $PM_CMDLINE"
56load_hook_blacklist
57load_hook_parameters
58
59case "$STAGE" in
60	pre)
61		log "$(date): Running hooks for $ACTION."
62		run_hooks sleep "$ACTION $METHOD"
63		log "$(date): performing $METHOD"
64		;;
65	post)
66		log "$(date): Running hooks for $REVERSE"
67		run_hooks sleep "$REVERSE $METHOD" reverse
68		log "$(date): Finished."
69		;;
70esac
71