lkml.org 
[lkml]   [2003]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: BUG (non-kernel), can hurt developers.

On Wed, 26 Nov 2003, Richard B. Johnson wrote:
>
> Note to hackers. Even though this is a lib-c bug

It's not.

It's a bug in your program.

You can't just randomly use library functions in signal handlers. You can
only use a very specific "signal-safe" set.

POSIX lists that set in 3.3.1.3 (3f), and says

"All POSIX.1 functions not in the preceding table and all
functions defined in the C standard {2} not stated to be callable
from a signal-catching function are considered to be /unsafe/
with respect to signals. .."

typos mine.

The thing is, they have internal state that makes then non-reentrant (and
note that even the re-entrant ones might not be signal-safe, since they
may have deadlock issues: being thread-safe is _not_ the same as being
signal-safe).

In other words, if you want to do complex things from signals, you should
really just set a flag (of type "sigatomic_t") and have your main loop do
them. Or you have to be very very careful and only use stuff that is
defined to be signal-safe (mainly core system calls - stuff like <stdio.h>
is right out).

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-11-18 23:46    [W:0.044 / U:8.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site