Commit e1b3431c authored by Martin Panter's avatar Martin Panter

Issue #22636: Handle OSError from subprocess, e.g. if command not found

parent bfb15ab7
...@@ -115,10 +115,13 @@ elif os.name == "posix": ...@@ -115,10 +115,13 @@ elif os.name == "posix":
env = dict(os.environ) env = dict(os.environ)
env['LC_ALL'] = 'C' env['LC_ALL'] = 'C'
env['LANG'] = 'C' env['LANG'] = 'C'
proc = subprocess.Popen(args, try:
stdout=subprocess.PIPE, proc = subprocess.Popen(args,
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
env=env) stderr=subprocess.STDOUT,
env=env)
except OSError: # E.g. bad executable
return None
with proc: with proc:
trace = proc.stdout.read() trace = proc.stdout.read()
finally: finally:
...@@ -140,9 +143,12 @@ elif os.name == "posix": ...@@ -140,9 +143,12 @@ elif os.name == "posix":
if not f: if not f:
return None return None
proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f), try:
stdout=subprocess.PIPE, proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
stderr=subprocess.DEVNULL) stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
except OSError: # E.g. command not found
return None
with proc: with proc:
data = proc.stdout.read() data = proc.stdout.read()
res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data) res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
...@@ -159,9 +165,12 @@ elif os.name == "posix": ...@@ -159,9 +165,12 @@ elif os.name == "posix":
# objdump is not available, give up # objdump is not available, give up
return None return None
proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f), try:
stdout=subprocess.PIPE, proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
stderr=subprocess.DEVNULL) stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
except OSError: # E.g. bad executable
return None
with proc: with proc:
dump = proc.stdout.read() dump = proc.stdout.read()
res = re.search(br'\sSONAME\s+([^\s]+)', dump) res = re.search(br'\sSONAME\s+([^\s]+)', dump)
...@@ -187,11 +196,15 @@ elif os.name == "posix": ...@@ -187,11 +196,15 @@ elif os.name == "posix":
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename) expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
expr = os.fsencode(expr) expr = os.fsencode(expr)
proc = subprocess.Popen(('/sbin/ldconfig', '-r'), try:
stdout=subprocess.PIPE, proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
stderr=subprocess.DEVNULL) stdout=subprocess.PIPE,
with proc: stderr=subprocess.DEVNULL)
data = proc.stdout.read() except OSError: # E.g. command not found
data = b''
else:
with proc:
data = proc.stdout.read()
res = re.findall(expr, data) res = re.findall(expr, data)
if not res: if not res:
...@@ -214,10 +227,13 @@ elif os.name == "posix": ...@@ -214,10 +227,13 @@ elif os.name == "posix":
args = ('/usr/bin/crle',) args = ('/usr/bin/crle',)
paths = None paths = None
proc = subprocess.Popen(args, try:
stdout=subprocess.PIPE, proc = subprocess.Popen(args,
stderr=subprocess.DEVNULL, stdout=subprocess.PIPE,
env=env) stderr=subprocess.DEVNULL,
env=env)
except OSError: # E.g. bad executable
return None
with proc: with proc:
for line in proc.stdout: for line in proc.stdout:
line = line.strip() line = line.strip()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment