Merge pull request #2189 from yarikoptic/bf-initd-exit

debian-initd: exit with non-0 if fail, account that 255 is "Ok" exit code, use 255 explicitly instead of -1
pull/2215/head
Sergey G. Brester 2018-09-06 13:54:16 +02:00 committed by GitHub
commit 5b0c3e75d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 12 deletions

View File

@ -69,7 +69,7 @@ class Fail2banClient(Fail2banCmdLine, Thread):
# Print a new line because we probably come from wait # Print a new line because we probably come from wait
output("") output("")
logSys.warning("Caught signal %d. Exiting" % signum) logSys.warning("Caught signal %d. Exiting" % signum)
exit(-1) exit(255)
def __ping(self, timeout=0.1): def __ping(self, timeout=0.1):
return self.__processCmd([["ping"] + ([timeout] if timeout != -1 else [])], return self.__processCmd([["ping"] + ([timeout] if timeout != -1 else [])],
@ -500,5 +500,5 @@ def exec_command_line(argv):
if client.start(argv): if client.start(argv):
exit(0) exit(0)
else: else:
exit(-1) exit(255)

View File

@ -668,7 +668,7 @@ def exec_command_line(*args):
if errors: if errors:
sys.stderr.write("\n".join(errors) + "\n\n") sys.stderr.write("\n".join(errors) + "\n\n")
parser.print_help() parser.print_help()
sys.exit(-1) sys.exit(255)
output( "" ) output( "" )
output( "Running tests" ) output( "Running tests" )
@ -696,4 +696,4 @@ def exec_command_line(*args):
fail2banRegex = Fail2banRegex(opts) fail2banRegex = Fail2banRegex(opts)
if not fail2banRegex.start(args): if not fail2banRegex.start(args):
sys.exit(-1) sys.exit(255)

View File

@ -212,7 +212,7 @@ class Fail2banServer(Fail2banCmdLine):
if not phase.get('done', False): if not phase.get('done', False):
if server: # pragma: no cover if server: # pragma: no cover
server.quit() server.quit()
exit(-1) exit(255)
if background: if background:
logSys.debug('Starting server done') logSys.debug('Starting server done')
@ -223,7 +223,7 @@ class Fail2banServer(Fail2banCmdLine):
logSys.error(e) logSys.error(e)
if server: # pragma: no cover if server: # pragma: no cover
server.quit() server.quit()
exit(-1) exit(255)
return True return True
@ -238,4 +238,4 @@ def exec_command_line(argv):
if server.start(argv): if server.start(argv):
exit(0) exit(0)
else: else:
exit(-1) exit(255)

View File

@ -581,7 +581,7 @@ class Fail2banClientTest(Fail2banClientServerBase):
# test reload missing jail (direct): # test reload missing jail (direct):
self.execCmd(FAILED, startparams, "reload", "~~unknown~jail~fail~~") self.execCmd(FAILED, startparams, "reload", "~~unknown~jail~fail~~")
self.assertLogged("Failed during configuration: No section: '~~unknown~jail~fail~~'") self.assertLogged("Failed during configuration: No section: '~~unknown~jail~fail~~'")
self.assertLogged("Exit with code -1") self.assertLogged("Exit with code 255")
self.pruneLog() self.pruneLog()
finally: finally:
self.pruneLog() self.pruneLog()

View File

@ -180,10 +180,17 @@ do_reload() {
# #
log_end_msg_wrapper() log_end_msg_wrapper()
{ {
if [ $1 != 0 ] && [ $1 != $2 ]; then
value=1
else
value=0
fi
if [ "$3" != "no" ]; then if [ "$3" != "no" ]; then
[ $1 -lt $2 ] && value=0 || value=1
log_end_msg $value log_end_msg $value
fi fi
if [ $value != "0" ]; then
exit $1
fi
} }
command="$1" command="$1"
@ -191,13 +198,13 @@ case "$command" in
start|force-start) start|force-start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start "$command" do_start "$command"
log_end_msg_wrapper $? 2 "$VERBOSE" log_end_msg_wrapper $? 255 "$VERBOSE"
;; ;;
stop) stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop do_stop
log_end_msg_wrapper $? 2 "$VERBOSE" log_end_msg_wrapper $? 255 "$VERBOSE"
;; ;;
restart|force-reload) restart|force-reload)
@ -206,7 +213,7 @@ case "$command" in
case "$?" in case "$?" in
0|1) 0|1)
do_start do_start
log_end_msg_wrapper $? 1 "always" log_end_msg_wrapper $? 0 "always"
;; ;;
*) *)
# Failed to stop # Failed to stop