From: Didier Raboud Date: Tue, 22 May 2012 10:54:02 +0000 (+0200) Subject: Safe-guard calls to echo with || true. X-Git-Tag: archive/raspbian/10.2018112800+rpi1^2~120 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6c5b3ff6e324a17e9c982e319a34e1a214257ea6;p=lsb.git Safe-guard calls to echo with || true. 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 --- diff --git a/init-functions b/init-functions index d6a6590..d8a7e98 100644 --- a/init-functions +++ b/init-functions @@ -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 "$@" diff --git a/init-functions.d/20-left-info-blocks b/init-functions.d/20-left-info-blocks index 39f6039..9b9f3b1 100644 --- a/init-functions.d/20-left-info-blocks +++ b/init-functions.d/20-left-info-blocks @@ -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 () { diff --git a/init-functions.d/50-ubuntu-logging b/init-functions.d/50-ubuntu-logging index ac22357..4fdadcf 100644 --- a/init-functions.d/50-ubuntu-logging +++ b/init-functions.d/50-ubuntu-logging @@ -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 () {