Bug 240978

Summary: the init script should be more careful about exit code
Product: [Fedora] Fedora Reporter: Stepan Kasal <kasal>
Component: nfs-utilsAssignee: Steve Dickson <steved>
Status: CLOSED INSUFFICIENT_DATA QA Contact: Ben Levenson <benl>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: triage
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard: bzcl34nup
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-05-06 21:47:29 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Attachments:
Description Flags
a proposed patch none

Description Stepan Kasal 2007-05-23 11:09:19 EDT
Scriptc /etc/rc.d/init.d/{nfs,nfslock} contain constructs like:
        [ -f /var/lock/subsys/nfs ] && {
                $0 stop
                $0 start
        }

But this construct is dangerous, because if /var/lock/sybsys/nfs does not exist,
then the whole compound command has a non-zero exit code.
The subsequent "exit $?" propagates the exit code, so it seems that the
condrestart failed.

It is always safer to use `if' in this case.  If the condition is false, the
exit code of the whole `if' compound command is 0, which is more adequate in
this situation. See also
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_04_07

Attached please find a patch which fixes (at least part of) the problem.
Comment 1 Stepan Kasal 2007-05-23 11:09:20 EDT
Created attachment 155256 [details]
a proposed patch
Comment 2 Stepan Kasal 2007-05-23 11:11:18 EDT
Let me note that this report is not purely theoretical, it was triggered by a
real-life problem, filed as bug #240979.
Comment 3 Stepan Kasal 2007-05-23 11:46:12 EDT
Another solution is to replace the final "exit $?" by "exit $RETVAL".
Buty please note that this change was done in FC-6 branch only, not in F-7 nor
devel.
And please note that with "exit $RETVAL", the exit code for "service nfs
restart" and "sevice nfs condrestart" is _always_ 0, because RETVAL is not set
in these cases.

So it still seems that the init scripts need a thorough review.
(I admit that my patch attached to this bug is far from complete.)
Comment 4 Bug Zapper 2008-04-03 20:51:20 EDT
Based on the date this bug was created, it appears to have been reported
against rawhide during the development of a Fedora release that is no
longer maintained. In order to refocus our efforts as a project we are
flagging all of the open bugs for releases which are no longer
maintained. If this bug remains in NEEDINFO thirty (30) days from now,
we will automatically close it.

If you can reproduce this bug in a maintained Fedora version (7, 8, or
rawhide), please change this bug to the respective version and change
the status to ASSIGNED. (If you're unable to change the bug's version
or status, add a comment to the bug and someone will change it for you.)

Thanks for your help, and we apologize again that we haven't handled
these issues to this point.

The process we're following is outlined here:
http://fedoraproject.org/wiki/BugZappers/F9CleanUp

We will be following the process here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping to ensure this
doesn't happen again.
Comment 5 Bug Zapper 2008-05-06 21:47:28 EDT
This bug has been in NEEDINFO for more than 30 days since feedback was
first requested. As a result we are closing it.

If you can reproduce this bug in the future against a maintained Fedora
version please feel free to reopen it against that version.

The process we're following is outlined here:
http://fedoraproject.org/wiki/BugZappers/F9CleanUp