graysky2 / profile-sync-daemon

Symlinks and syncs browser profile dirs to RAM thus reducing HDD/SDD calls and speeding-up browsers.

Home Page:https://wiki.archlinux.org/index.php/Profile-sync-daemon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running Firefox 94.0 not detected at startup

rstech209 opened this issue · comments

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:

running_check ()
kill_browsers ()

pgrep takes into account the first 15 characters of /proc/<firefox_pid>/stat which is: GeckoMain
See Note in man pgrep/pkill:

"Note: The process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat.
Use the -f option to match against the complete command line, /proc/pid/cmdline. "

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" by pgrep/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 ()).

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:

  • In the standard case, the commands currently used are correct pgrep/pkill -x -u "$user" "$PSNAME"
  • For Firefox, Librewolf (or other?), do not use the command line pattern only: 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 ()).
  • Do not rely solely on the process name 'GeckoMain' => how to differentiate Firefox and Librewolf for example?
  • Case scenario: psd configured with 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

PR #316 fix the problem