From 2c8be0c21dd2d929cbdcda57d36f730e17a8c217 Mon Sep 17 00:00:00 2001 From: Alpha <43486986+sudoAlphaX@users.noreply.github.com> Date: Fri, 21 Feb 2025 12:47:37 +0530 Subject: [PATCH] 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. --- safeeyes/__main__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/safeeyes/__main__.py b/safeeyes/__main__.py index 71234544..d5b430d8 100755 --- a/safeeyes/__main__.py +++ b/safeeyes/__main__.py @@ -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 @@ -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):