slicer69 / sysvinit

GNU General Public License v2.0
111 stars 20 forks source link

power off on signal 38 #9

Closed omcaif closed 2 years ago

omcaif commented 2 years ago

Hi.

I was just trying to use the Tiny Power Button Driver on a Linux system and noticed that there is no signal to init to tell it to power off (at least its not signal 38 and its not in the man page).

The description seems to indicate that signal 38 is traditionally used to signal a power off. I did test kill -s 38 1 on a Debian system, which uses systemd-sysv and it worked.

I would appreciate if a signal can be added/documented to signal a power off.

Thanks.

slicer69 commented 2 years ago

Signal 38 doesn't seem to be defined or even an optional signal according to the kill/signal manual pages. Since signals have different meanings on different platforms/architectures we need to be really careful about how we use them.

I couldn't, for example, hard code signal 38 into init's behaviour because it might be called or used something else on different systems. Do you have any standards documentation which talks about signal 38 (or whatever its proper signal name is)?

You said there is a description which indicates signal 38 is traditionally used to signal a poweroff, but where is that documented? The script you linked to suggested maybe an existing signal +4 or using SIGINT, but that just makes it look like the user may be trying to kill init and forcing it to terminate to shutdown the system.

omcaif commented 2 years ago

You said there is a description which indicates signal 38 is traditionally used to signal a poweroff, but where is that documented?

Other than the link to the Linux kernel config documentation, I know nothing about any standards. I meant to say that the following description implies that signal 38, or "SIGRTMIN+4" is expected to cause a power off: "Likely values here include 38 (SIGRTMIN+4) to power off, or 2 (SIGINT) to simulate Ctrl+Alt+Del." Maybe this is just a systemd thing and that description assumes you use are using systemd.

I did notice that SIGINT is documented with the "expected" behavior (based on the kernel config documentation): https://github.com/slicer69/sysvinit/blob/main/man/init.8#L284.

Only SIGHUP is mentioned in Version 7 Unix man page: http://man.cat-v.org/unix_7th/8/init.

Since signals have different meanings on different platforms/architectures we need to be really careful about how we use them.

Are there any signals that can be used which are known to be "safe"?

Sorry, I don't really know about signals much; I just wanted to see if its possible to use the Tiny Power Button Driver, which can send a configured signal, instead of just 38.

slicer69 commented 2 years ago

As you pointed out, we do support using a signal (SIGINT) to trigger the ctrl+alt+del action. This will, on most distributions, trigger an immediate shutdown, which is what I think you want to do. So the functionality is already there. You'd just need to tell Tiny Power Button Driver to send SIGINT instead of signal 38.

Just make sure in your /etc/inittab file you've got a line which handles the ctrlaltdel message. On Debian and related distributions the line looks like this:

  ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
omcaif commented 2 years ago

Thanks for that. I'm not sure why I assumed /etc/inittab was only for setting up serial consoles, so I did not bother looking into it. I changed the ctrlaltdel action to /sbin/shutdown -hP now to achieve my desired effect.

Personally, I am happy to close this issue, but I guess it is fine to reopen if there is a need to research how other init implementations (e.g. BusyBox) handle SIGRTMIN+4.