[Toybox] signal or xsignal for sigatexit()?

Gavin Howard gavin.d.howard at gmail.com
Fri Sep 21 17:06:23 PDT 2018


Rob,

I'm not better than you at C, but I did have to dig deep into this for
my `bc', so I thought I would offer my 2 cents.

First off, sigaction() is complex, but it is better in every other
way. It gives you a lot more options, has better ways of querying the
current signal handlers, has better behavior, etc.

For multithreaded programs on Linux, the man page
(http://man7.org/linux/man-pages/man2/signal.2.html) says that the
behavior of signal() is unspecified. It also encourages the use of
sigaction().

Second, the GNU page for glibc's signal() and sigaction()
(http://www.gnu.org/software/libc/manual/html_node/Signal-and-Sigaction.html)
says that they discourage the use of both signal() and sigaction() in
the same program.

There is one more wrinkle, but I don't think it will be a problem for
toybox: signal() is more widely available. However, sigaction() has
been defined in POSIX since at least 2001, and you told me that you
generally require POSIX 2008, so I don't think that availability will
be a problem at all.

Also, my `bc' already uses sigaction().

Thus, I suggest you use xsignal()/sigaction(). I can send you a patch
for that. Would you want me to do that? And if so, would you want it
before or after the next release?

Gavin Howard

On Fri, Sep 21, 2018 at 5:30 PM Rob Landley <rob at landley.net> wrote:
>
> signal() defaults to SA_RESTART, xsignal() uses sigaction() which does not. I'm
> not sure which is correct? (It's currently using signal() and things seem ok
> with what?)
>
> *shrug* The readall() code assumes no SA_RESTART. The main downside of signal by
> default I'm aware of is having to poll before read() when you want a timeout via
> alarm() (unless you siglongjmp)...
>
> Just wondering if anybody out there better than me at C has an opinion. :)
>
> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net



More information about the Toybox mailing list