News for hackers. Stuff that matters.
Re:A guide to Linux signals by danieltillett on Tuesday November 24, 2015 @12:09AM (#10619216)
Catching signals is a great way of catching nasty bugs in production code. I use them to be able to log information on the cause of an error before the code exits due to some sort of catastrophic bug (e.g. null pointer deference, etc). This also allows you to clean up to clean up temp files, etc. They are much nicer to use than the Windows equivalent.
Re:A guide to Linux signals by useerup on Tuesday November 24, 2015 @01:09AM (#10619378)
> They are much nicer to use than the Windows equivalent

Seriously? You find a system with global events where you must perform your own resource book-keeping to clean up the correct resources nicer than structured exception handling?

Re:A guide to Linux signals by danieltillett on Tuesday November 24, 2015 @02:15AM (#10619547)
Yes as soon as you have to support both 32 and 64 builds in a multi-threaded program that is using the C run time library. This of course is just my opinion :)
Re:A guide to Linux signals by pjc50 on Tuesday November 24, 2015 @02:54AM (#10619640)
Why is SEH a problem in that case? SEH is occasionally flaky but much nicer than trying to handle SEGV.
Re:A guide to Linux signals by rewqfdsa on Tuesday November 24, 2015 @01:02AM (#10619363)
> They are much nicer to use than the Windows equivalent.

Strongly disagree. It's hard to make different signals cooperate. Vectored exception handlers in Windows have built-in support for arbitrating between different users.

Re:A guide to Linux signals by ratboy666 on Tuesday November 24, 2015 @02:04AM (#10619520)
Linux (Unix) signals are per-process. What is hard about making signals cooperate? Are you referring to a signal generated while in a signal handler? raise() is supported on Windows, but kill() isn't (directly, signals don't seem to be well supported as an IPC mechanism on Windows -- although there appear to be kill() style mechanisms).
Re:A guide to Linux signals by rewqfdsa on Tuesday November 24, 2015 @04:16AM (#10619857)
> What is hard about making signals cooperate?

Library A wants to handle SIGSEGV for memory mapping X. Library B wants to handle SIGSEGV for memory mapping Y. Which of them calls sigaction? What if both do? What if then unload one of the libraries?

Windows handles this interaction sanely. Sigaction does not.

> raise() is supported on Windows, but kill()

Windows splits the jobs of signals into structured exceptions and APCs. You can definitely send an APC to another thread: https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...

Re:A guide to Linux signals by fulafel on Tuesday November 24, 2015 @05:49AM (#10620098)
It's actually alarmingly common for Windows C/C++ apps to paper over crashes with SEH try { } catch (segfault) { /* seems to work */ } this way. Even Microsoft's own apps used to do it, maybe they still do. You run into this when running random apps under a debugger.
Re:A guide to Linux signals by silon7 on Tuesday November 24, 2015 @09:39AM (#10620930)
There's nothing structured about core dumps. Better to do nothing so the developer can see a clean core dump.
Re:A guide to Linux signals by ratboy666 on Tuesday November 24, 2015 @06:19AM (#10620168)
sigaction() returns the old action. This permits chaining of the actions. Specifically for SIGSEGV, if Library B does not want the signal, it can invoke Library A (without caring what it is). Similarily, A can invoke B. "Unloading" cannot be done, unless you are aware of the load order. This is a general issue -- dlclose() is reference counted, and you wouldn't know if it actually unloaded the library.
Re:A guide to Linux signals by useerup on Tuesday November 24, 2015 @08:20AM (#10620490)
> Unloading" cannot be done, unless you are aware of the load order. This is a general issue -- dlclose() is reference counted, and you wouldn't know if it actually unloaded the library.

Yup. Which is exactly why Windows is more sane: No chaining, "unloading" (i.e. unsubscribing) can be done robustly. In the absence of a mechanism like SEH on Linux, signals are (mis)used. Signals are a crude, unstructured way of handling internal termination.

Re:A guide to Linux signals by pjc50 on Tuesday November 24, 2015 @02:52AM (#10619635)
Much of the IPC stuff Linux has to do with signals is done with window messages on Windows, which is usually nicer as you get to handle it in a defined state rather than, say, in the middle of a syscall.
Re:A guide to Linux signals by zurn on Tuesday November 24, 2015 @03:21AM (#10619709)
Signals are not generally used for IPC on Linux. Also you can handle them orderly along with other fd events using the standard & portable self-pipe pattern or Linux-specific signalfd.