[PATCH] make iwhd's startup script report failure reliably

Jim Meyering jim at meyering.net
Fri Sep 16 14:14:50 UTC 2011


Pete Zaitcev wrote:
> On Wed, 14 Sep 2011 16:26:31 +0200
> Jim Meyering <jim at meyering.net> wrote:
>
>> As for propagating from each branch of the "case" statement,
>> we can let the shell help us there.  Simply exiting with "$?"
>> makes the script do the right thing.  No need to set RETVAL
>> in each branch of the case statement.
>
> Right, this works, thanks.

I tested it, added a NEWS entry, and pushed this:

>From af161e18fbf58669ba1d6dca6de20fd211bd4b76 Mon Sep 17 00:00:00 2001
From: Pete Zaitcev <zaitcev at redhat.com>
Date: Wed, 14 Sep 2011 16:22:47 +0200
Subject: [PATCH] make iwhd's startup script report failure reliably

iwhd's startup script would mistakenly exit successfully even
though it failed, e.g., because it failed to find a usable
instance of Mongo.
* iwhd.init.in (start, stop): Return success indicator.
(main): Propagate success/failure from case stmt to script "exit".
* NEWS (Bug fixes): Mention it.
---
 NEWS         |    5 +++++
 iwhd.init.in |    7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index c827c0e..be681f9 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,11 @@ iwhd NEWS                                                   -*- outline -*-

 ** Bug fixes

+  iwhd's /etc/init.d startup script now reports failure reliably, for
+  example when failing to start because no MongoDB server is running.
+  Before it would print [FAILED], but mistakenly exit 0 (successful).
+  Now it exits with status 1.
+
   Adapt to a slight variation in the status report of a template import
   action in RHEV-M 2.x.

diff --git a/iwhd.init.in b/iwhd.init.in
index 306fcf7..9a7d9b6 100644
--- a/iwhd.init.in
+++ b/iwhd.init.in
@@ -89,6 +89,7 @@ start() {
         failure
     fi
     echo
+    return $RETVAL
 }

 stop() {
@@ -99,6 +100,7 @@ stop() {
         rm -f $PIDFILE
         rm -rf @localstatedir@/cache/iwhd/*
     fi
+    return $RETVAL
 }

 restart() {
@@ -122,7 +124,6 @@ case "$1" in
         ;;
     status)
         status -p $PIDFILE $PROCESS
-        RETVAL=$?
         ;;
     force-reload)
         reload
@@ -135,4 +136,6 @@ case "$1" in
         exit 2
         ;;
 esac
-exit $RETVAL
+
+# Exit with the result of the "case" statement.
+exit $?
--
1.7.7.rc0.362.g5a14


More information about the iwhd-devel mailing list