(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.
Moving rfkill to the main event loop had unexpected side-effects.
Notably, the network module mutex can block all the main thread events
for several seconds while the network worker thread is sleeping.
Instead of waiting for the mutex let's hope that the worker thread
succeeds and schedule timer thread wakeup just in case.
Open rfkill device only once per module.
Remove rfkill threads and use `Glib::signal_io` as a more efficient way
to poll the rfkill device.
Handle runtime errors from rfkill and stop polling of the device instead
of crashing waybar.
Kernel 5.11 added one more field to the `struct rfkill_event` and broke
unnecessarily strict check in `rfkill.cpp`. According to `linux/rfkill.h`,
we must accept events at least as large as v1 event size and should be
prepared to get additional fields at the end of a v1 event structure.
Multiple .done events may arrive in batch. In this case libwayland would
queue xdg_output.destroy and dispatch all pending events, triggering
this callback several times for the same output.
Delete xdg_output pointer immediately on the first event and use the
value as a guard for reentering.
At this point we're not awaiting any protocol events and flushing
wayland queue makes little sense. As #1019 shows, it may be even harmful
as an extra roundtrip could process wl_output disappearance and delete
output object right from under our code.