Bug 45966 - halt/reboot scripts with word action or daemon commit suicide too soon
Summary: halt/reboot scripts with word action or daemon commit suicide too soon
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: initscripts   
(Show other bugs)
Version: 7.1
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact: Brock Organ
Depends On:
TreeView+ depends on / blocked
Reported: 2001-06-26 04:35 UTC by j. alan eldridge
Modified: 2014-03-17 02:21 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-06-26 14:51:20 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description j. alan eldridge 2001-06-26 04:35:44 UTC
Description of Problem, followed by technophilosophical discussion on why 
the damn thing just isn't a good idea:

In /etc/rc, the code that execs the various S??* scripts tries to 
ascertain whether it is safe to exec a script or whether it should run it 
in a subshell. To do this, it looks for calls to the shell functions 
"action" and "daemon". 

Whether this is even an advisable method, *if* implemented correctly, is 
not clear to me.

But ... it is clear that the way it is implemented is less than desirable 
and can lead to exceedingly bizarre behavior.

Scripts name halt or reboot are the last guys in the chain. /etc/rc wants 
to exec them, after clearing out locale references. If it doesn't do 
this, they will hold open files on /usr.

The problem is that the logic checks for the words "action" or "daemon" 
in a script *first*, then checks to see if it's halt or reboot.

I have a UPS. I switched to NUT. NUT requires adding code to 
/etc/rc.d/init.d/halt to tell the UPS daemon to kill the power.
I put a comment in that file, saying, "tell the UPS daemon to kill the 
power". You can see where this is going, can't you?

My comment tripped the "daemon" checker, which executed halt in a 
subshell. It had references to locale files on /usr. Halt loops over 
filesystems, killing all processes with open files that prevent 
unmounting. Halt kills all process with open files on /usr. Halt has an 
open file on /usr. Therefore, .... Aiiiieeeeee! Halt commits suicide 
before it is ready to commit suicide.

Please, before this is dismissed as minor, think about trying to debug 
this mess. Not pretty, is it? 

I am willing to argue that the text of a comment in any script, but 
especially not a critical system script, should not cause changes in the 
script's behavior at all. This isn't just a change in behavior, it is ... 
premature suicide!? 

So, first, please reverse the order of the tests. Check for halt or 
reboot first.

Second, think about whether this whole idea is really sound. It's 
tempting to say, "ok, we'll strip comments." So I add an echo command:
	echo "Telling UPS daemon to kill power"
and we're right back where we started. "OK, strip strings, too."
Well, how about:
	$(echo "action") "Fsck me" /sbin/fsck --me --really_hard
You'll miss that one. I don't think there's any way to make this do what 
is meant.

There has to be a better way. Unfortunately between mucking with KDE-2.2 
CVS, and tracking down a kernel 2.4.5 page_launder() bug, I can't think 
of it at the moment.

Comment 1 Bill Nottingham 2001-06-26 14:19:59 UTC
It's orthangonal to this problem, but why isn't the nut initscript suitable
for your needs? If, even with that, code needs added to the halt script, something
is wrong with the nut package.

Comment 2 j. alan eldridge 2001-06-26 14:51:16 UTC
No, there's nothing wrong with the nut package. The code (that runs only when 
the UPS is on low battery, and we're going down for that reason) needs to be 
added at the end of "halt" because IT SHUTS THE POWER OFF!

Do you think that "service nut stop" should kill the power? I hope not ...

Here are the choices: 

1. Run it in /etc/rc.d/init.d/nut. So we'll just kill the power with all the 
filesystems mounted.

2. Add it to the end of halt. We'll kill the UPS power rather than the "normal" 
way of shutting the power off.

3. Do it after halt completes ... umm, wait, we're halted...

Comment 3 Bill Nottingham 2001-07-09 05:26:20 UTC
Fixed in CVS, will be in 6.00-1 or so. (I added the special case check for
halt/reboot/etc in the 'action|daemon' case.)

The grep is an ugly hack, but the only other way is a magic comment, which
is equally as ugly. (And since the grep has been in the release since 6.0
(or 6.1, I forget), people may be *expecting* this behavior.

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