Merge pull request #109 from warner/2023-caution
Avoid Popen() of executables that don't exist
This commit is contained in:
commit
d91170a7ac
|
@ -106,24 +106,25 @@ def get_linux_distro():
|
||||||
if _distname and _version:
|
if _distname and _version:
|
||||||
return (_distname, _version)
|
return (_distname, _version)
|
||||||
|
|
||||||
try:
|
if os.path.isfile("/usr/bin/lsb_release") or os.path.isfile("/bin/lsb_release"):
|
||||||
p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
try:
|
||||||
rc = p.wait()
|
p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
if rc == 0:
|
rc = p.wait()
|
||||||
for line in p.stdout.readlines():
|
if rc == 0:
|
||||||
m = _distributor_id_cmdline_re.search(line)
|
for line in p.stdout.readlines():
|
||||||
if m:
|
m = _distributor_id_cmdline_re.search(line)
|
||||||
_distname = m.group(1).strip()
|
if m:
|
||||||
if _distname and _version:
|
_distname = m.group(1).strip()
|
||||||
return (_distname, _version)
|
if _distname and _version:
|
||||||
|
return (_distname, _version)
|
||||||
|
|
||||||
m = _release_cmdline_re.search(p.stdout.read())
|
m = _release_cmdline_re.search(p.stdout.read())
|
||||||
if m:
|
if m:
|
||||||
_version = m.group(1).strip()
|
_version = m.group(1).strip()
|
||||||
if _distname and _version:
|
if _distname and _version:
|
||||||
return (_distname, _version)
|
return (_distname, _version)
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if os.path.exists("/etc/arch-release"):
|
if os.path.exists("/etc/arch-release"):
|
||||||
return ("Arch_Linux", "")
|
return ("Arch_Linux", "")
|
||||||
|
|
|
@ -130,6 +130,7 @@ class ListAddresses(testutil.SignalMixin, unittest.TestCase):
|
||||||
e.errno = errno.ENOENT
|
e.errno = errno.ENOENT
|
||||||
raise e
|
raise e
|
||||||
self.patch(subprocess, 'Popen', call_Popen)
|
self.patch(subprocess, 'Popen', call_Popen)
|
||||||
|
self.patch(os.path, 'isfile', lambda x: True)
|
||||||
|
|
||||||
def call_get_local_ip_for(target):
|
def call_get_local_ip_for(target):
|
||||||
if target in ("localhost", "127.0.0.1"):
|
if target in ("localhost", "127.0.0.1"):
|
||||||
|
|
|
@ -190,6 +190,8 @@ def _synchronously_find_addresses_via_config():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _query(path, args, regex):
|
def _query(path, args, regex):
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
return []
|
||||||
env = {'LANG': 'en_US.UTF-8'}
|
env = {'LANG': 'en_US.UTF-8'}
|
||||||
TRIES = 5
|
TRIES = 5
|
||||||
for trial in xrange(TRIES):
|
for trial in xrange(TRIES):
|
||||||
|
|
Loading…
Reference in New Issue