home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!daemon
- From: Philip Balister <balister@pdsrvr.salem.ge.com>
- Subject: Return from signal handler??
- Message-ID: <1992Aug12.195205.10052@athena.mit.edu>
- Sender: daemon@athena.mit.edu (Mr Background)
- Reply-To: balister@pdsrvr.salem.ge.com
- Organization: The Internet
- Date: Wed, 12 Aug 1992 19:52:05 GMT
- Lines: 66
-
- A guy where I work is trying to use the signal mechanism of Lynxos to set
- a global variable to indicate a floating point error by trapping floating
- point exceptions signals. What he found was that the signal handler seems
- to return to the line that caused the signal, causing it to happen again,
- not what he wanted! I tried his code on my linux box to see what would happen
- (Note the code is now using a segment violation, but the thought is the same
- handle the signal and continue running from the line after the problem).
-
- Well it continually loops (returnss to the line causing the seg. violation)
- using sigaction and handles the signal once and core dumps the other way.
-
- Here is the code:
-
- ========================================================
- #include <signal.h>
- /* The following does not appear to work correctly regardless of
- the state of "DOSIGACTION". Is this a bug?
- */
-
- void catch(a)
- int a;
- {
- printf("Got it %d -> %x\n",a);
- }
-
- int main()
- {
- struct sigaction sig1,sig2;
-
- int a,b;
-
- #ifdef DOSIGACTION
- printf("Using sigaction\n");
- sig1.sa_handler=catch;
- #ifdef Lynx
- sig1.sa_mask.x[0]=0;
- sig1.sa_mask.x[1]=0;
- #else
- sig1.sa_mask=0;
- #endif
- sig1.sa_flags=0;
- sigaction(SIGSEGV,&sig1,&sig2);
- #else
- printf("Using signal\n");
- signal(SIGSEGV,catch);
- #endif
-
- /* Generate a floating point error. */
- a=*(int *) 0xfffffff;
-
- }
- =====================================================
-
- Note the inconsistent comment!
-
- Lynx is not equal to Linux.
-
- Can anyone tell me if the Linux behavior is correct? It works the way we
- expect it to on an Interactive unix box. For Linux I used GCC2.2.2 and 0.96c
- kernel.
-
- Thanks,
-
- Philip Balister
- balister@salem.salem.ge.com
-
-