From: Russ Allbery Date: Tue, 1 Jun 2010 17:40:41 +0000 (-0700) Subject: Except init.d scripts from the normal set -e requirement X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=054029abead4996f10c2a97bf431db0bd95de44c;p=debian%2Fdebian-policy.git Except init.d scripts from the normal set -e requirement Mention init.d scripts as a special exception from the normal advise to always use set -e in all shell scripts, and add a new paragraph to the section on init.d scripts advising caution in using set -e and explaining some of the issues. --- diff --git a/policy.sgml b/policy.sgml index d16df70..1871d4c 100644 --- a/policy.sgml +++ b/policy.sgml @@ -6011,7 +6011,7 @@ rmdir /usr/local/share/emacs 2>/dev/null || true

- + Writing the scripts

@@ -6061,6 +6061,23 @@ rmdir /usr/local/share/emacs 2>/dev/null || true option.

+

+ Be careful of using set -e in init.d + scripts. Writing correct init.d scripts requires + accepting various error exit statuses when daemons are already + running or already stopped without aborting + the init.d script, and common init.d + function libraries are not safe to call with set -e + in effect + /lib/lsb/init-functions, which assists in writing + LSB-compliant init scripts, may fail if set -e is + in effect and echoing status messages to the console fails, + for example. + . For init.d scripts, it's often easier + to not use set -e and instead check the result of + each command separately. +

+

If a service reloads its configuration automatically (as in the case of cron, for example), the @@ -7158,13 +7175,19 @@ strip --strip-unneeded your-lib language currently used to implement it.

- Shell scripts (sh and bash) - should almost certainly start with set -e so that - errors are detected. Every script should use - set -e or check the exit status of every - command. + Shell scripts (sh and bash) other than + init.d scripts should almost certainly start + with set -e so that errors are detected. + init.d scripts are something of a special case, due + to how frequently they need to call commands that are allowed to + fail, and it may instead be easier to check the exit status of + commands directly. See for more + information about writing init.d scripts. +

+

+ Every script should use set -e or check the exit status + of every command.

-

Scripts may assume that /bin/sh implements the SUSv3 Shell Command Language