From 4d3ec28046f4d5d0b9fb8b24c1235c6e369b8837 Mon Sep 17 00:00:00 2001 From: ThePrez Date: Fri, 22 Nov 2019 15:14:35 -0600 Subject: [PATCH] fix IBM i 'missing libc' failure (#2195) allow gunicorn on IBM i (and AIX) platform with Python 3.6 and earlier --- gunicorn/socketfromfd.py | 13 +++++++++++-- gunicorn/util.py | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gunicorn/socketfromfd.py b/gunicorn/socketfromfd.py index 74f6503d..71b40d3c 100644 --- a/gunicorn/socketfromfd.py +++ b/gunicorn/socketfromfd.py @@ -20,10 +20,18 @@ SO_DOMAIN = getattr(socket, 'SO_DOMAIN', 39) SO_TYPE = getattr(socket, 'SO_TYPE', 3) SO_PROTOCOL = getattr(socket, 'SO_PROTOCOL', 38) - _libc_name = find_library('c') if _libc_name is not None: - libc = ctypes.CDLL(_libc_name, use_errno=True) + if sys.platform.startswith("aix"): + member = ( + '(shr_64.o)' if ctypes.sizeof(ctypes.c_voidp) == 8 else '(shr.o)') + # 0x00040000 correspondes to RTLD_MEMBER, undefined in Python <= 3.6 + dlopen_mode = (ctypes.DEFAULT_MODE | 0x00040000 | os.RTLD_NOW) + libc = ctypes.CDLL(_libc_name+member, + use_errno=True, + mode=dlopen_mode) + else: + libc = ctypes.CDLL(_libc_name, use_errno=True) else: raise OSError('libc not found') @@ -36,6 +44,7 @@ def _errcheck_errno(result, func, arguments): raise OSError(errno, os.strerror(errno)) return arguments + if platform.system() == 'SunOS': _libc_getsockopt = libc._so_getsockopt else: diff --git a/gunicorn/util.py b/gunicorn/util.py index 0cf5e751..3c72d9fc 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -659,9 +659,9 @@ def _findWalk_ldpath(name): if _is_elf(f): return os.path.basename(f) prefix = os.path.join(d, 'lib'+name) - for suffix in ['so', 'so.*', '*.so.*']: + for suffix in ['so', 'so.*', '*.so.*', 'a']: for f in glob('{0}.{1}'.format(prefix, suffix)): - if _is_elf(f): + if _is_elf(f) or suffix == 'a': return os.path.basename(f)