This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

SIGINT, longjmp, getaddrinfo


I'm working on some code that wants to use ^C to bail out from working on a 
command and get back to the top of the read/dispatch loop.

The symptom is that ^C stopped working.  A few printf-s later, I discovered 
that the SIGINT handler was being called with SIGINT masked.  Switching from 
setjmp/longjmp to sigsetjmp/siglongjmp solved the problem, I think, but 
leaves me confused.

Poking around with google didn't find anything that discusses this case.  (I 
might have missed it.)  I did find various examples using longjmp from a 
signal handler, but none that I looked at suggested that I should use 
siglongjmp or really should avoid jmp-ing if at all possible.

Now that I think about it, jmp-ing out of getaddrinfo or other arbitrary code 
seems like a bad idea.  Or at least a very complicated one.  The code doesn't 
get a chance to clean up.  In the getaddrinfo case, there is the possibility 
to leave a socket opened or leak some storage.  But maybe getaddrinfo is 
smart enough to mask SIGINT until it is ready.  (I've noticed unexpected 
delays while trying to ^C out of various utilities when they were doing DNS 
lookups.  I don't remember any details.)  But only SIGINT was masked.  There 
could also be timer interrupts.  My man pages don't mention masking any 
interrupts...

Is this a well know can-of-worms?  If so, can somebody point me at the 
appropriate FAQ or discussion?

In case it matters, I was running on Fedora 23, probably 32 bit.  I can test 
on various other distros/OSes if that will help.

Thanks.


-- 
These are my opinions.  I hate spam.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]