Bug 970288

Summary: luci initscript does not check return values correctly
Product: Red Hat Enterprise Linux 5 Reporter: Jan Pokorný [poki] <jpokorny>
Component: congaAssignee: Jan Pokorný [poki] <jpokorny>
Status: CLOSED ERRATA QA Contact: Cluster QE <mspqa-list>
Severity: medium Docs Contact:
Priority: medium    
Version: 5.9CC: cluster-maint, fdinitto, jharriga, rsteiger
Target Milestone: rcKeywords: EasyFix
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: conga-0.12.2-70.el5 Doc Type: Bug Fix
Doc Text:
Cause: Improper return value check when stopping the luci service. Consequence: Luci reported as stopped even if, for some reason, it was not. Fix: Return value checked correctly when stopping the luci service. Result: Accurate diagnostics reported when stopping the luci service failed.
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-09-16 05:31:00 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jan Pokorný [poki] 2013-06-03 21:46:18 UTC
Reproducer could be something like this (untested)

# service luci start
# vim /etc/init.d/luci  # set LUCI_ZOPE_TIMEOUT=1
# <command to utilize the machine on 100% so luci stop is slow>&

Observed:

# service luci stop && pgrep -f luci
Shutting down luci:                                        [  OK  ]
31800

Expected:

# service luci stop && pgrep -f luci
Shutting down luci:                                        [ FAIL ]
31800
# grep '[lL]uci' /var/log/messages | tail -n1
[...] Luci did not stop after 1 seconds.

---

The issue is in bad handling of $? special variable in (1) the "if" inner
context and (2) the "while" outer context.  Bash man page says...

re (1):
> The exit status is the exit status of the last command executed, or zero if
> no condition tested true.

re (2):
> The exit status of the while and until commands is the exit status of the
> last do list command executed, or zero if none was executed.


Under this conditions, following snippet from stop function in luci
initscript:

> while [ $cur_wait -lt $max_wait ]; do
>         sleep 1
>         cur_wait=`expr $cur_wait + 1`
>         luci_running
>         if [ $? -eq 0 ]; then
>                 break
>         fi
> done

will always have, immediately after being executed, exit code of zero
and it makes no sense to use it in subsequent conditionals.

Action items:
a. fix stop function so that it works as per "Expected"
b. check the correctness of exit code handling in other parts of initscript

Comment 6 errata-xmlrpc 2014-09-16 05:31:00 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2014-1194.html