[libvirt] [PATCH 1/2] libvirtd.init: improve portability

Jim Meyering jim at meyering.net
Wed Apr 14 16:24:24 UTC 2010


Eric Blake wrote:
> This patch kills translation of the daemon messages, but being a
> daemon, the messages probably didn't need translation in the first
> place.  Other alternatives would be to make the script require
>
> * daemon/libvirtd.init.in (start, stop, reload): Drop bash-ism of
> $"".  Use printf instead of echo -n.

IMHO, converting "echo -n" to printf is the way to go,
if for no other reason than to set a proper example.

However, you might want to keep the $"" for now, if only to remain
consistent with the majority of other Fedora /etc/init.d/* scripts.
On an F13 system I just checked, those that use that idiom outnumber
the others more than 2-to-1:

    $ grep -l '\$"Startin' /etc/init.d/* |wc -l
    59
    $ grep -L '\$"Startin' /etc/init.d/* |wc -l
    24

> Just as 'echo -e' is non-portable, so is 'echo -n'.  Plus, $"" and
> #!/bin/sh don't mix.  Any opinions on the issue of translating the
> output of the libvirt daemon, or is this patch okay as-is?
>
>  daemon/libvirtd.init.in |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/daemon/libvirtd.init.in b/daemon/libvirtd.init.in
> index 4c8821b..22f3305 100644
> --- a/daemon/libvirtd.init.in
> +++ b/daemon/libvirtd.init.in
> @@ -54,7 +54,7 @@ fi
>  RETVAL=0
>
>  start() {
> -    echo -n $"Starting $SERVICE daemon: "
> +    printf "Starting $SERVICE daemon: "
>      mkdir -p @localstatedir@/cache/libvirt
>      rm -rf @localstatedir@/cache/libvirt/*
>      KRB5_KTNAME=$KRB5_KTNAME daemon --pidfile $PIDFILE --check $SERVICE $PROCESS --daemon $LIBVIRTD_CONFIG_ARGS $LIBVIRTD_ARGS
> @@ -64,7 +64,7 @@ start() {
>  }
>
>  stop() {
> -    echo -n $"Stopping $SERVICE daemon: "
> +    printf "Stopping $SERVICE daemon: "
>
>      killproc -p $PIDFILE $PROCESS
>      RETVAL=$?
> @@ -82,7 +82,7 @@ restart() {
>  }
>
>  reload() {
> -    echo -n $"Reloading $SERVICE configuration: "
> +    printf "Reloading $SERVICE configuration: "
>
>      killproc -p $PIDFILE $PROCESS -HUP
>      RETVAL=$?
> @@ -106,7 +106,7 @@ case "$1" in
>          [ -f @localstatedir@/lock/subsys/$SERVICE ] && restart || :
>          ;;
>      *)
> -        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload|try-restart}"
> +        echo "Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload|try-restart}"
>  	exit 2
>          ;;
>  esac




More information about the libvir-list mailing list