unsafe functions from signal handler
- From: "bill pursell" <bill.pursell@xxxxxxxxx>
- Date: 31 Jan 2006 00:52:24 -0800
I came upon the following code yesterday in a signal handler:
fflush(stderr);
fprintf(stderr, "...%d\n", signal);
fflush(stderr);
/* snip */
exit(-1);
This brought to mind several questions:
1. fprintf is not a safe function, so it is a bad idea to
call it from within a signal handler. However, it strikes
me that the only problem with it is that the writes to stderr
will be interleaved and munged a bit. Is there a more
substantial problem? Also, does it matter if the signal
disposition is set with signal() or with sigaction()? In
either case, I would not call fprintf from the signal handler,
but there seems to be a subtlety that I'm missing. In particular,
if the signal is SIGRTMIN or greater, the signals are reliable,
so it would be safe to make the call; is that correct? I apologize
for rambling a bit, but I think my underlying question is as follows:
the man page for signal lists functions which are safe to call
from a signal handler---is it the case that only those functions should
be called even in a handler for a reliable signal?
2. The fflush calls are totally pointless, as stderr is
unbuffered. Am I missing something here, and am I
being harsh in thinking that the author was clueless? Other
than the fact that they are unsafe functions, they don't seem
to cause any problems. How bad is this ? Also, I should
mention that the disposition is reset to default by sigaction, and the
signals
being caught all have abort as there default action, so it seems
that the only real problem is that the code is somewhat silly. Again,
apologies for the rambling, but it seems that the only error here is
one of bad form. Is there a substantial problem with this code? It's
just exiting, so no harm done, right? Is there potentially a
substantial problem with this code?
.
- Follow-Ups:
- Re: unsafe functions from signal handler
- From: "Nils O. Selåsdal"
- Re: unsafe functions from signal handler
- From: Andrei Voropaev
- Re: unsafe functions from signal handler
- Prev by Date: Re: X Application Programming in Pascal: HELP!
- Next by Date: Re: unsafe functions from signal handler
- Previous by thread: Re: X Application Programming in Pascal: HELP!
- Next by thread: Re: unsafe functions from signal handler
- Index(es):
Relevant Pages
|