halt(8) says: -p When halting the system, switch off the power. This is the de‐ fault when halt is called as poweroff. Now /sbin/halt without the -p option executes "shutdown -h", whereas with the -p option it executes "shutdown -h -P". AFAICS, the only difference between the two is that environment variable INIT_HALT will be set to "POWEROFF" in the second case (while it remains unset otherwise). shutdown then calls /sbin/halt.sh which does: #!/bin/sh if [ "${INIT_HALT}" = HALT ]; then exec /sbin/halt -dhn else exec /sbin/poweroff -dhn fi Since INIT_HALT doesn't have the value "HALT" in either case, the script will always execute the else clause.
shutdown sets INIT_HALT = "HALT" here. https://github.com/slicer69/sysvinit/blob/3.07/src/shutdown.c#L558 https://github.com/slicer69/sysvinit/blob/3.07/src/shutdown.c#L459
Ah, but I guess halt doesn't call shutdown -H?
(In reply to Mike Gilbert from comment #2) > Ah, but I guess halt doesn't call shutdown -H? It's this code in function do_shutdown (in halt.c): args[i++] = "shutdown"; args[i++] = fl; if ( (! strcmp(fl, "-h") ) && (should_poweroff) ) args[i++] = "-P"; So it calls "shutdown -h" or "shutdown -h -P", but never "shutdown -h -H". Maybe halt.sh should test for [ "${INIT_HALT}" = POWEROFF ] instead?
(In reply to Ulrich Müller from comment #3) > Maybe halt.sh should test for [ "${INIT_HALT}" = POWEROFF ] instead? Yeah, that seems reasonable.
Updates from IRC: 14:33:40 <@floppym> ulm: I guess one concern is that this might result in unexpected behavior for people who currently run "shutdown -h" instead of "poweroff" or "shutdown -h -P". 14:34:31 <@floppym> ulm: It might make more sense to update halt.c to pass -H to shutdown. 14:42:54 <@floppym> Maybe this instead? https://gist.github.com/floppym/0e0e029c93b61c7089620d023fb5798c 15:02:05 <@ulm> floppym: I've tested you patch with "halt", "halt -p" and "poweroff" 15:02:46 <@ulm> all three behave as expected, i.e. no power-off with plain halt, power-off with the other two I will send a patch upstream and see what they have to say.
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=07b943791fb87acef33c0e50ea196e63937d6ffb commit 07b943791fb87acef33c0e50ea196e63937d6ffb Author: Mike Gilbert <floppym@gentoo.org> AuthorDate: 2023-07-27 13:48:34 +0000 Commit: Mike Gilbert <floppym@gentoo.org> CommitDate: 2023-07-27 13:49:25 +0000 sys-apps/sysvinit: prevent 'halt' from powering off the machine If you want to power off, use 'poweroff' or 'halt -p' instead. Closes: https://bugs.gentoo.org/911257 Signed-off-by: Mike Gilbert <floppym@gentoo.org> sys-apps/sysvinit/files/sysvinit-3.07-halt.patch | 53 +++++++ sys-apps/sysvinit/sysvinit-3.07-r1.ebuild | 190 +++++++++++++++++++++++ 2 files changed, 243 insertions(+)
Was this really necessary? Last night one of my computers didn't shut down, and it took me a while to figure out that now gentoo also adopted this braindead behavior that previously I only noticed with alpine and its busybox based init system. I've always shut down my gentoo machines with halt, and it worked fine in the last 17 or so years. Or if this change is really necessary, could we have at least have a huge warning when merging sysvinit that the behavior of `halt` changed significantly in a patch release and if you don't want to inflate your electricity bill you should use `halt -p` or `poweroff` instead of halt?
(In reply to Kővágó, Zoltán from comment #7) > [...] braindead behavior [...] The command now behaves as documented: -p When halting the system, switch off the power. This is the default when halt is called as poweroff. Conversely, I would conclude that it *doesn't* switch of the power when called without the -p option (because otherwise the option would be useless). > [...] if you don't want to inflate your electricity bill you should use > `halt -p` or `poweroff` instead of halt? This is exactly what halt(8) says?
He's asking for a warning to reinforce that given the behaviour change.
I have no objection to adding a warning, but I do not plan on adding it myself. Patches welcome.
(In reply to Sam James from comment #9) > He's asking for a warning to reinforce that given the behaviour change. "Previously, the 'halt' command caused the system to power off, even if option -p was not given. This long-standing bug has been fixed, and the command now behaves as documented."?
That language seems good to me.
Created attachment 868089 [details, diff] sys-apps/sysvinit: Add postinst message about halt bugfix
Or should we revbump to -r2, so that current users of -r1 will also see the message immediately?
Let's change it from elog to ewarn, and revbump the ebuild. Go ahead and push when ready.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=53aae885d64f2284895359d9366641656d82b49e commit 53aae885d64f2284895359d9366641656d82b49e Author: Ulrich Müller <ulm@gentoo.org> AuthorDate: 2023-08-17 17:41:35 +0000 Commit: Ulrich Müller <ulm@gentoo.org> CommitDate: 2023-08-17 19:25:28 +0000 sys-apps/sysvinit: Add postinst message about halt bugfix Bug: https://bugs.gentoo.org/911257#c7 Signed-off-by: Ulrich Müller <ulm@gentoo.org> .../{sysvinit-3.07-r1.ebuild => sysvinit-3.07-r2.ebuild} | 9 +++++++++ 1 file changed, 9 insertions(+)
Hi!, sys-power/acpid does shutdown -h if the init process it not openrc-init So with sysvinit-3.0.8, it hangs in place of poweroff when pressing the power button. I didn't inspected the other power utilities that react on power button, but it seems this new version of sysvinit aks to change those actions. Do I need to file a bug for sys-power/acpid?
(In reply to Xavier Miller from comment #17) > Hi!, > > sys-power/acpid does shutdown -h if the init process it not openrc-init > > So with sysvinit-3.0.8, it hangs in place of poweroff when pressing the > power button. > > I didn't inspected the other power utilities that react on power button, but > it seems this new version of sysvinit aks to change those actions. > > Do I need to file a bug for sys-power/acpid? shutdown -h (i.e. without the -H or -P option) still defaults to poweroff, because INIT_HALT is unset in /sbin/halt.sh. See comment #1 for a link to the relevant source code.
Thinking about it, it would be somewhat cleaner if acpid called shutdown with an explicit -P option instead of relying on its (undocumented) default. shutdown(8) says: -h Halt or power off after shutdown. Usually used with the -P or -H flags, depending on whether we want to poweroff or simply stop the operating system.