home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / linux / 8040 < prev    next >
Encoding:
Text File  |  1992-08-12  |  2.2 KB  |  78 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!daemon
  3. From: Philip Balister <balister@pdsrvr.salem.ge.com>
  4. Subject: Return from signal handler??
  5. Message-ID: <1992Aug12.195205.10052@athena.mit.edu>
  6. Sender: daemon@athena.mit.edu (Mr Background)
  7. Reply-To: balister@pdsrvr.salem.ge.com
  8. Organization: The Internet
  9. Date: Wed, 12 Aug 1992 19:52:05 GMT
  10. Lines: 66
  11.  
  12. A guy where I work is trying to use the signal mechanism of Lynxos to set
  13. a global variable to indicate a floating point error by trapping floating
  14. point exceptions signals. What he found was that the signal handler seems
  15. to return to the line that caused the signal, causing it to happen again,
  16. not what he wanted! I tried his code on my linux box to see what would happen
  17. (Note the code is now using a segment violation, but the thought is the same
  18. handle the signal and continue running from the line after the problem).
  19.  
  20. Well it continually loops (returnss to the line causing the seg. violation)
  21. using sigaction and handles the signal once and core dumps the other way.
  22.  
  23. Here is the code:
  24.  
  25. ========================================================
  26. #include <signal.h>
  27. /* The following does not appear to work correctly regardless of
  28.    the state of "DOSIGACTION".  Is this a bug?
  29. */
  30.  
  31. void catch(a)
  32. int a;
  33. {  
  34.   printf("Got it %d -> %x\n",a);
  35. }          
  36.  
  37. int main()
  38. {                    
  39.   struct sigaction sig1,sig2;
  40.  
  41.   int a,b;                  
  42.   
  43. #ifdef DOSIGACTION                        
  44.   printf("Using sigaction\n");
  45.   sig1.sa_handler=catch;   
  46. #ifdef Lynx
  47.   sig1.sa_mask.x[0]=0;
  48.   sig1.sa_mask.x[1]=0;
  49. #else
  50.   sig1.sa_mask=0;
  51. #endif 
  52.   sig1.sa_flags=0;
  53.   sigaction(SIGSEGV,&sig1,&sig2);
  54. #else                         
  55.   printf("Using signal\n");
  56.   signal(SIGSEGV,catch);
  57. #endif
  58.                  
  59.   /* Generate a floating point error. */  
  60.   a=*(int *) 0xfffffff;
  61.   
  62. }
  63. =====================================================
  64.  
  65. Note the inconsistent comment!
  66.  
  67. Lynx is not equal to Linux.
  68.  
  69. Can anyone tell me if the Linux behavior is correct? It works the way we
  70. expect it to on an Interactive unix box. For Linux I used GCC2.2.2 and 0.96c
  71. kernel.
  72.  
  73. Thanks,
  74.  
  75. Philip Balister
  76. balister@salem.salem.ge.com
  77.  
  78.