Description of problem: The /lib/lsb/init-functions file (both on Fedora Core 4 and RedHat EL 4) uses alias to attempt to set up lsb init script support functions such as log_success_msg and log_failure_msg. Unfortunately, /lib/lsb/init-functions wrongly uses alias for this purpose, despite the fact that neither Bash (http://www.gnu.org/software/bash/manual/bashref.html#SEC79) nor the Posix standard (see http://www.opengroup.org/onlinepubs/009695399/utilities/alias.html) shell by default will expand aliases during non-interactive shell script processing. The /lib/lsb/init-functions file needs to be rewritten to define the commands as true shell functions, and not aliases. Version-Release number of selected component (if applicable): redhat-lsb-1.3-10 How reproducible: Try running the /etc/init.d/xendomains script from the xen-3.0-0.20050912.fc4 RPM for Fedora Core 4. See it fail with a log_success_msg command not found. Steps to Reproduce: 1. Install Xen for Fedora Core 4 using the instructions at http://www.fedoraproject.org/wiki/FedoraXenQuickstart 2. Try to run /etc/init.d/xendomains start 3. See it fail with a log_success_msg command not found error on line 50. Actual results: log_success_msg not found. Expected results: correct invocation of the /etc/init.d/functions success function. Additional info:
Created attachment 120073 [details] Corrected version of /etc/init.d/init-functions This version of init-functions correctly operates in LSB-using /etc/init.d scripts.
Note: this bug is essentially identical to what was reported in bug 158183. However, I believe that bug was closed incorrectly. In that bug report, the reporter was doing a simple #!/bin/bash . /lib/lsb/init-functions log_success_msg "hi matt" log_failure_msg "hi matt" log_warning_msg "hi matt" and experiencing the failure. The reporter determined that changing this to #!/bin/sh . /lib/lsb/init-functions log_success_msg "hi matt" log_failure_msg "hi matt" log_warning_msg "hi matt" rendered the script working. In my case, with the Xen xendomains file, the shell script is more complicated. It actually looks like this: ---------------8< start -------------- #!/bin/sh # # /etc/init.d/xendomains # Start / stop domains automatically when domain 0 boots / shuts down. # # chkconfig: 345 99 00 # description: Start / stop Xen domains. # # This script offers fairly basic functionality. It should work on Redhat # but also on LSB-compliant SuSE releases and on Debian with the LSB package # installed. (LSB is the Linux Standard Base) # # Based on the example in the "Designing High Quality Integrated Linux # Applications HOWTO" by Avi Alkalay # <http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/> # ### BEGIN INIT INFO # Provides: xendomains # Required-Start: $syslog $remote_fs xend # Should-Start: # Required-Stop: $syslog $remote_fs xend # Should-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: Start/stop secondary xen domains # Description: Start / stop domains automatically when domain 0 # boots / shuts down. ### END INIT INFO if ! [ -e /proc/xen/privcmd ]; then exit 0 fi RETVAL=0 INITD=/etc/init.d AUTODIR=/etc/xen/auto LOCKFILE=/var/lock/subsys/xendomains if [ -e /lib/lsb ]; then # assume an LSB-compliant distro (Debian with LSB package, # recent-enough SuSE, others...) . /lib/lsb/init-functions.jon # source LSB standard functions on_fn_exit() { if [ $RETVAL -eq 0 ]; then log_success_msg else log_failure_msg fi } elif [ -r $INITD/functions ]; then # assume a Redhat-like distro . $INITD/functions # source Redhat functions on_fn_exit() { if [ $RETVAL -eq 0 ]; then success else failure fi echo } else # none of the above LOCKFILE=/var/lock/xendomains on_fn_exit() { echo } fi start() { if [ -f $LOCKFILE ]; then return; fi echo -n $"Starting auto Xen domains:" # We expect config scripts for auto starting domains to be in # AUTODIR - they could just be symlinks to files elsewhere if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then touch $LOCKFILE # Create all domains with config files in AUTODIR. for dom in $AUTODIR/*; do xm create --quiet --defconfig $dom if [ $? -ne 0 ]; then RETVAL=$? fi done fi on_fn_exit } stop() { # NB. this shuts down ALL Xen domains (politely), not just the ones in # AUTODIR/* # This is because it's easier to do ;-) but arguably if this script is run # on system shutdown then it's also the right thing to do. echo -n $"Shutting down all Xen domains:" xm shutdown --all --wait --halt RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $LOCKFILE on_fn_exit } # This does NOT necessarily restart all running domains: instead it # stops all running domains and then boots all the domains specified in # AUTODIR. If other domains have been started manually then they will # not get restarted. # Commented out to avoid confusion! # #restart() #{ # stop # start #} # same as restart for now - commented out to avoid confusion #reload() #{ # restart #} case "$1" in start) start ;; stop) stop ;; # The following are commented out to disable them by default to avoid confusion # - see the notes above # # restart) # restart # ;; # # reload) # reload # ;; status) xm list ;; *) echo $"Usage: $0 {start|stop|status}" ;; esac exit $RETVAL ---------------8< end ---------------- in this case, the LSB functions are meant to be used within a subsequent shell function definition. This completely fails when /lib/lsb/init-functions is constructed out of alias statements, but it works properly when init-functions is made up of shell functions. Given the general fragility of using aliases in non-interactive Bash and Sh scripts, I would argue that init-functions needs to use proper Shell functions, rather than aliasing, even if simple test cases happen to work with /bin/sh. Note that I'm using the standard Fedora Core 4 bash RPM for all of this, bash-3.0-31.
Ah, of course that . /lib/lsb/init-functions.jon was originally . /lib/lsb/init-functions The init-functions.jon file is my version with shell functions defined, and it actually works just great.
See bug 171056 for my related bug on the xen subsystem.
Still present in FC5.
It's been a year, now. Any way to get this issue moved out of 'NEW'?
This bug is still present in Fedora Core 6.
It's been four years now. And this bug also causes issues with the integration of the JPackage tomcat6 with RHEL 4, which I've recently had to deal with professionally. But isn't this fixed more simply by using "#!/bin/sh" instead of "#!/bin/bash" in init scripts? Is there any reason to use bash's subtler implementations for init scripts?