Back to index

glibc  2.9
Functions | Variables
sigwait.c File Reference
#include <errno.h>
#include <signal.h>
#include <stddef.h>
#include <sysdep-cancel.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static void ignore_signal (int sig)
static int do_sigwait (const sigset_t *set, int *sig)
int __sigwait (const sigset_t *set, int *sig)
 libc_hidden_def (weak_alias(__sigwait)

Variables

static int was_sig

Function Documentation

int __sigwait ( const sigset_t set,
int sig 
)

Definition at line 87 of file sigwait.c.

{
  if (SINGLE_THREAD_P)
    return do_sigwait (set, sig);

  int oldtype = LIBC_CANCEL_ASYNC ();

  int result = do_sigwait (set, sig);

  LIBC_CANCEL_RESET (oldtype);

  return result;
}

Here is the call graph for this function:

static int do_sigwait ( const sigset_t set,
int sig 
) [static]

Definition at line 36 of file sigwait.c.

{
  sigset_t tmp_mask;
  struct sigaction saved[NSIG];
  struct sigaction action;
  int save_errno;
  int this;

  /* Prepare set.  */
  __sigfillset (&tmp_mask);

  /* Unblock all signals in the SET and register our nice handler.  */
  action.sa_handler = ignore_signal;
  action.sa_flags = 0;
  __sigfillset (&action.sa_mask);  /* Block all signals for handler.  */

  /* Make sure we recognize error conditions by setting WAS_SIG to a
     value which does not describe a legal signal number.  */
  was_sig = -1;

  for (this = 1; this < NSIG; ++this)
    if (__sigismember (set, this))
      {
       /* Unblock this signal.  */
       __sigdelset (&tmp_mask, this);

       /* Register temporary action handler.  */
       if (__sigaction (this, &action, &saved[this]) != 0)
         goto restore_handler;
      }

  /* Now we can wait for signals.  */
  __sigsuspend (&tmp_mask);

 restore_handler:
  save_errno = errno;

  while (--this >= 1)
    if (__sigismember (set, this))
      /* We ignore errors here since we must restore all handlers.  */
      __sigaction (this, &saved[this], NULL);

  __set_errno (save_errno);

  /* Store the result and return.  */
  *sig = was_sig;
  return was_sig == -1 ? -1 : 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ignore_signal ( int  sig) [static]

Here is the caller graph for this function:

libc_hidden_def ( weak_alias __sigwait)

Definition at line 100 of file sigwait.c.

{
  /* Remember the signal.  */
  was_sig = sig;
}

Variable Documentation

int was_sig [static]

Definition at line 32 of file sigwait.c.