Bug 475006 - shutdown ignores requested halt action
shutdown ignores requested halt action
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: initscripts (Show other bugs)
All Linux
low Severity medium
: rc
: ---
Assigned To: initscripts Maintenance Team
: Regression, Reopened
Depends On: 475609
Blocks: 501487
  Show dependency treegraph
Reported: 2008-12-06 11:29 EST by Vadym Chepkov
Modified: 2009-09-02 07:14 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 501487 (view as bug list)
Last Closed: 2009-09-02 07:14:22 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
create /halt file if halt action was requested (1.73 KB, patch)
2008-12-06 11:29 EST, Vadym Chepkov
no flags Details | Diff
patch (401 bytes, patch)
2008-12-09 10:16 EST, Bill Nottingham
no flags Details | Diff

  None (edit)
Description Vadym Chepkov 2008-12-06 11:29:02 EST
Created attachment 326004 [details]
create /halt file if halt action was requested

When you request a halt action
/sbin/shutdown -h -H now
instead of halting system gets powered down

The problem comes from SysVinit-2.86-14

/etc/init.d/halt from initscripts- has this line of code

[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"

Which makes poweroff a default action in absence of /halt file. In my opinion this assumption is questionable for servers. Usually, after a power failure if a system BIOS has "Power recovery: LAST" setting, system can start automatically after power returns. If the action during shutdown was poweroff it would never happen, somebody would have to go to the server and press the power button. 

But back to shutdown problem. 
when /sbin/halt is called it properly creates /halt file if -p switch (power off) was not passed, so for /sbin/halt halt is default action, proper behavior, in my opinion. But when /sbin/shutdown called with -H switch it doesn't create /halt file, which it should.

Proposed patch is attached. I removed "usage" comment because it is not in sync with the actual source code
Comment 1 Vadym Chepkov 2008-12-06 17:10:41 EST
Unfortunately, the approach doesn't work on kernel-xen. 
First, strcmp(halttype,HALT) code causes segmentation fault, because halttype
is uninitialized. But even after I fixed that, still kernel-xen powers down.

so, to reiterate the problem

/sbin/shutdown -h -H now doesn't halt the system

if on plain kernel you do touch /halt first, system halts as expected. No
workaround for kernel-xen
Comment 2 Bill Nottingham 2008-12-08 10:46:55 EST
I'm cloning this bug for our development stream, to be considered for the next major Red Hat Enterprise Linux release.

As this change would change behavior that's been in all prior versions of Red Hat Enterprise Linux releases, this isn't really something suitable for fixing in an update to RHEL 5, where we try and maintain as stable a base as possible. Ergo, closing as WONTFIX for RHEL 5.
Comment 3 Vadym Chepkov 2008-12-09 02:05:42 EST
I think, I was misunderstood. I didn't ask to change the behavior.
The subject of the bug report stands.

man shutdown says:

       -h     Halt or poweroff after shutdown.

       -H     Halt action is to halt or drop into boot monitor on systems that
              support it.

#  /sbin/shutdown -? shows:
                  -h:      halt after shutdown.
                  -P:      halt action is to turn off power.
                  -H:      halt action is to just halt.

and command
shutdown -h -H now does not halt the system
Comment 4 Bill Nottingham 2008-12-09 10:16:59 EST
Created attachment 326330 [details]

Whoops, misread that as you wanted to change the default for -h to halt w/o poweroff.

Does the attached fix it for you?
Comment 5 Vadym Chepkov 2008-12-09 10:58:43 EST
It did only for plain kernel, not for kernel-xen and on kernel-xen shutdown coredumps with my patch, so I don't think it's a proper way to handle the situation.
Comment 6 Bill Nottingham 2008-12-09 12:04:22 EST
Please try the patch I posted, not your patch.
Comment 7 Vadym Chepkov 2008-12-09 12:22:32 EST
Whoops :)

After a small correction (space is missing before first closing bracket)

The patch halts normal kernel, but not kernel-xen.
Comment 8 Bill Nottingham 2008-12-09 13:23:04 EST
Does a manual invocation of 'halt -f' also poweroff?
Comment 9 Bill Nottingham 2008-12-09 13:31:22 EST
Poweroff the xen kernel, that is.
Comment 10 Vadym Chepkov 2008-12-09 13:36:57 EST
/sbin/halt -f halts system with normal kernel and poweroffs kernel-xen
Comment 11 Bill Nottingham 2008-12-09 13:44:28 EST
OK. Can you open a separate bug against kernel-xen for that? This patch fixes the general case, and once kernel-xen is fixed, it should work there too.
Comment 12 Vadym Chepkov 2008-12-09 14:12:55 EST
Bug 475609 has been submitted, I am not sure if we should link them together or not.
Comment 13 Vadym Chepkov 2008-12-15 10:07:18 EST
Do I need to submit duplicates for Fedora? It has the same issue.
Comment 14 Bill Nottingham 2008-12-16 10:03:10 EST
http://git.fedorahosted.org/git/?p=initscripts.git;a=commitdiff;h=b7b6cb4ce32ba749f5f7b786ddc3bafd37442a89 was committed to the Fedora upstream; it hasn't been built yet, though.
Comment 16 Harald Hoyer 2009-05-05 08:51:59 EDT
Please test the erratum candidate:
Comment 18 Vadym Chepkov 2009-05-06 16:13:14 EDT
I only can see people.redhat.com Logo
Comment 19 Harald Hoyer 2009-05-07 04:17:11 EDT
works for me from outside connections
Comment 20 Vadym Chepkov 2009-05-07 07:20:54 EDT
Hmm, must have been temporary issue.

Anyway, /etc/init.d/halt has a syntax error in line 220, unmatching ]

Comment 21 Vadym Chepkov 2009-05-07 07:24:53 EDT
After I fixed the error above the system did halt as requested.
Comment 22 Harald Hoyer 2009-05-07 08:12:19 EDT
I should have double checked the patch from comment #14

Thank you!
Comment 24 Jay Turner 2009-05-13 08:04:46 EDT
I'm kicking this back to assigned to pick up the typo identified in comment 20.
Comment 25 Jay Turner 2009-05-19 10:07:59 EDT
Fix confirmed with initscripts-8.45.28-1.el5.  Looks like the advisory has been updated as well so moving this to Verified.

[root@dyno /etc/rc.d/rc0.d]# rpm -q initscripts
[root@dyno /etc/rc.d/rc0.d]# diff -Nru S01halt.orig S01halt
--- S01halt.orig        2009-05-13 07:18:11.000000000 -0400
+++ S01halt     2009-05-14 13:57:05.000000000 -0400
@@ -217,6 +217,6 @@
 [ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null
 exec $command $HALTARGS
Comment 27 errata-xmlrpc 2009-09-02 07:14:22 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.


Note You need to log in before you can comment on or make changes to this bug.