Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zsh signal handler is not safe



Hi folks,

I wanted to reach out to you and let you know that I've seen some crashes in zsh related to using illegal API from within a signal handler context.  Specifically, you signal handler zhandle() will call zexit() with which in turn calls savehistfile() and lockhistfile() which expectedly does a lot of API calls that are not thread safe (eg: malloc/stdio/etc).

It looks like zexit()'s from_where is set to 1 for the signal handler case, which is causing HFILE_NO_REWRITE to be added to the writeflags passed to savehistfile().  That seems to be designed to avoid the memory allocations from reading in the existing file, but unfortunately we still fail in the call to lockhistfile().

It would be better for your signal handler to set a sentinel that will be checked by the main event loop to trigger the exit and then just get out of the signal handler as soon as possible.

--Jeremy

Attachment: smime.p7s
Description: S/MIME cryptographic signature



Messages sorted by: Reverse Date, Date, Thread, Author