linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: "Richard B. Johnson" <root@chaos.analogic.com>
Cc: Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: BUG (non-kernel), can hurt developers.
Date: Wed, 26 Nov 2003 10:29:54 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.58.0311261021400.1524@home.osdl.org> (raw)
In-Reply-To: <Pine.LNX.4.53.0311261153050.10929@chaos>


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

  parent reply	other threads:[~2003-11-26 18:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-26 16:54 BUG (non-kernel), can hurt developers Richard B. Johnson
2003-11-26 17:21 ` YOSHIFUJI Hideaki / 吉藤英明
2003-11-26 18:29 ` Linus Torvalds [this message]
2003-11-26 18:55   ` Richard B. Johnson
2003-11-26 19:33     ` Jamie Lokier
2003-11-26 20:17       ` Richard B. Johnson
2003-11-26 20:42         ` Jamie Lokier
2003-11-26 18:59   ` YOSHIFUJI Hideaki / 吉藤英明
2003-11-27 20:41   ` Mikulas Patocka
2003-11-28  7:18   ` Tomas Szepe
2003-11-28 10:29 Andries.Brouwer
2003-11-28 17:22 ` Chris Friesen
2003-11-28 21:21 Andries.Brouwer
2003-11-28 21:38 ` Chris Friesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.58.0311261021400.1524@home.osdl.org \
    --to=torvalds@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=root@chaos.analogic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).