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

Running Firefox 94.0 not detected at startup #310

Open
rstech209 opened this issue Nov 21, 2021 · 4 comments
Open

Running Firefox 94.0 not detected at startup #310

rstech209 opened this issue Nov 21, 2021 · 4 comments

Comments

@rstech209
Copy link

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 ()).

@graysky2
Copy link
Owner

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.

@rstech209
Copy link
Author

rstech209 commented Nov 29, 2021

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
}

@rstech209 rstech209 reopened this Nov 29, 2021
@rstech209
Copy link
Author

Accidentally closed

@rstech209
Copy link
Author

PR #316 fix the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants