toys: Sun Jan 13 23:33:00 2008

Sun Jan 13 23:33:00 2008

While debugging a very strange problem (a simple shell loop that was occasionally continuing around before the body was done, leading to multiple parallel runs of something that was supposed to be serialized) I came across Debian Bug #445956 - "script dies on SIGWINCH."

The bug report simply notes that script "dies", reporting "Script done, file is typescript", which is true... but incomplete. It turns out that script has a parent and child process, and only the parent dies; the child (and whatever was being run inside script) continues to run!

In the long run, the important thing is that bsd-utils actually got fixed (the bug mentioned above is closed by 2.13-9, though that is post-etch and post-gutsy.) In the short run, it would be nice (at least for me) to have a workaround...

My first attempt was simply to use signal.signal to set SIGWINCH to SIG_IGN (in the python wrapper that actually runs script for me.) Not good enough - the bug is in code that is setting a SIGWINCH handler in script itself.

Second attempt was to call sigblock... but for portability reasons (somewhat tied to embedding python in other code, if I correctly interpreted the postings excusing its absence - I didn't look to closely because having a good reason didn't actually solve my problem :-) python's signal module can't do sigblock. Oh well, ctypes to the rescue; fixed_script.py shows an example of the workaround. Worked for me, both in my application and in standalone tests using screen to change window sizes (I use ratpoison and generally don't want windows to take up less than the entire screen, so outside of testing like this I don't generally care that I can't easily resize windows... I only noticed in this case because I reattached the screen session from two different machines, which had different (fixed) window sizes :-)

Footnotes: