Bug#710571: Patch for /lib/lsb/init-functions
The attached git patch makes the log_* functions in
/lib/lsb/init-functions check $VERBOSE before outputting anything.
- Josh Triplett
>From b9280a56114591c73fef9899e01aee6cf9d4a78b Mon Sep 17 00:00:00 2001
From: Josh Triplett <josh@joshtriplett.org>
Date: Fri, 31 May 2013 16:38:21 -0700
Subject: [PATCH] init-functions: Check $VERBOSE before generating output from
log_*
This avoids the need for init scripts to check $VERBOSE before every
invocation of these functions (which they sometimes forget to do, and
which requires sourcing the internal-use-only /lib/init/vars.sh).
Furthermore, eliminating such checks will eventually allow init systems
and output multiplexers to count on unconditional invocations of log_*,
so that they can always collect log data and decide what to do with it.
---
init-functions | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/init-functions b/init-functions
index cb8874c..36de2f5 100644
--- a/init-functions
+++ b/init-functions
@@ -27,6 +27,9 @@
#OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
#EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+VERBOSE=$([ -f /lib/init/vars.sh ] && . /lib/init/vars.sh >/dev/null 2>&1 && echo $VERBOSE)
+: ${VERBOSE:=no}
+
start_daemon () {
local force nice pidfile exec args OPTIND
force=""
@@ -276,10 +279,13 @@ init_is_upstart()
# int log_begin_message (char *message)
log_begin_msg () {
- log_begin_msg_pre "$@"
if [ -z "${1:-}" ]; then
return 1
fi
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
+ log_begin_msg_pre "$@"
echo -n "$@" || true
log_begin_msg_post "$@"
}
@@ -302,6 +308,9 @@ log_daemon_msg () {
if [ -z "${1:-}" ]; then
return 1
fi
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
log_daemon_msg_pre "$@"
if [ -z "${2:-}" ]; then
@@ -332,6 +341,9 @@ log_progress_msg () {
if [ -z "${1:-}" ]; then
return 1
fi
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
echo -n " $@" || true
}
@@ -342,6 +354,9 @@ log_end_msg () {
if [ -z "${1:-}" ]; then
return 1
fi
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
local retval
retval=$1
@@ -372,22 +387,34 @@ log_end_msg () {
}
log_action_msg () {
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
log_action_msg_pre "$@"
echo "$@." || true
log_action_msg_post "$@"
}
log_action_begin_msg () {
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
log_action_begin_msg_pre "$@"
echo -n "$@..." || true
log_action_begin_msg_post "$@"
}
log_action_cont_msg () {
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
echo -n "$@..." || true
}
log_action_end_msg () {
+ if [ "$VERBOSE" = no ]; then
+ return 0
+ fi
local end
log_action_end_msg_pre "$@"
if [ -z "${2:-}" ]; then
--
1.7.10.4
Reply to: