Re: unsafe functions from signal handler
- From: "bill pursell" <bill.pursell@xxxxxxxxx>
- Date: 4 Feb 2006 00:48:19 -0800
Nils O. Selåsdal wrote:
bill pursell wrote:
I came upon the following code yesterday in a signal handler:If the main program is in the middle of updating the fields
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
in the FILE, and a signal occurse, reading/writing half garbled
members havoc might follow (there are various X_unlocked functions)
FILE operations are normally locked though on posixishy systems with
pthreads (yes - even if your program doesn't use threads - just as with
malloc :-) so you risk deadlocking your program.
Is the deadlock condition still possible if the sigaction resets
the signal dispostion to abort? (so the first signal enters the
handler which calls printf, but the second signal causes an abort)
.
- Prev by Date: cron wrapper (ugh1)
- Next by Date: Re: cron wrapper (ugh1)
- Previous by thread: cron wrapper (ugh1)
- Next by thread: Re: unsafe functions from signal handler
- Index(es):