Re: Is clock_nanosleep() async-signal safe?



Spoon wrote:

The Open Group Base Specifications Issue 6 states:

3.26 Async-Signal-Safe Function

A function that may be invoked, without restriction, from
signal-catching functions. No function is async-signal-safe unless
explicitly described as such.

The older Single UNIX Specification, Version 2 stated:

* When signal-catching functions are invoked asynchronously
with process execution, the behaviour of some of the functions defined
by this document is unspecified if they are called from a
signal-catching function.

The following table defines a set of interfaces that are
either reentrant or not interruptible by signals and are async-signal
safe. Therefore applications may invoke them, without restriction, from
signal-catching functions:

[...]
sigismember() signal() sigpending() sigprocmask() sigsuspend() sleep()
[...]

All functions not in the above table are considered to be unsafe with
respect to signals.

sleep() used to be considered Async-Signal-Safe.
Is this not true anymore?
http://www.opengroup.org/onlinepubs/000095399/functions/sleep.html
(sleep is not explicitly described as Async-Signal-Safe.)

sleep() is still async-signal-safe. SUSv3 has much the same text, and
list of functions, that you quoted from SUSv2. See the end of XSH6
section 2.4.3.

Is clock_nanosleep() also not Async-Signal-Safe?
http://www.opengroup.org/onlinepubs/009695399/functions/clock_nanosleep.html

clock_nanosleep() is not in the list in XSH6 2.4.3, so it is not
async-signal-safe (neither is nanosleep()).

In general, is it legal to sleep in a signal handler?

Only using sleep().

--
Geoff Clare <netnews@xxxxxxxxxxxxx>
.



Relevant Pages

  • Re: Is clock_nanosleep() async-signal safe?
    ... No function is async-signal-safe unless explicitly described as such. ... When signal-catching functions are invoked asynchronously with process execution, the behaviour of some of the functions defined by this document is unspecified if they are called from a signal-catching function. ... Therefore applications may invoke them, without restriction, from signal-catching functions: ... I had always assumed that sleep() was a fancy wrapper around nanosleep. ...
    (comp.unix.programmer)
  • Is clock_nanosleep() async-signal safe?
    ... The Open Group Base Specifications Issue 6 states: ... No function is async-signal-safe unless explicitly described as such. ... When signal-catching functions are invoked asynchronously with process execution, the behaviour of some of the functions defined by this document is unspecified if they are called from a signal-catching function. ... Therefore applications may invoke them, without restriction, from signal-catching functions: ...
    (comp.unix.programmer)