Marin D wrote:

> Could someone give me some light on the SA_RESTART flag used by
> sigaction() as the man page and the *info file contain contrary
> information
> 
> [snip from the man page]
> 
>               SA_RESTART
>                      The opposite to SA_ONESHOT, do  not  restore
>                      the  signal  action.  This provides behavior
>                      compatible with BSD signal semantics.

This is wrong. To get the opposite behaviour to SA_ONESHOT (i.e. BSD
semantics), simply don't specify SA_ONESHOT.

It's not what my sigaction(2) manpage says, either:

              SA_RESTART
                     Provide behaviour compatible with BSD signal
                     semantics  by  making  certain  system calls
                     restartable across signals.

> This seems to be right. I tested it. The SA_RESTART makes the signal
> action not be changed with the default action once raised.

No, it's the lack of SA_ONESHOT that causes the signal disposition not
to be reset to its default.

> [snip from the libc info file]
> 
>  - Macro: int SA_RESTART
>      This flag controls what happens when a signal is delivered during
>      certain primitives (such as `open', `read' or `write'), and the
>      signal handler returns normally.  There are two alternatives: the
>      library function can resume, or it can return failure with error
>      code `EINTR'.
> 
>      The choice is controlled by the `SA_RESTART' flag for the
>      particular kind of signal that was delivered.  If the flag is set,
>      returning from a handler resumes the library function.  If the
>      flag is clear, returning from a handler makes the function fail.

This is correct. SA_RESTART => BSD semantics, no SA_RESTART => SysV
semantics.

> Well.. I have no idea how to raise signal during open() and to test
> this...

Install a handler for SIGALRM, use alarm() to cause a SIGALRM to be
generated after a given delay, and then perform an open() on a tty
device or FIFO.

> So , why is the info contrary and is the man page correct as I think?

No, the man page is wrong.

> And how to acquire behaviour as explained by the *info file i.e. to make
> i/o functions "atomic" in the way of resuming operation and not returning
> EINTR?

Specify SA_RESTART.

Basically to get the behaviour of BSD's signal() function, you set the
`sa_flags' field to SA_RESTART, whereas to get the behaviour of the
SysV signal() function, you would set it to (SA_ONESHOT | SA_NODEFER).

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to