Re: strange definitions of SA_* flags

Linus Torvalds (
Tue, 15 Aug 1995 07:29:43 +0300

Ben Wing: "strange definitions of SA_* flags" (Aug 14, 3:53):
> In the process of trying to write signal code that works over a
> variety of systems, I've discovered some things in the sigaction()
> flags in Linux that are incompatible with other systems.
> Here's what the man page says:
> Restore the signal action to the default
> state once the signal handler has been
> called. This is the default behavior.

I'm told this is the same as SA_RESETHAND on other systems. The names
under linux are made up by yours truly, as I didn't have any
documentation for other systems, so I just made the sigaction() stuff to
suit myself. Interestingly, I ended up with almost exactly the same
flags as SVR4, but I didn't get the names right ;-)

> The opposite to SA_ONESHOT, do not restore
> the signal action. This provides behavior
> compatible with BSD signal semantics.

The man-page is incorrect. This is not what SA_RESTART does. The
opposite of SA_ONESHOT is simply to not set the SA_ONESHOT flag, which
will leave the signal handler in place.

The man-page is partly correct, though: the flag is there for BSD
compatible behaviour, and setting this flag will make certain system
calls restartable across signals (not all of them: even original BSD
didn't restart more than a few system calls, it seems).

> Do not prevent the signal from being
> received from within its own signal handler.

I'm told this is called SA_NODEFER on SVR4. There may be some slight
differences in operation between the SVR4 flag and the linux flag,
especially with older kernels. Old kernels used to zero out the signal
mask completely when this flag was set, even when it came to other
signals than the one we were installing. When somebody told me that the
SVR4 semantics don't do that, I changed linux to do as SVR4 seems to do,
but this behaviour is reasonably recent (ie 1.3.x).

We talked about this with hjl at some point, and newer library header
files _may_ alias these to the SVR names. I haven't checked, though.
But if you have a program that uses SA_NODEFER etc, you could do
something like this:

#ifndef SA_NODEFER
#ifdef SA_NOMASK
#define SA_NODEFER SA_NOMASK /* linux calls it SA_NOMASK */
#error This program needs SA_NODEFER

That should make it work on linux..