SIGINT, longjmp, getaddrinfo
Hal Murray
hmurray@megapathdsl.net
Tue Feb 9 09:29:00 GMT 2016
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.
More information about the Libc-help
mailing list