Safe-guard calls to echo with || true.
authorDidier Raboud <odyx@debian.org>
Tue, 22 May 2012 10:54:02 +0000 (12:54 +0200)
committerDidier Raboud <odyx@debian.org>
Tue, 22 May 2012 11:28:00 +0000 (13:28 +0200)
This helps towards making sure init.d scripts called with `set -e`
continue to work, see #661002.

In particular, this avoids blocking all init.d scripts run on a terminal
where civis and cnorm are capabilities not available, such as cmd.exe .

Thanks-to: Sam Hocevar <sho@debian.org>
init-functions
init-functions.d/20-left-info-blocks
init-functions.d/50-ubuntu-logging

index d6a65906f7e28334442ff265a1f1881d8f2a1744..d8a7e9855373e5c519b6dd469c0c112fe1bd7de4 100644 (file)
@@ -87,10 +87,10 @@ pidofproc () {
         read pid < "$pidfile"
         if [ -n "${pid:-}" ]; then
             if $(kill -0 "${pid:-}" 2> /dev/null); then
-                echo "$pid"
+                echo "$pid" || true
                 return 0
             elif ps "${pid:-}" >/dev/null 2>&1; then
-                echo "$pid"
+                echo "$pid" || true
                 return 0 # program is running, but not owned by this user
             else
                 return 1 # program is dead and /var/run pid file exists
@@ -276,7 +276,7 @@ log_begin_msg () {
     if [ -z "${1:-}" ]; then
         return 1
     fi
-    /bin/echo -n "$@"
+    /bin/echo -n "$@" || true
     log_begin_msg_post "$@"
 }
 
@@ -301,11 +301,11 @@ log_daemon_msg () {
     log_daemon_msg_pre "$@"
 
     if [ -z "${2:-}" ]; then
-        /bin/echo -n "$1:"
+        /bin/echo -n "$1:" || true
         return
     fi
     
-    /bin/echo -n "$1: $2"
+    /bin/echo -n "$1: $2" || true
     log_daemon_msg_post "$@"
 }
 
@@ -328,7 +328,7 @@ log_progress_msg () {
     if [ -z "${1:-}" ]; then
         return 1
     fi
-    /bin/echo -n " $@"
+    /bin/echo -n " $@" || true
 }
 
 
@@ -357,11 +357,11 @@ log_end_msg () {
     fi
 
     if [ $1 -eq 0 ]; then
-        echo "."
+        echo "." || true
     elif [ $1 -eq 255 ]; then
-        /bin/echo -e " ${YELLOW}(warning).${NORMAL}"
+        /bin/echo -e " ${YELLOW}(warning).${NORMAL}" || true
     else
-        /bin/echo -e " ${RED}failed!${NORMAL}"
+        /bin/echo -e " ${RED}failed!${NORMAL}" || true
     fi
     log_end_msg_post "$@"
     return $retval
@@ -369,18 +369,18 @@ log_end_msg () {
 
 log_action_msg () {
     log_action_msg_pre "$@"
-    echo "$@."
+    echo "$@." || true
     log_action_msg_post "$@"
 }
 
 log_action_begin_msg () {
     log_action_begin_msg_pre "$@"
-    /bin/echo -n "$@..."
+    /bin/echo -n "$@..." || true
     log_action_begin_msg_post "$@"
 }
 
 log_action_cont_msg () {
-    /bin/echo -n "$@..."
+    /bin/echo -n "$@..." || true
 }
 
 log_action_end_msg () {
@@ -393,14 +393,14 @@ log_action_end_msg () {
     fi
 
     if [ $1 -eq 0 ]; then
-        echo "done${end}"
+        echo "done${end}" || true
     else
         if log_use_fancy_output; then
             RED=$( $TPUT setaf 1)
             NORMAL=$( $TPUT op)
-            /bin/echo -e "${RED}failed${end}${NORMAL}"
+            /bin/echo -e "${RED}failed${end}${NORMAL}" || true
         else
-            echo "failed${end}"
+            echo "failed${end}" || true
         fi
     fi
     log_action_end_msg_post "$@"
index 39f6039f8efb651109e1d6afe68b80debab4c22e..9b9f3b17f653d80783c08c019ff971c01a67d939 100644 (file)
@@ -1,7 +1,7 @@
 # Default info blocks put to the left of the screen
 log_daemon_msg_pre () {
     if log_use_fancy_output; then
-        /bin/echo -n "[....] "
+        /bin/echo -n "[....] " || true
     fi
 }
 log_begin_msg_pre () {
@@ -14,25 +14,25 @@ log_end_msg_pre () {
         YELLOW=$( $TPUT setaf 3)
         NORMAL=$( $TPUT op)
 
-        $TPUT civis
-        $TPUT sc
-        $TPUT hpa 0
+        $TPUT civis || true
+        $TPUT sc && \
+        $TPUT hpa 0 && \
         if [ $1 -eq 0 ]; then
-            /bin/echo -ne "[${GREEN} ok ${NORMAL}"
+            /bin/echo -ne "[${GREEN} ok ${NORMAL}" || true
         elif [ $1 -eq 255 ]; then
-            /bin/echo -ne "[${YELLOW}warn${NORMAL}"
+            /bin/echo -ne "[${YELLOW}warn${NORMAL}" || true
         else
-            /bin/echo -ne "[${RED}FAIL${NORMAL}"
-        fi
-        $TPUT rc
-        $TPUT cnorm
+            /bin/echo -ne "[${RED}FAIL${NORMAL}" || true
+        fi && \
+        $TPUT rc || true
+        $TPUT cnorm || true
     fi
 }
 log_action_msg_pre () {
     if log_use_fancy_output; then
         CYAN=$( $TPUT setaf 6)
         NORMAL=$( $TPUT op)
-        /bin/echo -ne "[${CYAN}info${NORMAL}] "
+        /bin/echo -ne "[${CYAN}info${NORMAL}] " || true
     fi
 }
 log_action_begin_msg_pre () {
index ac223579cab0fd14939fe83c1ee06aa8dbfb22fe..4fdadcff53d198378f1c08409c7ce07a3cae6547 100644 (file)
@@ -10,16 +10,16 @@ log_use_plymouth () {
 }
 
 log_success_msg () {
-    echo " * $@"
+    echo " * $@" || true
 }
 
 log_failure_msg () {
     if log_use_fancy_output; then
         RED=`$TPUT setaf 1`
         NORMAL=`$TPUT op`
-        echo " $RED*$NORMAL $@"
+        echo " $RED*$NORMAL $@" || true
     else
-        echo " * $@"
+        echo " * $@" || true
     fi
 }
 
@@ -27,9 +27,9 @@ log_warning_msg () {
     if log_use_fancy_output; then
         YELLOW=`$TPUT setaf 3`
         NORMAL=`$TPUT op`
-        echo " $YELLOW*$NORMAL $@"
+        echo " $YELLOW*$NORMAL $@" || true
     else
-        echo " * $@"
+        echo " * $@" || true
     fi
 }
 
@@ -71,14 +71,14 @@ log_daemon_msg () {
         # and we won't be able to reliably know where the colourful
         # asterisk ought to go.
 
-        printf " * $*       "
+        printf " * $*       " || true
         # Enough trailing spaces for ` [fail]' to fit in; if the message
         # is too long it wraps here rather than later, which is what we
         # want.
-        $TPUT hpa `$EXPR $COLS - 1`
-        printf ' '
+        $TPUT hpa `$EXPR $COLS - 1` || true
+        printf ' ' || true
     else
-        echo " * $@"
+        echo " * $@" || true
         COL=
     fi
 }
@@ -102,37 +102,37 @@ log_end_msg () {
             fi
         fi
 
-        printf "\r"
+        printf "\r" || true
         $TPUT hpa $COL
         if [ "$1" -eq 0 ]; then
-            echo "[ OK ]"
+            echo "[ OK ]" || true
         else
-            printf '['
-            $TPUT setaf 1 # red
-            printf fail
-            $TPUT op # normal
-            echo ']'
+            printf '[' || true
+            $TPUT setaf 1 || true # red
+            printf fail || true
+            $TPUT op || true # normal
+            echo ']' || true
         fi
     else
         if [ "$1" -eq 0 ]; then
-            echo "   ...done."
+            echo "   ...done." || true
         else
-            echo "   ...fail!"
+            echo "   ...fail!" || true
         fi
     fi
     return $1
 }
 
 log_action_msg () {
-    echo " * $@"
+    echo " * $@" || true
 }
 
 log_action_begin_msg () {
-    log_daemon_msg "$@..."
+    log_daemon_msg "$@..." || true
 }
 
 log_action_cont_msg () {
-    log_daemon_msg "$@..."
+    log_daemon_msg "$@..." || true
 }
 
 log_action_end_msg () {