[PATCH 2/5] Fix the return value of vlog* functions when VERBOSE=no

Trek trek00 at inbox.ru
Tue Apr 26 22:48:11 BST 2022


To improve compatibility between the logging functions and the
vlog* ones, the return value should be consistent with their
counterparts, regardless of the VERBOSE value.

Each function will return 0 if VERBOSE=no, with the exception
of vlog_end_msg that will return the value of its first
argument, or 1 if not specified.
---
 conf/conf.yaml                    |  4 +++-
 init-functions                    |  5 +----
 init-functions.d/00-verbose.jinja | 11 +++++++++++
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/conf/conf.yaml b/conf/conf.yaml
index d1ac18b..f786704 100644
--- a/conf/conf.yaml
+++ b/conf/conf.yaml
@@ -1,7 +1,9 @@
 log_functions:
   - log_daemon_msg
   - log_begin_msg
-  - log_end_msg
   - log_action_msg
   - log_action_begin_msg
   - log_action_end_msg
+
+log_end_functions:
+  - log_end_msg
diff --git a/init-functions b/init-functions
index f2088b3..cd584d0 100644
--- a/init-functions
+++ b/init-functions
@@ -338,9 +338,6 @@ log_end_msg () {
         return 1
     fi
 
-    local retval
-    retval=$1
-
     log_end_msg_pre "$@"
 
     # Only do the fancy stuff if we have an appropriate terminal
@@ -361,7 +358,7 @@ log_end_msg () {
         echo " ${red}failed!${normal}" || true
     fi
     log_end_msg_post "$@"
-    return $retval
+    return $1
 }
 
 log_action_msg () {
diff --git a/init-functions.d/00-verbose.jinja b/init-functions.d/00-verbose.jinja
index c1af825..99d4a6c 100644
--- a/init-functions.d/00-verbose.jinja
+++ b/init-functions.d/00-verbose.jinja
@@ -3,6 +3,17 @@
 v{{ fn }}() {
 	if test x"${VERBOSE:-yes}" != x"no" ; then
 		{{ fn }} "$@"
+	else
+		true
+	fi
+}
+{% endfor %}
+{% for fn in log_end_functions %}
+v{{ fn }}() {
+	if test x"${VERBOSE:-yes}" != x"no" ; then
+		{{ fn }} "$@"
+	else
+		return ${1:-1}
 	fi
 }
 {% endfor %}
-- 
2.20.1



More information about the Debian-init-diversity mailing list