Berkeley CSUA MOTD:Entry 52547
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2009/2/9-17 [Computer/SW/Languages/C_Cplusplus] UID:52547 Activity:nil
2/9     I am new to signal handlers in C. I want to clean up some temp
        files if my program is interrupted. I can catch the interrupt
        just fine, but signal() doesn't take any args to pass to the
        handler. So how can I pass it the information it needs to be
        useful, like the names of the files to delete before exiting?
        STFW doesn't yield much.
        \_ You are going to need a global variable.
        \_ Be careful.  Almost every library function can't be used from
           within a signal handler.  Take a look at this website, and
           take its message to heart ;)
           <DEAD>www.securecoding.cert.org/confluence/display<DEAD>
           seccode/11.+Signals+(SIG)
        \_ You will probably need to do something with sigsetjmp and
           siglongjmp.  Stevens APUE Ch 10 has a good explanation iirc.
           \_ Depending on your security needs this is a bad idea
              <DEAD>www.securecoding.cert.org/confluence/display/seccode<DEAD>
              SIG32-C.+Do+not+call+longjmp%28%29+from+inside+a+signal+handler
              \_ Didn't know this. Thanks for the link.