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

Terminate custom module scripts on exit #1032

Merged
merged 1 commit into from
Feb 23, 2021
Merged

Terminate custom module scripts on exit #1032

merged 1 commit into from
Feb 23, 2021

Conversation

matteodelabre
Copy link
Contributor

@matteodelabre matteodelabre commented Feb 12, 2021

(Fixes #358.)

Subprocesses created for custom module scripts were previously left running when the parent Waybar process exited. This patch sets the parent-death signal of child processes (PR_SET_PDEATHSIG on Linux, PROC_PDEATHSIG_CTL on FreeBSD) to SIGTERM.

Caveats:

  • This uses Linux-specific or FreeBSD-specific calls. I don’t know if this project targets other systems?
  • There is a possibility that Waybar exits after calling fork(), but before calling prctl to set the parent-death signal. In this case, the child will not receive the SIGTERM signal and will continue to run. I did not handle this case as I consider it quite unlikely, since module scripts are usually launched only when Waybar starts. Please let me know if you think it needs to be handled.

Testing:

  • With htop open, run Waybar v0.9.5 with a custom module that has an exec script. Terminate the Waybar process and notice that the script’s subprocess stays alive and is now a child of the init process.
  • Run Waybar with this patch and follow the same steps as above. Notice that this time the script’s subprocess terminates when the parent exits.

@matteodelabre

This comment has been minimized.

@matteodelabre matteodelabre marked this pull request as draft February 12, 2021 19:39
(Fixes #358.)

Subprocesses created for custom module scripts were previously left
running when the parent Waybar process exited. This patch sets the
parent-death signal of child processes (PR_SET_PDEATHSIG on Linux,
PROC_PDEATHSIG_CTL on FreeBSD) to SIGTERM.

Caveats:

* This uses Linux-specific or FreeBSD-specific calls. I don’t know if
  this project targets other systems?
* There is a possibility that Waybar exits after calling `fork()`, but
  before calling `prctl` to set the parent-death signal. In this case,
  the child will not receive the SIGTERM signal and will continue to
  run. I did not handle this case as I consider it quite unlikely, since
  module scripts are usually launched only when Waybar starts. Please
  let me know if you think it needs to be handled.

Testing:

* With `htop` open, run Waybar v0.9.5 with a custom module that has an
  `exec` script. Terminate the Waybar process and notice that the
  script’s subprocess stays alive and is now a child of the init
  process.
* Run Waybar with this patch and follow the same steps as above. Notice
  that this time the script’s subprocess terminates when the parent
  exits.
@matteodelabre matteodelabre marked this pull request as ready for review February 12, 2021 20:25
@Alexays
Copy link
Owner

Alexays commented Feb 23, 2021

Thanks @matteodelabre!

@Alexays Alexays merged commit cb1c7ea into Alexays:master Feb 23, 2021
@matteodelabre matteodelabre deleted the terminate-custom-on-exit branch February 23, 2021 08:59
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

Successfully merging this pull request may close these issues.

Child process does not stops
2 participants