Skip to content

Commit

Permalink
cmdline/daemon: make sure found pid is from this user
Browse files Browse the repository at this point in the history
the pid of the stale process could be recycled as the daemon of someone else
  • Loading branch information
dev-zero committed Jul 21, 2021
1 parent 2d51386 commit 057c8a5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions aiida/cmdline/utils/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ class StartCircusNotFound(Exception):
if pid is not None:
try:
process = psutil.Process(pid)
# the PID got recycled, but a different process
if _START_CIRCUS_COMMAND not in process.cmdline():
raise StartCircusNotFound() # Also this is a case in which the process is not there anymore

# the PID got recycled, but for a daemon of someone else
if process.username() != psutil.Process().username(): # compare against the username of this interpreter
raise StartCircusNotFound()
except (psutil.AccessDenied, psutil.NoSuchProcess, StartCircusNotFound):
echo.echo_warning(
f'Deleted apparently stale daemon PID file as its associated process<{pid}> does not exist anymore'
Expand Down

0 comments on commit 057c8a5

Please sign in to comment.