From 30bd78f2664e0fe41dd87d733b618a5413278080 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 29 Mar 2018 16:45:37 +0200 Subject: [PATCH 1/2] remove platform.uname() call, fixes #3732 also: add exception handler around deprecated platform.linux_distribution() call. (cherry picked from commit 1e94211bf5166cc68a8073aff62e61fb31117f10) (cherry picked from commit 4f45eb660a469d7ab6d92a35ac83f41b34a5f8af) --- src/borg/helpers/misc.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/borg/helpers/misc.py b/src/borg/helpers/misc.py index b0fbb203e..a2579f5b9 100644 --- a/src/borg/helpers/misc.py +++ b/src/borg/helpers/misc.py @@ -61,11 +61,28 @@ def prune_split(archives, rule, n, kept_because=None): def sysinfo(): - info = [] - info.append('Platform: %s' % (' '.join(platform.uname()), )) + python_implementation = platform.python_implementation() + python_version = platform.python_version() + # platform.uname() does a shell call internally to get processor info, + # creating #3732 issue, so rather use os.uname(). + try: + uname = os.uname() + except AttributeError: + uname = None if sys.platform.startswith('linux'): - info.append('Linux: %s %s %s' % platform.linux_distribution()) - info.append('Borg: %s Python: %s %s' % (borg_version, platform.python_implementation(), platform.python_version())) + try: + linux_distribution = platform.linux_distribution() + except: + # platform.linux_distribution() is deprecated since py 3.5 and removed in 3.7. + linux_distribution = ('Unknown Linux', '', '') + else: + linux_distribution = None + info = [] + if uname is not None: + info.append('Platform: %s' % (' '.join(uname), )) + if linux_distribution is not None: + info.append('Linux: %s %s %s' % linux_distribution) + info.append('Borg: %s Python: %s %s' % (borg_version, python_implementation, python_version)) info.append('PID: %d CWD: %s' % (os.getpid(), os.getcwd())) info.append('sys.argv: %r' % sys.argv) info.append('SSH_ORIGINAL_COMMAND: %r' % os.environ.get('SSH_ORIGINAL_COMMAND')) From d94bd2274030cd9f5b83b37ced61a1eb2dd698b3 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 29 Mar 2018 23:45:01 +0200 Subject: [PATCH 2/2] BORG_SHOW_SYSINFO=no to hide system information from exceptions Can be used: - in case of troubles with the sysinfo code - by borg backup providers who do not want to show system information (cherry picked from commit 64aaec662805fecadbd0108d8840945982a73808) --- docs/usage_general.rst.inc | 4 ++++ src/borg/helpers/misc.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/usage_general.rst.inc b/docs/usage_general.rst.inc index fa16bf841..b343e18a0 100644 --- a/docs/usage_general.rst.inc +++ b/docs/usage_general.rst.inc @@ -197,6 +197,10 @@ General: When set to a numeric value, this determines the maximum "time to live" for the files cache entries (default: 20). The files cache is used to quickly determine whether a file is unchanged. The FAQ explains this more detailed in: :ref:`always_chunking` + BORG_SHOW_SYSINFO + When set to no (default: yes), system information (like OS, Python version, ...) in + exceptions is not shown. + Please only use for good reasons as it makes issues harder to analyze. TMPDIR where temporary files are stored (might need a lot of temporary space for some operations) diff --git a/src/borg/helpers/misc.py b/src/borg/helpers/misc.py index a2579f5b9..97576966e 100644 --- a/src/borg/helpers/misc.py +++ b/src/borg/helpers/misc.py @@ -61,6 +61,10 @@ def prune_split(archives, rule, n, kept_because=None): def sysinfo(): + show_sysinfo = os.environ.get('BORG_SHOW_SYSINFO', 'yes').lower() + if show_sysinfo == 'no': + return '' + python_implementation = platform.python_implementation() python_version = platform.python_version() # platform.uname() does a shell call internally to get processor info,