*BSD News Article 30217


Return to BSD News archive

Xref: sserve comp.unix.internals:7170 comp.unix.bsd:13899 comp.unix.sys5.r4:7212
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!news.Hawaii.Edu!ames!hookup!swrinde!cs.utexas.edu!chpc.utexas.edu!news.utdallas.edu!corpgate!bnrgate!bmerha64.bnr.ca!bcarh2ee!rakshit
From: rakshit@bcarh2ee.bnr.ca (Rakshit Simha)
Newsgroups: comp.unix.internals,comp.unix.bsd,comp.unix.sys5.r4
Subject: Re: Pushing/Popping Signal Catching Functions
Date: 3 May 1994 19:58:12 GMT
Organization: Bell-Northern Research, Ottawa, Canada
Lines: 40
Sender: rakshit@bcarh2ee (Peter Channen)
Distribution: world
Message-ID: <2q6ack$pq1@bmerha64.bnr.ca>
References: <2q63js$snd@access3.digex.net>
NNTP-Posting-Host: bcarh2ee.bnr.ca

In article <2q63js$snd@access3.digex.net>, masato@access.digex.net (J M Thompson) writes:
|> 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:
[...]
|> Source for my library routines
|> void libfunc1( void) {
|> 
|>  /* push my  specific action, i.e., equivalent of
|>   signal(SIGTERM, my_term_func);
|>  */

*** The "signal" system call itself returns the previous disposition of that
signal.  You can save this in a variable of type "void (*)(int)".  That is, a
pointer to a function that takes a single parameter ( an integer) and returns
nothing.  Note that "signal" returns SIG_ERR if there is a problem.

|>   /* do processing libfunc1 */
|> 
|>   /* now pop off my specific action for SIGTERM */

*** You can call "signal" again with the saved return value of the first call
as the new disposition.

|>   return;
|> } 
|> 

Also check out "sigaction".

Regards,
Rakshit.