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.
This commit is contained in:
Thomas Waldmann 2020-06-30 00:11:12 +02:00
parent 5b5bd9f7f2
commit e0545e921d
2 changed files with 7 additions and 4 deletions

View File

@ -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)

View File

@ -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