int main(void) {
struct sigaction sact , sact_old ;
// Definitions for functions handler() and fatal() not shown ; assume
// they have no issues.
if (sigaction(SIGCHLD , 0 , &sact_old) == -1)
fatal("sigaction() call to get the original signal handling failed") ;
sact.sa_handler = handler ;
sact.sa_flags = 0 ;
sact.sa_mask = sact_old.sa_mask ; // *** Is this OK ? ***
if (sigaction(SIGCHLD , &sact , 0) == -1)
fatal("sigaction(SIGCHLD , ...) failed") ;
...................
}
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigemptyset.html :
RATIONALE
The implementation of the sigemptyset() (or sigfillset()) function
could quite trivially clear (or set) all the bits in the signal set.
Alternatively, it would be reasonable to initialize part of the
structure, such as a version field, to permit binary-compatibility
between releases where the size of the set varies. For such reasons,
either sigemptyset() or sigfillset() must be called prior to any
other use of the signal set, even if such use is read-only (for
example, as an argument to sigpending()).
If we take this literally then what my code does above is not ok. On the other
hand what I do seems reasonable and the only alternative would be something
like
sigemptyset(&sact.sa_mask) ;
Have variable sig loop over all signals {
if sigismember(&sact_old.sa_mask , sig) sigaddset(&sact.sa_mask , sig) ;
}
If the assignment is not ok then it would be nice if POSIX had something like
sigcopyset(sigset_t *set1 , sigset_t *set2)
GNU offers sigorset(...) but I don't want to use extensions.
--
Somebody was trying to tell me that CDs are better than vinyl because
they don't have any surface noise. I said, "Listen, mate, life has
surface noise."
John Peel