*BSD News Article 29994


Return to BSD News archive

Xref: sserve comp.unix.internals:7146 comp.unix.bsd:13836 comp.unix.sys5.r4:7166
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!howland.reston.ans.net!cs.utexas.edu!convex!news.duke.edu!MathWorks.Com!news.kei.com!babbage.ece.uc.edu!mary.iia.org!rtp.vnet.net!news1.digex.net!access.digex.net!not-for-mail
From: masato@access.digex.net (J M Thompson)
Newsgroups: comp.unix.internals,comp.unix.bsd,comp.unix.sys5.r4
Subject: Pushing/Popping Signal Catching Functions
Date: 3 May 1994 14:02:36 -0400
Organization: The Internet
Lines: 69
Message-ID: <2q63js$snd@access3.digex.net>
NNTP-Posting-Host: access3.digex.net

I am writing a set of library routines in which I would like to 
catch signals, i.e. SIGTERM, but in a way that does not replace
any signal catching functions implmented by the caller of my
library routines.  In other words, when my routine is in control,
I'd like to "push" my signal processing routine on top and just
before I exit, I'd like to "pop" my signal processing routine off.  
When I am in control, I want to do some specific actions when
the signal is generated, but when control is returned to the caller,
I'd like to restore the caller's action if there was one specified.

Expressed as source code fragments:

Caller's source module
main() {

  signal(SIGTERM, term_func);

  /* do processing */

  libfunc1();      /* call library function */

} /* end of main */

int term_func(int signo) {

  /* do SIGTERM processing  for caller */

} /* end of term_func */


Source for my library routines
void libfunc1( void) {

 /* push my  specific action, i.e., equivalent of
  signal(SIGTERM, my_term_func);
 */

  /* do processing libfunc1 */


  /* now pop off my specific action for SIGTERM */

  return;
} 

int my_term_func(int signo) {

  /* libfunc1 specific processing for SIGTERM */ 

}

If it matters, I envision that my routines will be statically linked
with the caller's object code, but I would eventually like my stuff
to be a shared library.  I need to support the functionality
described in SunOS, Solaris 2.3, and AIX.

I've read Steven's book _Advanced_Programming_in_the_UNIX_Environment_
and from what I understand (which could be flawed), I can replace
the function that processes a signal but not "pop on" and "push off"
functions.  

Any help or ideas would be appreciated.

Please send email replies, I'll summarize for the newsgroup.

-- 
Jim Thompson                     
email: masato@digex.net
phone: 703-759-8252