Puzzled: SIGALRM signal handler doesn't install
Hello.
I already installed some signal handlers, but the one for SIGALRM doesn't install.
Application follows default action and quits.
Here is my code
Code:
#define INTERVAL 10
static int s_interrupted = 0;
static void s_signal_handler (int signal_value)
{
if (signal_value == SIGTERM || signal_value == SIGSTOP || signal_value == SIGINT)
s_interrupted = 1;
if (signal_value == SIGALRM)
{
//signal(SIGALRM,alarm_wakeup);
printf("%d sec up partner, Wakeup!!!\n",INTERVAL);
}
}
static void s_catch_signals (void)
{
struct sigaction action;
action.sa_handler = s_signal_handler;
action.sa_flags = 0;
sigemptyset (&action.sa_mask);
sigaction (SIGINT, &action, NULL);
sigaction (SIGTERM, &action, NULL);
sigaction (SIGALRM, &action, NULL);
}
void alarm_wakeup (int i)
{
signal(SIGALRM,alarm_wakeup);
printf("%d sec up partner, Wakeup!!!\n",INTERVAL);
}
int main (void)
{
struct itimerval tout_val, check_val;
tout_val.it_interval.tv_sec = 0;
tout_val.it_interval.tv_usec = 0;
tout_val.it_value.tv_sec = 10; /* set timer for "INTERVAL (10) seconds */
tout_val.it_value.tv_usec = 0;
//int myerr = setitimer(ITIMER_REAL, &tout_val,0);
//signal(SIGALRM,alarm_wakeup); /* set the Alarm signal capture */
s_catch_signals ();
while (1) {
if (s_interrupted == 1) {
printf("\n");
#if (MAIN_DEBUG)
dbg_print(MAIN_PROC_NAME,"SIGINT interrupt received, killing node\n");
#else
printf("\n!!!!! KILL NODE COMMAND RECEIVED !!!!!\n\n");
#endif
break;
}
getitimer(ITIMER_REAL,&check_val);
dbg_print(MAIN_PROC_NAME,"Timer check %ld, %ld, %ld, %ld\n",check_val.it_interval.tv_sec,check_val.it_interval.tv_usec,check_val.it_value.tv_sec,check_val.it_value.tv_usec);
if (check_val.it_value.tv_usec == 0)
alarm(10);
s_sleep (1000);
}
return 0;
}
As you can see from the code I tried two ways of installing the handler:
-standalone with call to signal(SIGALRM,alarm_wakeup);
-integrated in the already existing signal handler
No matter what after the timer expires the application quits.
What am I doing wrong?