OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [sys/] [linux/] [sigwait.c] - Blame information for rev 207

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* Implementation of sigwait function from POSIX.1c.
2
   Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
5
 
6
   The GNU C Library is free software; you can redistribute it and/or
7
   modify it under the terms of the GNU Lesser General Public
8
   License as published by the Free Software Foundation; either
9
   version 2.1 of the License, or (at your option) any later version.
10
 
11
   The GNU C Library is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   Lesser General Public License for more details.
15
 
16
   You should have received a copy of the GNU Lesser General Public
17
   License along with the GNU C Library; if not, write to the Free
18
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19
   02111-1307 USA.  */
20
 
21
#include <errno.h>
22
#include <signal.h>
23
#include <stddef.h>             /* For NULL.  */
24
 
25
#include <machine/weakalias.h>
26
 
27
/* This is our dummy signal handler we use here.  */
28
static void ignore_signal (int sig);
29
 
30
/* Place where to remember which signal we got.  Please note that this
31
   implementation cannot be used for the threaded libc.  The
32
   libpthread must provide an own version.  */
33
static int was_sig;
34
 
35
 
36
int
37
__sigwait (const sigset_t *set, int *sig)
38
{
39
  sigset_t tmp_mask;
40
  struct sigaction saved[NSIG];
41
  struct sigaction action;
42
  int save_errno;
43
  int this;
44
 
45
  /* Prepare set.  */
46
  sigfillset (&tmp_mask);
47
 
48
  /* Unblock all signals in the SET and register our nice handler.  */
49
  action.sa_handler = ignore_signal;
50
  action.sa_flags = 0;
51
  sigfillset (&action.sa_mask); /* Block all signals for handler.  */
52
 
53
  /* Make sure we recognize error conditions by setting WAS_SIG to a
54
     value which does not describe a legal signal number.  */
55
  was_sig = -1;
56
 
57
  for (this = 1; this < NSIG; ++this)
58
    if (sigismember (set, this))
59
      {
60
        /* Unblock this signal.  */
61
        sigdelset (&tmp_mask, this);
62
 
63
        /* Register temporary action handler.  */
64
        if (__sigaction (this, &action, &saved[this]) != 0)
65
          goto restore_handler;
66
      }
67
 
68
  /* Now we can wait for signals.  */
69
  __sigsuspend (&tmp_mask);
70
 
71
 restore_handler:
72
  save_errno = errno;
73
 
74
  while (--this >= 1)
75
    if (sigismember (set, this))
76
      /* We ignore errors here since we must restore all handlers.  */
77
      __sigaction (this, &saved[this], NULL);
78
 
79
  errno = (save_errno);
80
 
81
  /* Store the result and return.  */
82
  *sig = was_sig;
83
  return was_sig == -1 ? -1 : 0;
84
}
85
weak_alias (__sigwait, sigwait)
86
 
87
 
88
static void
89
ignore_signal (int sig)
90
{
91
  /* Remember the signal.  */
92
  was_sig = sig;
93
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.