瀏覽代碼

Merge pull request #5876 from ThomasWaldmann/find-libc-1.1

implement BORG_LIBC env variable, fixes #5870
TW 4 年之前
父節點
當前提交
40bd891aef
共有 2 個文件被更改,包括 13 次插入8 次删除
  1. 5 0
      docs/usage/general/environment.rst.inc
  2. 8 8
      src/borg/xattr.py

+ 5 - 0
docs/usage/general/environment.rst.inc

@@ -68,6 +68,11 @@ General:
         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.
+    BORG_LIBC
+        borg uses ``ctypes.util.find_library`` to locate the 'c' library (aka libc).
+        find_library needs a shell and will invoke some tools like ldconfig, gcc/cc or objdump.
+        If a shell or these tools are not available, you can give the name of your libc via
+        BORG_LIBC=libc.so.6 (for example) and borg will not try the ``find_library`` call.
     BORG_SELFTEST
         This can be used to influence borg's builtin self-tests. The default is to execute the tests
         at the beginning of each borg command invocation.

+ 8 - 8
src/borg/xattr.py

@@ -62,21 +62,22 @@ def get_all(path, follow_symlinks=True):
             return {}
 
 
-libc_name = find_library('c')
+HINT_MSG = "Try installing ldconfig, gcc/cc or objdump or use BORG_LIBC."
+LIBC_NOT_FOUND_NO_FALLBACK_MSG = "Can't find C library. No fallback known. " + HINT_MSG
+LIBC_NOT_FOUND_FNAME_MSG = "Can't find C library [%s]. " + HINT_MSG
+
+libc_name = os.environ.get('BORG_LIBC') or find_library('c')
 if libc_name is None:
     # find_library didn't work, maybe we are on some minimal system that misses essential
     # tools used by find_library, like ldconfig, gcc/cc, objdump.
     # so we can only try some "usual" names for the C library:
     if sys.platform.startswith('linux'):
         libc_name = 'libc.so.6'
-    elif sys.platform.startswith(('freebsd', 'netbsd')):
-        libc_name = 'libc.so'
     elif sys.platform == 'darwin':
         libc_name = 'libc.dylib'
     else:
-        msg = "Can't find C library. No fallback known. Try installing ldconfig, gcc/cc or objdump."
-        print(msg, file=sys.stderr)  # logger isn't initialized at this stage
-        raise Exception(msg)
+        print(LIBC_NOT_FOUND_NO_FALLBACK_MSG, file=sys.stderr)  # logger isn't initialized at this stage
+        raise Exception(LIBC_NOT_FOUND_NO_FALLBACK_MSG)
 
 # If we are running with fakeroot on Linux, then use the xattr functions of fakeroot. This is needed by
 # the 'test_extract_capabilities' test, but also allows xattrs to work with fakeroot on Linux in normal use.
@@ -102,8 +103,7 @@ if sys.platform.startswith('linux'):
 try:
     libc = CDLL(libc_name, use_errno=True)
 except OSError as e:
-    msg = "Can't find C library [%s]. Try installing ldconfig, gcc/cc or objdump." % e
-    raise Exception(msg)
+    raise Exception(LIBC_NOT_FOUND_FNAME_MSG % e)
 
 
 def split_string0(buf):