From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 72F317F891 for ; Wed, 19 Mar 2014 23:19:28 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jesper.louis.andersen@gmail.com) identity=pra; client-ip=209.85.223.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jesper.louis.andersen@gmail.com"; x-sender="jesper.louis.andersen@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of jesper.louis.andersen@gmail.com designates 209.85.223.173 as permitted sender) identity=mailfrom; client-ip=209.85.223.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jesper.louis.andersen@gmail.com"; x-sender="jesper.louis.andersen@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f173.google.com) identity=helo; client-ip=209.85.223.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jesper.louis.andersen@gmail.com"; x-sender="postmaster@mail-ie0-f173.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As8BACYXKlPRVd+tlGdsb2JhbABSCINBV4MHv0OBFggWDgEBAQEHCwsJEiqCJQEBAQMBIx0BGx0BAwELBgUEBzcCAiIBEQEFARwGEwmHWwEDCQgNoTaMDlGDDpcRChknDWSGQREBBQyOA1YHgm+BSQSYR5BCGCmEWzw X-IPAS-Result: As8BACYXKlPRVd+tlGdsb2JhbABSCINBV4MHv0OBFggWDgEBAQEHCwsJEiqCJQEBAQMBIx0BGx0BAwELBgUEBzcCAiIBEQEFARwGEwmHWwEDCQgNoTaMDlGDDpcRChknDWSGQREBBQyOA1YHgm+BSQSYR5BCGCmEWzw X-IronPort-AV: E=Sophos;i="4.97,689,1389740400"; d="scan'208";a="53347853" Received: from mail-ie0-f173.google.com ([209.85.223.173]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 19 Mar 2014 23:19:27 +0100 Received: by mail-ie0-f173.google.com with SMTP id rl12so9719247iec.32 for ; Wed, 19 Mar 2014 15:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=wyjafbLVPAoLbQvrMIVK5gTwn27ve+EUIK+1aBEy1/4=; b=aufk2EB3I7ivT8cFZdooGjOhvveLodVg0bebdVLXvieUznnyPW6u/TVU8/6BRDHWrN D36HetnA17J1k2cMh8rIo4ckwg5mMENeRl3zHSeU5GPBVfn1wODUaJNPNsInfpyOYq6R lLT/fPGrm6R/CNzdvt43BTm2p8QiHbwEeLAd8A0NQzDB0Qi7WJ9SjLrFZDJLt+f5MSlk 5/YEH88gHS+TL21VePZoczrSQ3aoeMXnF4usrxPni87sAztpSt4UmIprJ7TGILVdPit8 jC82AUVP+u+TTHseePs5unzSd+NWvA0L9zgqm+LUVofHjSXwkHcXWIlTu/y79BASMA2r mnjA== X-Received: by 10.50.79.135 with SMTP id j7mr28188431igx.32.1395267566052; Wed, 19 Mar 2014 15:19:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.239.208 with HTTP; Wed, 19 Mar 2014 15:19:11 -0700 (PDT) In-Reply-To: <532A0A5E.6070107@fugmann.net> References: <532A0A5E.6070107@fugmann.net> From: Jesper Louis Andersen Date: Wed, 19 Mar 2014 23:19:11 +0100 Message-ID: To: Anders Peter Fugmann Cc: caml-list Content-Type: multipart/alternative; boundary=089e0122a754a4658f04f4fd0bbc Subject: Re: [Caml-list] Bug when printing from signal handlers? --089e0122a754a4658f04f4fd0bbc Content-Type: text/plain; charset=UTF-8 On Wed, Mar 19, 2014 at 10:21 PM, Anders Peter Fugmann wrote: > Is printing from a signal handler illegal? FWIW, that is illegal in some operating systems. I have seen it in one case at least: * Linux with threads. printf in C is protected by a mutex. Suppose we are inside the printf, with the mutex locked and then we get a signal. We run the handler, and it wants to print out debug information. Welcome deadlock! * Many system calls are not safe in the signal handler. FreeBSD has a list in sigaction(2) for instance. See http://www.freebsd.org/cgi/man.cgi?query=sigaction&apropos=0&sektion=0&manpath=FreeBSD+10.0-RELEASE&arch=default&format=html In practice, you should probably just set a flag in the signal handler and then handle that in a main loop of the program. Doing advanced stuff in a signal handler is usually dangerous non-compatible territory. -- J. --089e0122a754a4658f04f4fd0bbc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

= On Wed, Mar 19, 2014 at 10:21 PM, Anders Peter Fugmann &l= t;anders@fugmann.ne= t> wrote:
Is printing from a signal handler illegal?

FWIW, that is illegal in some operating systems. I have seen it in one = case at least:

* Linux with threads. printf in C is protected by a mutex. Suppose= we are inside the printf, with the mutex locked and then we get a signal. = We run the handler, and it wants to print out debug information. Welcome de= adlock!
* Many system calls are not safe in the signal h= andler. FreeBSD has a list in sigaction(2) for instance. See


In practice= , you should probably just set a flag in the signal handler and then handle= that in a main loop of the program. Doing advanced stuff in a signal handl= er is usually dangerous non-compatible territory.


--
J.
--089e0122a754a4658f04f4fd0bbc--