Bug 50241 - /etc/init.d/functions has fragile default-setting of variables
Summary: /etc/init.d/functions has fragile default-setting of variables
Alias: None
Product: Fedora
Classification: Fedora
Component: initscripts   
(Show other bugs)
Version: rawhide
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact: Brock Organ
Depends On:
TreeView+ depends on / blocked
Reported: 2001-07-28 23:17 UTC by dkk
Modified: 2014-03-17 02:22 UTC (History)
1 user (show)

Fixed In Version: 8.31.5-1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-07-09 03:02:02 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description dkk 2001-07-28 23:17:14 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.16-22 i686)

Description of problem:
When an initscript starts with ``#!/bin/bash'' it may well involve user
(e.g. via $BASH_ENV).  Bash has an option ("set -u" or "set -o nounset")
causes the shell to treat unset variables as an error.  This can cause init
scripts to
fail for some users.  You can make "functions" more robust by replacing
lines like
this: ``[ -z "$COLUMNS" ] && COLUMNS=80''
with lines like this: ``${COLUMNS:=80}''

The effect should be the same, and would allow those of us who like to use
bash with
the "nounset" option to keep doing so without tripping over init script
failures.  Some
such init scripts are atd, gpm, halt, netfs and sshd.

How reproducible:

Steps to Reproduce:
1. log in as root
2. append "set -o nounset" to ~/.bashrc
3. try `/etc/init.d/sshd status`

Actual Results:  The sshd init script bombed out (exit value 1) with:

  /etc/init.d/sshd: COLUMNS: unbound variable

That error comes from the following line in "functions", which is
dot-sourced by the
sshd init script:

  [ -z "$COLUMNS" ] && COLUMNS=80

Expected Results:  The sshd init script should have told me the status of
the sshd service,
rather than exiting with a non-zero value.

Additional info:

My first thought was that init scripts should stick to /bin/sh rather than
but concluded that "functions" is the appropriate place for the fix.  Init
scripts have
valid reasons to use bash functions instead of minimal sh capabilities, and
will always be people you don't know about writing init scripts.

Comment 1 Miloslav Trmač 2006-07-09 03:02:02 UTC
This should be fixed in FC5, at least for init.d/functions.  Thanks for your

Note You need to log in before you can comment on or make changes to this bug.