Re: unsafe functions from signal handler
- From: "Nils O. Selåsdal" <NOS@xxxxxxx>
- Date: Tue, 31 Jan 2006 14:26:34 +0100
bill pursell wrote:
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
If the main program is in the middle of updating the fields 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.
.
- References:
- unsafe functions from signal handler
- From: bill pursell
- unsafe functions from signal handler
- Prev by Date: Re: Newbie - Shared library
- Next by Date: Re: evecv/memory leak
- Previous by thread: Re: unsafe functions from signal handler
- Next by thread: Re: Newbie - Shared library
- Index(es):
Relevant Pages
|