From e0545e921d9f454a2e5f841079e0734eb2a6f5ed Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 30 Jun 2020 00:11:12 +0200 Subject: [PATCH] exit with 128 + signal number, fixes #5161 as documented: https://borgbackup.readthedocs.io/en/stable/usage/general.html#return-codes compatibility warning: in case you have scripts expecting rc == 2 for a signal exit, you need to update them to check for >= 128. --- src/borg/archiver.py | 10 ++++++---- src/borg/constants.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 6dcef8da7..321089e02 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -45,7 +45,7 @@ try: from .compress import CompressionSpec from .crypto.key import key_creator, key_argument_names, tam_required_file, tam_required, RepoKey, PassphraseKey from .crypto.keymanager import KeyManager - from .helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR + from .helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR, EXIT_SIGNAL_BASE from .helpers import Error, NoManifestError, set_ec from .helpers import positive_int_validator, location_validator, archivename_validator, ChunkerParams, Location from .helpers import PrefixSpec, GlobSpec, CommentSpec, SortBySpec, FilesCacheMode @@ -4644,17 +4644,17 @@ def main(): # pragma: no cover msg = 'Keyboard interrupt' tb_log_level = logging.DEBUG tb = '%s\n%s' % (traceback.format_exc(), sysinfo()) - exit_code = EXIT_ERROR + exit_code = EXIT_SIGNAL_BASE + 2 except SigTerm: msg = 'Received SIGTERM' msgid = 'Signal.SIGTERM' tb_log_level = logging.DEBUG tb = '%s\n%s' % (traceback.format_exc(), sysinfo()) - exit_code = EXIT_ERROR + exit_code = EXIT_SIGNAL_BASE + 15 except SigHup: msg = 'Received SIGHUP.' msgid = 'Signal.SIGHUP' - exit_code = EXIT_ERROR + exit_code = EXIT_SIGNAL_BASE + 1 if msg: logger.error(msg, msgid=msgid) if tb: @@ -4668,6 +4668,8 @@ def main(): # pragma: no cover rc_logger.warning(exit_msg % ('warning', exit_code)) elif exit_code == EXIT_ERROR: rc_logger.error(exit_msg % ('error', exit_code)) + elif exit_code >= EXIT_SIGNAL_BASE: + rc_logger.error(exit_msg % ('signal', exit_code)) else: rc_logger.error(exit_msg % ('abnormal', exit_code or 666)) sys.exit(exit_code) diff --git a/src/borg/constants.py b/src/borg/constants.py index a2eff43fa..b265ec6bd 100644 --- a/src/borg/constants.py +++ b/src/borg/constants.py @@ -80,6 +80,7 @@ DEFAULT_FILES_CACHE_MODE = 'cis' # == CacheMode(DEFAULT_FILES_CACHE_MODE_UI) EXIT_SUCCESS = 0 # everything done, no problems EXIT_WARNING = 1 # reached normal end of operation, but there were issues EXIT_ERROR = 2 # terminated abruptly, did not reach end of operation +EXIT_SIGNAL_BASE = 128 # terminated due to signal, rc = 128 + sig_no # never use datetime.isoformat(), it is evil. always use one of these: # datetime.strftime(ISO_FORMAT) # output always includes .microseconds