Re: How to trap ctrl-alt-del?

From: Guillermo <>
Date: Sat, 26 Nov 2016 13:49:20 -0300

2016-11-25 6:28 GMT-03:00 Colin Booth:
> On Nov 25, 2016 3:53 AM, "Casper Ti. Vector" wrote:
>> On Fri, Nov 25, 2016 at 11:07:15AM +0300, Jean Louis wrote:
>>> How may I trap ctrl-alt-del,
>> $ sysctl kernel.ctrl-alt-del=0
> This is a bit misleading since most (all?) default builds of linux already
> have kernel.ctrl-alt-del set to zero.

Acually, booting my own system with init=/bin/sh (i.e. without a
"proper" init) a couple of months ago I found the opposite to be true,
and IIUC this is also what happened to the OP. Anyway, if one wants to
trap CTRL+Alt+Del it probably *is* a good idea to explicitly set it
with 'sysctl kernel.ctrl-alt-del=0', or some equivalent of 'echo 0
>/proc/sys/kernel/ctrl-alt-del' after mounting /proc, instead of
relying on whatever happens to be the kernel's default.

2016-11-25 5:07 GMT-03:00 Jean Louis:
> While previously the ctrl-alt-del was trapped by SysV (or whatever),
> so that system runs "halt", `[...]

sysvinit does indeed turn CTRL+Alt+Del trapping on explicitly in the C code.

2016-11-26 9:10 GMT-03:00 Jean Louis:
> Now I wonder how to practically implement the -s option, should I just
> give it something like "sudo s6-poweroff"?
> On Fri, Nov 25, 2016 at 12:17:24PM +0300, Jean Louis wrote:
>> Now I found a solution

You write a diverted SIGINT handler according to the s6-svscan
documentation, as mentioned earlier, that at some point performs an
's6-svscanctl -6' or 's6-svscanctl -rt' on the scan directory, to make
s6-svscan exec into its 'finish' script with a 'reboot' argument. The
actual rebooting would be done directly or indirectly in the 'finish'
script. What else exactly the diverted SIGINT handler needs to do
depends on your setup, which brings me to...

2016-11-25 5:07 GMT-03:00 Jean Louis:
> [...] now when I have switched to s6-rc an s6-tools, [...]

You say you switched to s6-rc, are you not already running s6-svscan
as process 1 in "divert signals mode" (-s)? Also as mentioned earlier,
there is the s6-linux-init package, and the model of operation of its
s6-linux-init-maker program relies on directly or indirectly
performing an 's6-rc change' from a diverted signal handler to cleanly
bring the services down [1]. Are you using a custom setup instead?

If you use the unmodified s6-linux-init-maker output, you write a
suitable stage2_finish script to bring s6-rc services down, and you
want CTRL+Alt+Del to mean "reboot", then you don't have to do anything
special besides turning the feature on (in the stage2 script or an
s6-rc oneshot); s6-linux-init-maker creates a diverted SIGINT handler
for you (needed for the s6-reboot program to work, now also in
s6-linux-init) that does what you want.

[1] Explained in detail here under the "Shutdown sequence" title:
Received on Sat Nov 26 2016 - 16:49:20 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC