Does Ice catch any signals?

This answer applies to Ice for C++ on all platforms except Windows.

During the creation of the first communicator in a process, Ice changes the signal disposition of SIGPIPE to SIG_IGN (ignore). When the last communicator in a process is destroyed, Ice changes SIGPIPE's disposition to SIG_DFL; the default action for SIGPIPE terminates the process without core dump.

Ice does not install any signal handlers. However, Ice provides helper classes with signal-handling capabilities:

  • Ice::CtrlCHandler handles CTRL-C and CTRL-C-like signals (SIGINT, SIGTERM and SIGHUP) by calling a function registered by the application.
  • Ice::Application and Ice::Service each use a CtrlCHandler to shut down or destroy the communicator when the process receives a CTRL-C or similar signal.

These three classes are helper classes: they simplify coding, but you do not have to use them.

CtrlCHandler blocks delivery of SIGINT, SIGTERM, and SIGHUP and uses a separate thread to invoke an application-provided signal handler (if any). The handler is called synchronously from a separate thread, so the handler can safely call into the Ice run time and make system calls that are not async-signal-safe without fear of deadlock or data corruption.

However, if you fork and execute a child process, the exec'd process inherits the signal mask of the thread that calls exec, therefore the signals remain blocked; if you need the default behavior of these signals in the exec'd process, you must unblock them in the child after calling fork but before calling exec as follows:

C++
sigset_t sigs;
sigemptyset(&sigs);
sigaddset(&sigs, SIGHUP);
sigaddset(&sigs, SIGINT);
sigaddset(&sigs, SIGTERM);
sigprocmask(SIG_UNBLOCK, &sigs, 0);

See Also