Bug 171052
| Summary: | /lib/lsb/init-functions erroneously uses 'alias' to define lsb compatible init functions | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Fedora] Fedora | Reporter: | Jonathan Abbey <jonabbey> | ||||
| Component: | redhat-lsb | Assignee: | Lawrence Lim <llim> | ||||
| Status: | CLOSED RAWHIDE | QA Contact: | |||||
| Severity: | medium | Docs Contact: | |||||
| Priority: | medium | ||||||
| Version: | 6 | CC: | nkadel, pcormier, tools-bugs | ||||
| Target Milestone: | --- | ||||||
| Target Release: | --- | ||||||
| Hardware: | All | ||||||
| OS: | Linux | ||||||
| Whiteboard: | |||||||
| Fixed In Version: | redhat-lsb-3.1-12.2 | Doc Type: | Bug Fix | ||||
| Doc Text: | Story Points: | --- | |||||
| Clone Of: | Environment: | ||||||
| Last Closed: | 2006-12-10 10:14:47 UTC | Type: | --- | ||||
| Regression: | --- | Mount Type: | --- | ||||
| Documentation: | --- | CRM: | |||||
| Verified Versions: | Category: | --- | |||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||
| Embargoed: | |||||||
| Attachments: |
|
||||||
|
Description
Jonathan Abbey
2005-10-17 18:36:55 UTC
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? |