/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program receives SIGUSR1 signals. */
/* For my_handler(int signo, siginfo_t* info, void *context)
   this program does not work in Linux */

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

void my_handler(int signo, siginfo_t* info, void *context)
{
    fprintf(stdout,"Signal handler entered for signal number %d\n",signo);
    fprintf(stdout,"si_signo = %3d\n",info->si_signo);
    fprintf(stdout,"si_code = ");
    if(info->si_code == SI_USER) fprintf(stdout,"USER\n");
    else if (info->si_code == SI_QUEUE) fprintf(stdout,"QUEUE\n");
    else if (info->si_code == SI_TIMER) fprintf(stdout,"TIMER\n");
    else if (info->si_code == SI_ASYNCIO) fprintf(stdout,"ASYNCIO\n");
    else if (info->si_code == SI_MESGQ) fprintf(stdout,"MESGQ\n");            
    else fprintf(stdout, "%d\n", info->si_code);
    /* fprintf(stdout," si_value = %3d\n", info->si_value.sival_int); */
}

int main() {
    struct sigaction act;
    sigset_t sigset;
    
    fprintf(stdout,"Process ID is %ld\n", (long) getpid());
    sigemptyset(&sigset);
    sigaddset(&sigset, SIGALRM);
    sigprocmask(SIG_BLOCK, &sigset, NULL);
    sigemptyset(&act.sa_mask);
    act.sa_flags = SA_SIGINFO;
    act.sa_sigaction = my_handler;
    if(sigaction(SIGUSR1, &act, NULL) < 0) {
      perror("Sigaction failed");
      exit(1);
    }
    fprintf(stdout,"Signal SIGUSR1 = %d ready\n",SIGUSR1);
    raise(SIGUSR1);
}
       
