As others say, only one signal handler, which is the last, can be installed. You then have to manage the calls of the two functions yourself. The sigaction function can return a previously installed signal handler, which you can name yourself.
Something like this (unverified code):
static void (*lib1_sighandler)(int) = NULL; static void (*lib2_sighandler)(int) = NULL; static void aggregate_handler(int signum) { if (lib1_sighandler) lib1_sighandler(signum); if (lib2_sighandler) lib2_sighandler(signum); } ... (later in main) struct sigaction sa; struct sigaction old; lib1_init(...); sigaction(SIGINT, NULL, &old); lib1_sighandler = old.sa_handler; lib2_init(...); sigaction(SIGINT, NULL, &old); lib2_sighandler = old.sa_handler; memset(&sa, 0, sizeof(sa)); sa.sa_handler = aggregate_handler; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL);
Shahbaz
source share