Re: [hackers] [dwm][PATCH] do not call signal-unsafe function inside sighanlder

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Tue, 19 Jul 2022 09:27:35 +0200

On Tue, Jul 19, 2022 at 12:05:48AM +0200, François-Xavier Carton wrote:
> On Thu, Jul 14, 2022 at 07:26:40AM +0600, NRK wrote:
> > die() calls vprintf, fputc and exit; none of these are
> > async-signal-safe, see `man 7 signal-safety`.
> > ---
> > dwm.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/dwm.c b/dwm.c
> > index 5646a5c..8358fb0 100644
> > --- a/dwm.c
> > +++ b/dwm.c
> > _AT_@ -1541,6 +1541,8 @@ setup(void)
> > Atom utf8string;
> >
> > /* clean up any zombies immediately */
> > + if (signal(SIGCHLD, sigchld) == SIG_ERR)
> > + die("can't install SIGCHLD handler:");
> > sigchld(0);
> >
> > /* init screen */
> > _AT_@ -1638,8 +1640,6 @@ showhide(Client *c)
> > void
> > sigchld(int unused)
> > {
> > - if (signal(SIGCHLD, sigchld) == SIG_ERR)
> > - die("can't install SIGCHLD handler:");
>
> Technically, no standard guarantees that the handler stays after being
> called once. The implementation could reset it to the default action.
> One may want to re-add a call to signal here, without error checking, to
> ensure the handler remains in case SIGCHLD is raised multiple times.
>
> > while (0 < waitpid(-1, NULL, WNOHANG));
> > }
> >
> > --
> > 2.35.1
> >
> >
>

Hi,

Do you have a reference of a description of this behaviour in an other system,
specification or standard?

Thanks,

-- 
Kind regards,
Hiltjo
Received on Tue Jul 19 2022 - 09:27:35 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 19 2022 - 10:36:30 CEST