On Sat 12 Aug 2023 at 23:49:43 +0200, Michael van Elst wrote: > On Sat, Aug 12, 2023 at 03:22:56PM +0200, Rhialto wrote: > > > > Or, alternatively, a proper signal handler for SIGCHLD could be set up. > > ctwm had a signal handler for SIGCHLD (not 100% correct). And that got > replaced > by ignoring the signal to avoid waiting for children.
Yes, looking at the history, it got replaced in commit 647.1.4. This was removed (amongst other things): #ifdef __WAIT_FOR_CHILDS /* * Handler for SIGCHLD. Needed to avoid zombies when an .xinitrc * execs ctwm as the last client. (All processes forked off from * within .xinitrc have been inherited by ctwm during the exec.) * Jens Schweikhardt <[email protected]> */ void ChildExit(int signum) { int Errno = errno; signal(SIGCHLD, ChildExit); /* reestablish because we're a one-shot */ waitpid(-1, NULL, WNOHANG); /* reap dead child, ignore status */ errno = Errno; /* restore errno for interrupted sys calls */ } #endif The "one-shot" comment is no longer true (POSIX says "Once an action is installed for a specific signal, it shall remain installed until another action is explicitly requested (by another call to sigaction()), until the SA_RESETHAND flag causes resetting of the handler, or until one of the exec functions is called." in https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html The waitpid() call should be in a loop, because there may be multiple children to wait for. I read somewhere about "SysV semantics" that would cause exactly one SIGCHLD for each child, but I wouldn't want to invoke those semantics. The __WAIT_FOR_CHILDS was probably never defined so this code was probably never used. BUT, the comment on the new "signal(SIGCHLD, SIG_IGN);" says "This should be set by default" but that also isn't exactly true. Default action for SIGCHLD is to do nothing, but that isn't the same as SIG_IGN (as discussed in the initial mail and the referenced Problem Report). I suppose that the problem was not noticed since 2018 because there are several preconditions: - session startup script must start some programs in the background, and end with "exec ctwm". Just "ctwm" without "exec" doesn't do it. This is so that the started background processes become children of ctwm (even if ctwm didn't start them itself). - on FreeBSD (and probably Linux too) they apparently don't follow the described semantics of wait*(2) regarding SIGCHLD set to SIG_IGN, OR in system(3) they work around it somehow. Alledgedly, POSIX doesn't require system(3) to work in this state. -Olaf. -- ___ Olaf 'Rhialto' Seibert <rhialto/at/falu.nl> \X/ There is no AI. There is just someone else's work. --I. Rose
signature.asc
Description: PGP signature
