xref: /netbsd-src/etc/powerd/scripts/sleep_button (revision 1541a8a5a7284cb2b1cb7df93ff5a30efd551187)
187c704caSmycroft#!/bin/sh -
287c704caSmycroft#
3*1541a8a5Sroy#	$NetBSD: sleep_button,v 1.11 2017/07/13 13:50:48 roy Exp $
487c704caSmycroft#
5d54c2134Sjmcneill# Generic script for sleep button events.
687c704caSmycroft#
787c704caSmycroft# Arguments passed by powerd(8):
887c704caSmycroft#
987c704caSmycroft#	device event
1087c704caSmycroft
1187c704caSmycroftcase "${2}" in
12d54c2134Sjmcneillpressed)
13256df2d4Sjym	if /sbin/sysctl -q hw.acpi.sleep.state; then
147373892aSjruoho		/sbin/sysctl -w hw.acpi.sleep.state=3
15256df2d4Sjym	elif /sbin/sysctl -q machdep.xen.suspend; then
16256df2d4Sjym		/sbin/sysctl -w machdep.xen.suspend=1
171cba716bSjmcneill	else
18d54c2134Sjmcneill		sleep 1
1954e08a28Sabs		if /etc/rc.d/apmd onestatus >/dev/null ; then
20d54c2134Sjmcneill			/usr/sbin/apm -z
21d54c2134Sjmcneill		else
22d54c2134Sjmcneill			/usr/sbin/apm -d -z
23d54c2134Sjmcneill		fi
24d54c2134Sjmcneill		# ... waking up
25d54c2134Sjmcneill		sleep 1
261cba716bSjmcneill	fi
27d54c2134Sjmcneill	;;
287373892aSjruoho
29d54c2134Sjmcneillreleased)
303ed028dcSjmcneill	case "${1}" in
313ed028dcSjmcneill	vmt0)
323ed028dcSjmcneill		# Virtual machine is resuming, restart the network
333ed028dcSjmcneill		/etc/rc.d/dhcpcd restart
343ed028dcSjmcneill		;;
353ed028dcSjmcneill	esac
36d54c2134Sjmcneill	;;
3787c704caSmycroft*)
38d54c2134Sjmcneill	logger -p warning "${0}: unsupported event ${2} on device ${1}" >&1
3987c704caSmycroft	exit 1
4087c704caSmycroft	;;
4187c704caSmycroftesac
42