Re: Signal handler and longjmp question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Dec 9, 2007 2:12 PM, Yi Wang <yi.w@xxxxxxxx> 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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux