[PATCH 3/9] init-d-script: policy compliant exit values
Trek
trek00 at inbox.ru
Fri Aug 28 07:21:16 BST 2020
Init-script actions must return 0 on success or when nothing
was done, 1 on unspecified errors, 2 on invalid arguments and
3 on unimplemented feature, as required by LSB Core generic 5.0
chapter 22.2 and Debian Policy Manual 4.5.0.2 chapter 9.3.2.
The do_start_cmd and do_stop_cmd override functions are allowed
to return the same error set of start-stop-daemon, that is 0 on
success, 1 when nothing was done, 2 on timeout and 3 on other
errors.
With this patch it should return the right error code when
the override functions return 1 or the cleanup functions are
implemented. Furthermore try-restart returns 0 if the process
is not running, restart returns 1 if it cannot be stopped and
do_reload_sigusr1 returns 1 on errors or if not running.
---
debian/init-d-script | 43 ++++++++++++++++++-------------------------
1 file changed, 18 insertions(+), 25 deletions(-)
diff --git a/debian/init-d-script b/debian/init-d-script
index 21be2804..4c038aee 100755
--- a/debian/init-d-script
+++ b/debian/init-d-script
@@ -57,16 +57,12 @@ do_start()
fi
log_daemon_msg "Starting $DESC" "$NAME"
call do_start_cmd
- retval=$?
- case ${retval} in
- 0|1) vlog_end_msg 0 ;;
- 2) vlog_end_msg 1 ;;
- esac
+ retval=$(( $? > 1 ))
+ vlog_end_msg $retval
if is_call_implemented do_start_cleanup ; then
call do_start_cleanup
- else
- return ${retval}
fi
+ return $retval
}
#
@@ -103,16 +99,12 @@ do_stop()
fi
vlog_daemon_msg "Stopping $DESC" "$NAME"
call do_stop_cmd
- retval=$?
- case ${retval} in
- 0|1) vlog_end_msg 0 ;;
- 2) vlog_end_msg 1 ;;
- esac
+ retval=$(( $? > 1 ))
+ vlog_end_msg $retval
if is_call_implemented do_stop_cleanup ; then
call do_stop_cleanup
- else
- return ${retval}
fi
+ return $retval
}
do_restart() {
@@ -121,17 +113,16 @@ do_restart() {
fi
vlog_daemon_msg "Restarting $DESC" "$NAME"
call do_stop_cmd
- call do_start_cmd
- retval=$?
- case ${retval} in
- 0|1) vlog_end_msg 0 ;;
- 2) vlog_end_msg 1 ;;
- esac
+ retval=$(( $? > 1 ))
+ if [ $retval -eq 0 ] ; then
+ call do_start_cmd
+ retval=$(( $? > 1 ))
+ fi
+ vlog_end_msg $retval
if is_call_implemented do_restart_cleanup ; then
call do_restart_cleanup
- else
- return ${retval}
fi
+ return $retval
}
do_force_reload() {
@@ -149,13 +140,15 @@ do_reload_sigusr1() {
call do_reload_prepare
fi
log_daemon_msg "Reloading $DESC configuration files" "$NAME"
- start-stop-daemon --oknodo --stop --signal 1 --quiet \
+ start-stop-daemon --stop --signal 1 --quiet \
${PIDFILE:+--pidfile "$PIDFILE"} \
${DAEMON:+--exec "$DAEMON"}
- log_end_msg $?
+ retval=$(( $? != 0 ))
+ log_end_msg $retval
if is_call_implemented do_reload_cleanup ; then
call do_reload_cleanup
fi
+ return $retval
}
do_status() {
@@ -240,7 +233,7 @@ case "$1" in
log_end_msg $?
else
log_progress_msg "is not running."
- log_end_msg 1
+ log_end_msg 0
fi
;;
'')
--
2.20.1
More information about the Debian-init-diversity
mailing list