Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd305e4

Browse files
committed
Issue #22636: Merge ctypes.util from 3.5
2 parents ed80db5 + e1b3431 commit bd305e4

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

Lib/ctypes/util.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ def _findLib_gcc(name):
115115
env = dict(os.environ)
116116
env['LC_ALL'] = 'C'
117117
env['LANG'] = 'C'
118-
proc = subprocess.Popen(args,
119-
stdout=subprocess.PIPE,
120-
stderr=subprocess.STDOUT,
121-
env=env)
118+
try:
119+
proc = subprocess.Popen(args,
120+
stdout=subprocess.PIPE,
121+
stderr=subprocess.STDOUT,
122+
env=env)
123+
except OSError: # E.g. bad executable
124+
return None
122125
with proc:
123126
trace = proc.stdout.read()
124127
finally:
@@ -140,9 +143,12 @@ def _get_soname(f):
140143
if not f:
141144
return None
142145

143-
proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
144-
stdout=subprocess.PIPE,
145-
stderr=subprocess.DEVNULL)
146+
try:
147+
proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
148+
stdout=subprocess.PIPE,
149+
stderr=subprocess.DEVNULL)
150+
except OSError: # E.g. command not found
151+
return None
146152
with proc:
147153
data = proc.stdout.read()
148154
res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
@@ -159,9 +165,12 @@ def _get_soname(f):
159165
# objdump is not available, give up
160166
return None
161167

162-
proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
163-
stdout=subprocess.PIPE,
164-
stderr=subprocess.DEVNULL)
168+
try:
169+
proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
170+
stdout=subprocess.PIPE,
171+
stderr=subprocess.DEVNULL)
172+
except OSError: # E.g. bad executable
173+
return None
165174
with proc:
166175
dump = proc.stdout.read()
167176
res = re.search(br'\sSONAME\s+([^\s]+)', dump)
@@ -187,11 +196,15 @@ def find_library(name):
187196
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
188197
expr = os.fsencode(expr)
189198

190-
proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
191-
stdout=subprocess.PIPE,
192-
stderr=subprocess.DEVNULL)
193-
with proc:
194-
data = proc.stdout.read()
199+
try:
200+
proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
201+
stdout=subprocess.PIPE,
202+
stderr=subprocess.DEVNULL)
203+
except OSError: # E.g. command not found
204+
data = b''
205+
else:
206+
with proc:
207+
data = proc.stdout.read()
195208

196209
res = re.findall(expr, data)
197210
if not res:
@@ -214,10 +227,13 @@ def _findLib_crle(name, is64):
214227
args = ('/usr/bin/crle',)
215228

216229
paths = None
217-
proc = subprocess.Popen(args,
218-
stdout=subprocess.PIPE,
219-
stderr=subprocess.DEVNULL,
220-
env=env)
230+
try:
231+
proc = subprocess.Popen(args,
232+
stdout=subprocess.PIPE,
233+
stderr=subprocess.DEVNULL,
234+
env=env)
235+
except OSError: # E.g. bad executable
236+
return None
221237
with proc:
222238
for line in proc.stdout:
223239
line = line.strip()

0 commit comments

Comments
 (0)