NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg/57579: ctwm application menu hangs because of SIGCHLD/SIG_IGN/system(3) interaction



The following reply was made to PR xsrc/57579; it has been noted by GNATS.

From: Rhialto <rhialto%falu.nl@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: pkg/57579: ctwm application menu hangs because of
 SIGCHLD/SIG_IGN/system(3) interaction
Date: Sat, 12 Aug 2023 17:06:17 +0200

 Second version of the patch. Restores errno.
 
 Index: signals.c
 ===================================================================
 RCS file: /cvsroot/xsrc/external/mit/ctwm/dist/signals.c,v
 retrieving revision 1.1.1.1
 diff -u -r1.1.1.1 signals.c
 --- signals.c	5 Jul 2023 07:36:07 -0000	1.1.1.1
 +++ signals.c	12 Aug 2023 15:04:33 -0000
 @@ -8,6 +8,8 @@
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
 +#include <sys/wait.h>
 +#include <errno.h>
  
  #include "ctwm_shutdown.h"
  #include "signals.h"
 @@ -16,6 +18,7 @@
  /* Our backends */
  static void sh_restart(int signum);
  static void sh_shutdown(int signum);
 +static void sh_sigchld(int signum);
  
  
  // Internal flags for which signals have called us
 @@ -46,9 +49,8 @@
  	// die...
  	signal(SIGALRM, SIG_IGN);
  
 -	// This should be set by default, but just in case; explicitly don't
 -	// leave zombies.
 -	signal(SIGCHLD, SIG_IGN);
 +	// Explicitly don't leave zombies.
 +	signal(SIGCHLD, sh_sigchld);
  
  	return;
  }
 @@ -123,3 +125,18 @@
  	SignalFlag = sig_shutdown = true;
  }
  
 +/**
 + * Handle SIGCHLD so we don't leave zombie child processes.
 + * SIG_IGN'ing it would cause system(3) to malfunction.
 + */
 +static void
 +sh_sigchld(int signum)
 +{
 +	pid_t pid;
 +	int old_errno = errno;
 +
 +	while((pid = waitpid(-1, NULL, WNOHANG)) > 0)
 +		;
 +
 +	errno = old_errno;
 +}
 


Home | Main Index | Thread Index | Old Index