Open rstech209 opened 2 years ago
Thanks for reporting this... will need to look into a workaround if the one you proposed is problematic... need to think though the full pattern match.
I think I have found a solution that meets the following constraints:
pgrep/pkill -x -u "$user" "$PSNAME"
'GeckoMain'
=> how to differentiate Firefox and Librewolf for example?BROWSERS=firefox
a) leafpad firefox_text
running => psd does not start if you match the command line only.
b) librewolf
running => psd does not start believing it is firefox (do not rely solely on the name of the process 'GeckoMain'
)
c) firefox + librewolf
running => 2 GeckoMain processes, but only one should be considered as running because BROWSERS=firefox
d) For 2 simultaneous firefox
processes running (possible with 2 different versions of firefox) => take into account the 2 GeckoMain processes I created a new function:
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
}
Other functions running_check ()
and kill_browsers ()
become
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
running_browser_pid
if [[ -n "$PSNAME_PID" ]]; then
echo "Refusing to start; $browser is running by $user!"
exit 1
fi
done
}
kill_browsers() {
# check for browsers running and kill them to safely sync/unsync
# without this cannot guarantee profile integrity
local browser
for browser in "${BROWSERS[@]}"; do
load_env_for "$browser"
local x=1
while [[ $x -le 60 ]]; do
[[ -n "$PSNAME" ]] || break
running_browser_pid
[[ -n "$PSNAME_PID" ]] || break
if [[ $x -le 5 ]]; then
kill -SIGTERM "${PSNAME_PID//$'\n'/' '}"
else
kill -SIGKILL "${PSNAME_PID//$'\n'/' '}"
fi
x=$(( x + 1 ))
sleep .05
done
done
}
Accidentally closed
First of all, thanks for this software.
With Firefox 94.0 (and since version 93.0?) pgrep and pkill are not executed in the profile-sync-daemon script. (pgrep error code = 1)
Functions concerned:
pgrep takes into account the first 15 characters of
/proc/<firefox_pid>/stat
which is:GeckoMain
See Note in man pgrep/pkill:Using the -f option, the detection of a firefox process is OK
This is probably not a good solution, but it's OK after replacing in the main script /usr/bin/profile-sync-daemon:
pgrep/pkill -x -u "$user" "$PSNAME"
bypgrep/pkill -u "$user" -f "$PSNAME"
!!!Warning!!! : in this case all the processes and sub-processes containing the word 'firefox' in their command line will be taken into account for detection (
running_check ()
) and stopped (kill_browsers ()
).