- int rc = system(cmd.c_str());
- if (rc < 0 && errno == ECHILD) rc = 0; // ignore, it could happens
- // I know one reason for this is that SICCHLD is set to SIG_IGN but this
- // should not be the case here. SIGCHLD is explicity set to SIG_DFL
- // using a sigaction before the call to system(). (Although it is
- // normally set to SIG_IGN). There should not be any other threads
- // messing about with SIGCHLD.
+
+ // Result code:
+ int rc = 1;
+
+ struct sigaction sa;
+ sa.sa_handler = &handle_sigchld;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
+ if (sigaction(SIGCHLD, &sa, 0) != -1) {
+ rc = system(cmd.c_str());
+ }
+ else {
+ perror(0);
+ }