linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Steve Graegert" <graegerts@gmail.com>
To: Yi Wang <yi.w@live.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Signal handler and longjmp question
Date: Sun, 9 Dec 2007 15:06:22 +0100	[thread overview]
Message-ID: <6a00c8d50712090606k6882a52bv2735ee3d746ba7a8@mail.gmail.com> (raw)
In-Reply-To: <BLU125-W33C6B6DA207B733BBC1F7AEA6A0@phx.gbl>

On Dec 9, 2007 2:12 PM, Yi Wang <yi.w@live.com> wrote:
>
> Hi, all
>     I read from some book that a signal handler can either return or call exit, abort or longjmp, it is permitted by ANSI C.
>     However, I remember that lonjmp never returns, which in turn causes the signal handler can not return. In that case, the kernel will think the program is in signal handler forever, am I right?
>     IMHO, I think that is too bad...

This is not the case.  Rather than returning to the interrupted
statement, longjmp causes control to be sent back to the setjmp() in
the main program.  Since POSIX.1 does not specify whether setjmp and
longjmp save or restore the current set of blocked signals the use of
sigsetjmp/siglongjmp is recommended if signals must be handled.

longjmp does not return because setjmp first saves the environment to
which longjmp can return from another point in the program.  After
returning to setjmp the process does not know that it "has been
returned" from somewhere else.  So, technically longjmp cannot not
return.

A problem with the use of setjmp/longjmp is that the environment will
not be cleaned up (closing FDs, flushing buffers, freeing
heap-allocated memory, and the like).

	\Steve

--

Steve Grägert
DigitalEther.de
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2007-12-09 14:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <S1751093AbXLIMzQ/20071209125516Z+241@vger.kernel.org>
2007-12-09 13:12 ` Signal handler and longjmp question Yi Wang
2007-12-09 14:06   ` Steve Graegert [this message]
2007-12-10  6:03     ` Yi Wang

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=6a00c8d50712090606k6882a52bv2735ee3d746ba7a8@mail.gmail.com \
    --to=graegerts@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=yi.w@live.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).