Zsh Mailing List Archive
Messages sorted by:
zsh signal handler is not safe
- X-seq: zsh-workers 44355
- From: Jeremy Huddleston Sequoia <jeremyhu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: zsh signal handler is not safe
- Date: Wed, 22 May 2019 23:26:43 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=mime-version : from : content-type : subject : message-id : date : to; s=20180706; bh=oZTjpyRN7g5Iky12JOkuDYsf+cyjqQWwn2tguW2wM3U=; b=udTRT8xe6EiVPntDysnrZDX9yE/1DJ8eUvICwxPwpK7OdbyUS6i1jTBLiufGU9q1G22z 7IbHmjIfS0zhYdlmRePOmGSPpNpbRHK/HUwBZyZvy4VXkPlFSzxt25ONpXvYyv3nyCXF uwlD9qcnP/duNyhZSPXbaylkNdVf1M2n51LgWepaCgT+WG/IjBXz/t269VFviiy+opqQ PPJHnp6XDMpynaE2Gwvffkt6WMrWtCY/uPdYCgWikEtrAn3nPPJDofDA/r9Vm9kw/Wyg zlCVVManPQeCM+Gq9hKPOqBadnHUbwSv4/oydDTZqe3lRyPv3IsjGt1+LqI4ZJd48JCl xg==
- List-help: <mailto:email@example.com>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- List-unsubscribe: <mailto:email@example.com>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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.
Description: S/MIME cryptographic signature
Messages sorted by: