Subject: Re: Kernel <-> init communication for shutdown
To: None <tech-kern@NetBSD.ORG>
From: Ty Sarna <tsarna@endicor.com>
List: tech-kern
Date: 01/14/2001 17:28:43
In article <200101141322.f0EDMhc23515@night-porter.duskware.de>,
Martin Husemann  <martin@duskware.de> wrote:
> I'd like to propose a slight change to /sbin/init: there are several 
> architectures which have some sort of "power" button on their keyboard
[...]
> Actually (maybe enabled/disabled by a kernel option) this could also be
> mapped to the Ctrl-Alt-DEL keysequence.)
[...]
> I'd like to implement something like this for NetBSD and am looking for 
> comments on design and possible implementations.

How about the following?

- Power button sends init SIGPWR
- Ctrl-Alt-Del (or platform equivalent if there is one) sends init SIGUSR1
- Other special key, if any, sends init SIGUSR2

on receipt of SIGPWR/SIGUSR1/SIGUSR2, if /etc/initbuttons (or something
better named) exists, execute it with arg power/ctrlaltdel/other.
We supply the defaults below.

This should make everyone happy. People running systems who don't want
anything to happen get their wish by default. People who do can enable
it easily. People who have some other thing they'd like the commands to
do (run a screen lock command or whatever) can get that behavior.


---------- /etc/defaults/rc.conf ----------
# /sbin/init button actions
#
power_button=NO					# Execute Power button command?
power_command="/sbin/shutdown -p now"		# Command to run
ctrlaltdel_button=NO				# Execute Ctrl-Alt-Del command?
ctrlaltdel_command="/sbin/shutdown -r now"	# Command to run
other_button=NO					# Execute other button command?
other_command="/bin/true"			# Command to run
-------------------------------------------

---------- /etc/initbuttons ----------
#!/bin/sh
. /etc/rc.subr
. /etc/rc.conf

usage()
{
	echo 1>&2 "usage: $0 [power|ctrlaltdel|other]"
	exit 1
}

if [ $# != 1 ]; then usage; fi

case $1 in
power)
	if checkyesno 'power_button'; then
		$power_command
	fi
	;;

ctrlaltdel)
	if checkyesno 'ctrlaltdel_button'; then
		$ctrlaltdel_command
	fi
	;;

other)
	if checkyesno 'other_button'; then
		$other_command
	fi
	;;

*)
	usage
	;;
esac
--------------------------------------