I have some shared libraries. I am doing sigaction in each and
establishing a handler in each, but what I require is for whenever a
handler in one of the shared libs gets a signal, it will do it's
processing and then pass the signal on to the previous signal handler.
E.g. main does sigaction, calls shlib1, which does sigaction; then main
calls shlib2, which does sigaction. Eventually main gets a signal. What
makes sense is that the handlers in shlib2, shlib1, then main should get
control.

How to do this.
I tried the following (code is somewhat abbreviated):

Code:
void sighdlr( int sig )
{
   struct sigaction oact, nex;

   sigaction( sig, NULL, &oact);
   if ( oact.sa_handler != SIG_DFL && oact.sa_handler != SIG_ERR && oact.sa_handler != SIG_IGN && oact.sa_handler != NULL ) {
      printf( "sighdlr: calling ohandler %p\n", oact.sa_handler );
     (oact.sa_handler)( sig );
   }
}

main()
{
struct sigaction sigact;
memset( &sigact, 0, sizeof(sigact) );
sigemptyset ( &sigact.sa_mask );   /* all signals unblocked */
sigact.sa_handler   = hdlr;
sigact.sa_flags = 0;
sigaction( SIGTERM, &sigact,  NULL ); /* set up signal handler, don't
care about the old handler - system should save it I think */

shlib1();   /* sets up sigaction same as main does */
shlib2()    /* ditto */
pause();    /* wait for signal */
}
Now when I send kill -SIGTERM to the process, only the last sigaction
isuer gets control (as I expect and want).
The problem is that the sigaction( sig, NULL, &oact) gives the address of the LAST
sigaction structure and thus the same sa_handler as the one currently running. NOT the
one created by shlib1();
I expect the queue of sigaction structures to be, in order: main, shlib1, shlib2; and if
shlib2 gets a signal, the the previous should be the shlib1 sigaction structure etc.

Seems the only way is to keep track of the sigaction structures myself in some, but
that is a bit difficult if different folks are writing the shared libs.

I Googled this for any examples, looked in Steven's book and cannot find no
example of how to do this. Seems like a reasonable thing to try to
handle, but it just does not work.

Hopefully, this makes sense to someone and there is a way to obtain the list(in order) of the
sigaction structures.

Thanks,

Jim