1 /* vi: set sw=4 ts=4: */
4 * Copyright (C) 2003 by Erik Andersen <andersen@uclibc.org>
6 * This program 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.
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.
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
26 #if defined __UCLIBC_HAS_REALTIME__
28 int sigwait(const sigset_t *set, int *sig)
30 int ret = sigwaitinfo(set, NULL);
38 #else /* __UCLIBC_HAS_REALTIME__ */
39 /* variant without REALTIME extensions */
41 static smallint was_sig; /* obviously not thread-safe */
43 static void ignore_signal(int sig)
48 int sigwait (const sigset_t *set, int *sig)
51 struct sigaction saved[NSIG];
52 struct sigaction action;
57 __sigfillset (&tmp_mask);
59 /* Unblock all signals in the SET and register our nice handler. */
60 action.sa_handler = ignore_signal;
62 __sigfillset (&action.sa_mask); /* Block all signals for handler. */
64 /* Make sure we recognize error conditions by setting WAS_SIG to a
65 value which does not describe a legal signal number. */
68 for (this = 1; this < NSIG; ++this)
69 if (__sigismember (set, this))
71 /* Unblock this signal. */
72 __sigdelset (&tmp_mask, this);
74 /* Register temporary action handler. */
75 /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */
76 /* (so, will it work correctly if set has, say, SIGSTOP?) */
77 if (sigaction (this, &action, &saved[this]) != 0)
81 /* Now we can wait for signals. */
82 sigsuspend (&tmp_mask);
88 if (__sigismember (set, this))
89 /* We ignore errors here since we must restore all handlers. */
90 sigaction (this, &saved[this], NULL);
92 __set_errno (save_errno);
94 /* Store the result and return. */
96 return was_sig == -1 ? -1 : 0;
98 #endif /* __UCLIBC_HAS_REALTIME__ */