Skip to content

Commit db0137c

Browse files
committed
feat: check if the running process is of the same user
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.
1 parent 861fee3 commit db0137c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

safeeyes/__main__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
def __running():
4141
"""Check if SafeEyes is already running."""
4242
process_count = 0
43+
current_user = psutil.Process().username()
4344
for proc in psutil.process_iter():
4445
if not proc.cmdline:
4546
continue
@@ -54,9 +55,10 @@ def __running():
5455
if ("python3" in cmd_line[0] or "python" in cmd_line[0]) and (
5556
"safeeyes" in cmd_line[1] or "safeeyes" in cmd_line
5657
):
57-
process_count += 1
58-
if process_count > 1:
59-
return True
58+
if proc.username() == current_user:
59+
process_count += 1
60+
if process_count > 1:
61+
return True
6062

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

0 commit comments

Comments
 (0)