1From d321df349d10f038f0c89b9c11f8059572264f1b Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= <mail@nh2.me>
3Date: Sat, 13 May 2017 18:54:36 +0200
4Subject: [PATCH] python: Remove all uses of find_library. Fixes #1450593
5
6`find_library()` doesn't consider LD_LIBRARY_PATH on Python < 3.6.
7---
8 api/examples/getvolfile.py | 2 +-
9 geo-replication/syncdaemon/libcxattr.py | 3 +--
10 geo-replication/syncdaemon/libgfchangelog.py | 3 +--
11 tests/features/ipctest.py | 10 ++--------
12 tests/utils/libcxattr.py | 5 ++---
13 tools/glusterfind/src/libgfchangelog.py | 3 +--
14 .../features/changelog/lib/examples/python/libgfchangelog.py | 3 +--
15 7 files changed, 9 insertions(+), 20 deletions(-)
16
17diff --git a/api/examples/getvolfile.py b/api/examples/getvolfile.py
18index 0c95213..32c2268 100755
19--- a/api/examples/getvolfile.py
20+++ b/api/examples/getvolfile.py
21@@ -3,7 +3,7 @@
22 import ctypes
23 import ctypes.util
24
25-api = ctypes.CDLL(ctypes.util.find_library("gfapi"))
26+api = ctypes.CDLL("libgfapi.so")
27 api.glfs_get_volfile.argtypes = [ctypes.c_void_p,
28 ctypes.c_void_p,
29 ctypes.c_ulong]
30diff --git a/geo-replication/syncdaemon/libcxattr.py b/geo-replication/syncdaemon/libcxattr.py
31index 3671e10..f576648 100644
32--- a/geo-replication/syncdaemon/libcxattr.py
33+++ b/geo-replication/syncdaemon/libcxattr.py
34@@ -10,7 +10,6 @@
35
36 import os
37 from ctypes import CDLL, create_string_buffer, get_errno
38-from ctypes.util import find_library
39
40
41 class Xattr(object):
42@@ -25,7 +24,7 @@ class Xattr(object):
43 sizes we expect
44 """
45
46- libc = CDLL(find_library("c"), use_errno=True)
47+ libc = CDLL("libc.so.6", use_errno=True)
48
49 @classmethod
50 def geterrno(cls):
51diff --git a/geo-replication/syncdaemon/libgfchangelog.py b/geo-replication/syncdaemon/libgfchangelog.py
52index d87b56c..003c28c 100644
53--- a/geo-replication/syncdaemon/libgfchangelog.py
54+++ b/geo-replication/syncdaemon/libgfchangelog.py
55@@ -10,12 +10,11 @@
56
57 import os
58 from ctypes import CDLL, RTLD_GLOBAL, create_string_buffer, get_errno, byref, c_ulong
59-from ctypes.util import find_library
60 from syncdutils import ChangelogException, ChangelogHistoryNotAvailable
61
62
63 class Changes(object):
64- libgfc = CDLL(find_library("gfchangelog"), mode=RTLD_GLOBAL, use_errno=True)
65+ libgfc = CDLL("libgfchangelog.so", mode=RTLD_GLOBAL, use_errno=True)
66
67 @classmethod
68 def geterrno(cls):
69diff --git a/tests/features/ipctest.py b/tests/features/ipctest.py
70index 5aff319..9339248 100755
71--- a/tests/features/ipctest.py
72+++ b/tests/features/ipctest.py
73@@ -1,14 +1,8 @@
74 #!/usr/bin/python
75
76 import ctypes
77-import ctypes.util
78-
79-# find_library does not lookup LD_LIBRARY_PATH and may miss the
80-# function. In that case, retry with less portable but explicit name.
81-libgfapi = ctypes.util.find_library("gfapi")
82-if libgfapi == None:
83- libgfapi = "libgfapi.so"
84-api = ctypes.CDLL(libgfapi,mode=ctypes.RTLD_GLOBAL)
85+
86+api = ctypes.CDLL("libgfapi.so",mode=ctypes.RTLD_GLOBAL)
87
88 api.glfs_ipc.argtypes = [ ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p ]
89 api.glfs_ipc.restype = ctypes.c_int
90diff --git a/tests/utils/libcxattr.py b/tests/utils/libcxattr.py
91index 149db72..4e6e6c4 100644
92--- a/tests/utils/libcxattr.py
93+++ b/tests/utils/libcxattr.py
94@@ -11,7 +11,6 @@
95 import os
96 import sys
97 from ctypes import CDLL, c_int, create_string_buffer
98-from ctypes.util import find_library
99
100
101 class Xattr(object):
102@@ -28,9 +27,9 @@ class Xattr(object):
103
104 if sys.hexversion >= 0x02060000:
105 from ctypes import DEFAULT_MODE
106- libc = CDLL(find_library("libc"), DEFAULT_MODE, None, True)
107+ libc = CDLL("libc.so.6", DEFAULT_MODE, None, True)
108 else:
109- libc = CDLL(find_library("libc"))
110+ libc = CDLL("libc.so.6")
111
112 @classmethod
113 def geterrno(cls):
114diff --git a/tools/glusterfind/src/libgfchangelog.py b/tools/glusterfind/src/libgfchangelog.py
115index dd8153e..da822cf 100644
116--- a/tools/glusterfind/src/libgfchangelog.py
117+++ b/tools/glusterfind/src/libgfchangelog.py
118@@ -12,14 +12,13 @@
119 import os
120 from ctypes import CDLL, get_errno, create_string_buffer, c_ulong, byref
121 from ctypes import RTLD_GLOBAL
122-from ctypes.util import find_library
123
124
125 class ChangelogException(OSError):
126 pass
127
128
129-libgfc = CDLL(find_library("gfchangelog"), use_errno=True, mode=RTLD_GLOBAL)
130+libgfc = CDLL("libgfchangelog.so", use_errno=True, mode=RTLD_GLOBAL)
131
132
133 def raise_oserr():
134diff --git a/xlators/features/changelog/lib/examples/python/libgfchangelog.py b/xlators/features/changelog/lib/examples/python/libgfchangelog.py
135index 10e73c0..2cdbf11 100644
136--- a/xlators/features/changelog/lib/examples/python/libgfchangelog.py
137+++ b/xlators/features/changelog/lib/examples/python/libgfchangelog.py
138@@ -1,9 +1,8 @@
139 import os
140 from ctypes import *
141-from ctypes.util import find_library
142
143 class Changes(object):
144- libgfc = CDLL(find_library("gfchangelog"), mode=RTLD_GLOBAL, use_errno=True)
145+ libgfc = CDLL("libgfchangelog.so", mode=RTLD_GLOBAL, use_errno=True)
146
147 @classmethod
148 def geterrno(cls):
149--
1502.7.4
151