Back to index

glibc  2.9
Functions
sigaction.c File Reference
#include <sysdep.h>
#include <errno.h>
#include <stddef.h>
#include <signal.h>

Go to the source code of this file.

Functions

int __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)

Function Documentation

int __sigaction ( int  sig,
const struct sigaction act,
struct sigaction oact 
)

Definition at line 28 of file sigaction.c.

{
  sighandler_t handler;
  int save;

  if (sig <= 0 || sig >= NSIG)
    {
      __set_errno (EINVAL);
      return -1;
    }

  if (act == NULL)
    {
      if (oact == NULL)
       return 0;
      /* Race condition, but this is the only way to do it.  */
      handler = signal (sig, SIG_IGN);
      if (handler == SIG_ERR)
       return -1;
      save = errno;
      (void) signal (sig, handler);
      __set_errno (save);
    }
  else
    {
      int i;

      if (act->sa_flags != 0)
       {
       unimplemented:
         __set_errno (ENOSYS);
         return -1;
       }

      for (i = 1; i < NSIG; ++i)
       if (__sigismember (&act->sa_mask, i))
         goto unimplemented;

      handler = signal (sig, act->sa_handler);
      if (handler == SIG_ERR)
       return -1;
    }

  if (oact != NULL)
    {
      oact->sa_handler = handler;
      __sigemptyset (&oact->sa_mask);
      oact->sa_flags = 0;
    }

  return 0;
}

Here is the call graph for this function: