mirror of
https://github.com/borgbase/vorta
synced 2025-02-22 14:20:41 +00:00
Avoid deadlock when calling subprocess.Popen(), ignore terminated borg processes when finding mount points. Fixes #187
This commit is contained in:
parent
304ac3b90e
commit
b23cdf9851
2 changed files with 18 additions and 17 deletions
|
@ -143,7 +143,7 @@ def run(self):
|
|||
logger.info('Running command %s', ' '.join(self.cmd))
|
||||
|
||||
p = Popen(self.cmd, stdout=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True,
|
||||
env=self.env, cwd=self.cwd, preexec_fn=os.setsid)
|
||||
env=self.env, cwd=self.cwd, start_new_session=True)
|
||||
self.process = p
|
||||
|
||||
# Prevent blocking of stdout/err. Via https://stackoverflow.com/a/7730201/3983708
|
||||
|
|
|
@ -243,22 +243,23 @@ def get_mount_points(repo_url):
|
|||
for proc in psutil.process_iter():
|
||||
try:
|
||||
name = proc.name()
|
||||
except Exception:
|
||||
# Getting the process name may fail (e.g. zombie process on macOS)
|
||||
if name == 'borg' or name.startswith('python'):
|
||||
if 'mount' not in proc.cmdline():
|
||||
continue
|
||||
|
||||
for idx, parameter in enumerate(proc.cmdline()):
|
||||
if parameter.startswith(repo_url + '::'):
|
||||
archive_name = parameter[len(repo_url) + 2:]
|
||||
|
||||
# The borg mount command specifies that the mount_point
|
||||
# parameter comes after the archive name
|
||||
if len(proc.cmdline()) > idx + 1:
|
||||
mount_point = proc.cmdline()[idx + 1]
|
||||
mount_points[archive_name] = mount_point
|
||||
break
|
||||
except psutil._exceptions.ZombieProcess:
|
||||
# Getting process details may fail (e.g. zombie process on macOS)
|
||||
# Also see https://github.com/giampaolo/psutil/issues/783
|
||||
continue
|
||||
if name == 'borg' or name.startswith('python'):
|
||||
if 'mount' not in proc.cmdline():
|
||||
continue
|
||||
|
||||
for idx, parameter in enumerate(proc.cmdline()):
|
||||
if parameter.startswith(repo_url + '::'):
|
||||
archive_name = parameter[len(repo_url) + 2:]
|
||||
|
||||
# The borg mount command specifies that the mount_point
|
||||
# parameter comes after the archive name
|
||||
if len(proc.cmdline()) > idx + 1:
|
||||
mount_point = proc.cmdline()[idx + 1]
|
||||
mount_points[archive_name] = mount_point
|
||||
break
|
||||
|
||||
return mount_points
|
||||
|
|
Loading…
Reference in a new issue