Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix-#310-running-Firefox-94.0-detection #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions common/profile-sync-daemon.in
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,32 @@ load_env_for() {
. "$SHAREDIR/browsers/$browser"
}

running_browser_pid() {
local pid_list geckomain_pid

PSNAME_PID="$(pgrep -x -u "$user" "$PSNAME")"
# needed for browser using a process name different than application name
# e.g. GeckoMain for firefox or librewolf
if [[ -z "$PSNAME_PID" ]]; then
pid_list="$(pgrep -u "$user" -f "$PSNAME")"
if [[ -n "$pid_list" ]]; then
geckomain_pid="$(ps h -C GeckoMain -o pid:1)"
if [[ -n "$geckomain_pid" ]]; then
PSNAME_PID="$( grep "$geckomain_pid" <<< "$pid_list" )"
fi
fi
fi
}

running_check() {
# check for browsers running and refuse to start if so
# without this cannot guarantee profile integrity
local browser
for browser in "${BROWSERS[@]}"; do
load_env_for "$browser"
[[ -z "$PSNAME" ]] && continue
if pgrep -x -u "$user" "$PSNAME" &>/dev/null; then
running_browser_pid
if [[ -n "$PSNAME_PID" ]]; then
echo "Refusing to start; $browser is running by $user!"
exit 1
fi
Expand Down Expand Up @@ -433,12 +451,13 @@ kill_browsers() {
local x=1
while [[ $x -le 60 ]]; do
[[ -n "$PSNAME" ]] || break
pgrep -x -u "$user" "$PSNAME" &>/dev/null || break
running_browser_pid
[[ -n "$PSNAME_PID" ]] || break

if [[ $x -le 5 ]]; then
pkill -x -SIGTERM -u "$user" "$PSNAME"
kill -SIGTERM "${PSNAME_PID//$'\n'/' '}"
else
pkill -x -SIGKILL -u "$user" "$PSNAME"
kill -SIGKILL "${PSNAME_PID//$'\n'/' '}"
fi

x=$(( x + 1 ))
Expand Down