]>
Commit | Line | Data |
---|---|---|
ebbad4cc UD |
1 | /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
28f540f4 | 3 | |
ebbad4cc UD |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public License as | |
6 | published by the Free Software Foundation; either version 2 of the | |
7 | License, or (at your option) any later version. | |
28f540f4 | 8 | |
ebbad4cc UD |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Library General Public License for more details. | |
28f540f4 | 13 | |
ebbad4cc UD |
14 | You should have received a copy of the GNU Library General Public |
15 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
16 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 | Boston, MA 02111-1307, USA. */ | |
28f540f4 | 18 | |
28f540f4 RM |
19 | #include <errno.h> |
20 | #include <hurd.h> | |
21 | #include <hurd/signal.h> | |
22 | #include <hurd/msg.h> | |
23 | ||
24 | /* Change the set of blocked signals to SET, | |
25 | wait until a signal arrives, and restore the set of blocked signals. */ | |
ebbad4cc | 26 | /* XXX should be __sigsuspend ? */ |
28f540f4 | 27 | int |
ebbad4cc UD |
28 | sigsuspend (set) |
29 | const sigset_t *set; | |
28f540f4 RM |
30 | { |
31 | struct hurd_sigstate *ss; | |
32 | sigset_t newmask, oldmask, pending; | |
33 | mach_port_t wait; | |
34 | mach_msg_header_t msg; | |
35 | ||
36 | if (set != NULL) | |
37 | /* Crash before locking. */ | |
38 | newmask = *set; | |
39 | ||
40 | /* Get a fresh port we will wait on. */ | |
41 | wait = __mach_reply_port (); | |
42 | ||
43 | ss = _hurd_self_sigstate (); | |
44 | ||
45 | __spin_lock (&ss->lock); | |
46 | ||
47 | oldmask = ss->blocked; | |
48 | if (set != NULL) | |
49 | /* Change to the new blocked signal mask. */ | |
50 | ss->blocked = newmask & ~_SIG_CANT_MASK; | |
51 | ||
52 | /* Notice if any pending signals just became unblocked. */ | |
53 | pending = ss->pending & ~ss->blocked; | |
54 | ||
55 | /* Tell the signal thread to message us when a signal arrives. */ | |
56 | ss->suspended = wait; | |
57 | __spin_unlock (&ss->lock); | |
58 | ||
59 | if (pending) | |
60 | /* Tell the signal thread to check for pending signals. */ | |
8f0c527e | 61 | __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ()); |
28f540f4 RM |
62 | |
63 | /* Wait for the signal thread's message. */ | |
64 | __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait, | |
65 | MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); | |
66 | __mach_port_destroy (__mach_task_self (), wait); | |
67 | ||
68 | __spin_lock (&ss->lock); | |
69 | ss->blocked = oldmask; /* Restore the old mask. */ | |
70 | pending = ss->pending & ~ss->blocked; /* Again check for pending signals. */ | |
71 | __spin_unlock (&ss->lock); | |
72 | ||
73 | if (pending) | |
74 | /* Tell the signal thread to check for pending signals. */ | |
8f0c527e RM |
75 | __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ()); |
76 | ||
28f540f4 RM |
77 | /* We've been interrupted! And a good thing, too. |
78 | Otherwise we'd never return. | |
79 | That's right; this function always returns an error. */ | |
80 | errno = EINTR; | |
81 | return -1; | |
82 | } |