baskerville / bspwm

A tiling window manager based on binary space partitioning
BSD 2-Clause "Simplified" License
7.61k stars 420 forks source link

Revamp signal handling. #1480

Open falsifian opened 5 months ago

falsifian commented 5 months ago

I ran into a bug related to bspwm's signal handling, and then noticed a couple of other issues, so decided to try redoing it.

The bug: pipes like find / | : would hang when launched from bspwm instead of terminating right away. The reason was that bspwm ignores SIGPIPE, and that status got passed on to anything launched via bspwmrc, through sxhkdrc, xterm, my shell, all the way through to the find process which is supposed to die when its output is cut off.

NB I've only just started testing this change by using it (edit to add: on OpenBSD, so testing on Linux might be valuable). If there are particular things for me to try out (e.g. the reasons the signal handlers were installed in the first place), let me know.

Details:

ortango commented 5 months ago

Running linux here and everything seems to be working fine with the patch. I tried getting some zombied processes in bspwmrc and subscribe seems to work fine.

I needed to add a signal.h include in bspwm.h to build.

fwiw, i could not get the original issue to trigger - bash as shell and dash as sxhkd shell. I tried directly in bspwmrc, but no hang with the find command.

falsifian commented 5 months ago

Running linux here and everything seems to be working fine with the patch. I tried getting some zombied processes in bspwmrc and subscribe seems to work fine.

I needed to add a signal.h include in bspwm.h to build.

Thanks! Added.

fwiw, i could not get the original issue to trigger - bash as shell and dash as sxhkd shell. I tried directly in bspwmrc, but no hang with the find command.

Interesting. I don't have a Linux computer I can run bspwm on, but I do have Linux shell access. I'm curious what these two commands do for you:

On OpenBSD and my Linux shell account, the find command keeps running (and on Linux, writes permission errors to stderr).

Baseline to compare to. Exits right away for me.

(Tangent: I tried making Python versions of the above commands in case you have Python more readily available, but as far as I can tell Python's os.system suffers from the same SIGPIPE issue as bspwm. I found this related bug saying at least it got fixed for the subprocess module but I'm too lazy to figure out how to use that instead of os.system.)

ortango commented 5 months ago

The perl commands act as expected, pipe ignore version with perm errors to stderr and normal version exits immediately.

Not sure why I'm not getting the sig_ign behavior you get.

linux's procfs has bitmasks for the caught/blocked/ignored signals of a process and makes it easy enough to check. Certainly am inheriting the signal handlers from bspwm in bspwmrc and external rules script (sxhkd is not launched from bspwmrc and is not a child of bspwm on my machine)