Skip to content

Commit

Permalink
Avoid deadlock when calling subprocess.Popen(), ignore terminated bor…
Browse files Browse the repository at this point in the history
…g processes when finding mount points. Fixes borgbase#187
  • Loading branch information
m3nu committed Feb 16, 2019
1 parent 1eb4959 commit 440ffd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/vorta/borg/borg_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 17 additions & 16 deletions src/vorta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,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)
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:]
if name == 'borg' or name.startswith('python'):
if 'mount' not in proc.cmdline():
continue

# 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
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

return mount_points

0 comments on commit 440ffd2

Please sign in to comment.