Skip to content

Commit

Permalink
feat: check if the running process is of the same user
Browse files Browse the repository at this point in the history
When running SafeEyes in multi-user environments (multiple users running
SafeEyes in the same machine), it refuses to start more than two
instances of SafeEyes because it is already running accoding to ps.

This patch adds a check to the running SafeEyes pid such that the
_running() function returns True only if it is running as the same user.
  • Loading branch information
sudoAlphaX committed Feb 21, 2025
1 parent 6349949 commit 2c8be0c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions safeeyes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __running():
Check if SafeEyes is already running.
"""
process_count = 0
current_user = psutil.Process().username()
for proc in psutil.process_iter():
if not proc.cmdline:
continue
Expand All @@ -53,9 +54,10 @@ def __running():
# In older versions cmdline was a list object
cmd_line = proc.cmdline
if ('python3' in cmd_line[0] or 'python' in cmd_line[0]) and ('safeeyes' in cmd_line[1] or 'safeeyes' in cmd_line):
process_count += 1
if process_count > 1:
return True
if proc.username() == current_user:
process_count += 1
if process_count > 1:
return True

# Ignore if process does not exist or does not have command line args
except (IndexError, psutil.NoSuchProcess):
Expand Down

0 comments on commit 2c8be0c

Please sign in to comment.