]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/sigsuspend.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / mach / hurd / sigsuspend.c
1 /* Copyright (C) 1991-2019 Free Software Foundation, Inc.
2
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
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. */
26 int
27 __sigsuspend (const sigset_t *set)
28 {
29 struct hurd_sigstate *ss;
30 sigset_t newmask, oldmask, pending;
31 mach_port_t wait;
32 mach_msg_header_t msg;
33
34 if (set != NULL)
35 /* Crash before locking. */
36 newmask = *set;
37
38 /* Get a fresh port we will wait on. */
39 wait = __mach_reply_port ();
40
41 ss = _hurd_self_sigstate ();
42
43 __spin_lock (&ss->lock);
44
45 oldmask = ss->blocked;
46 if (set != NULL)
47 /* Change to the new blocked signal mask. */
48 ss->blocked = newmask & ~_SIG_CANT_MASK;
49
50 /* Notice if any pending signals just became unblocked. */
51 pending = ss->pending & ~ss->blocked;
52
53 /* Tell the signal thread to message us when a signal arrives. */
54 ss->suspended = wait;
55 __spin_unlock (&ss->lock);
56
57 if (pending)
58 /* Tell the signal thread to check for pending signals. */
59 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
60
61 /* Wait for the signal thread's message. */
62 __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait,
63 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
64 __mach_port_destroy (__mach_task_self (), wait);
65
66 __spin_lock (&ss->lock);
67 ss->blocked = oldmask; /* Restore the old mask. */
68 pending = ss->pending & ~ss->blocked; /* Again check for pending signals. */
69 __spin_unlock (&ss->lock);
70
71 if (pending)
72 /* Tell the signal thread to check for pending signals. */
73 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
74
75 /* We've been interrupted! And a good thing, too.
76 Otherwise we'd never return.
77 That's right; this function always returns an error. */
78 errno = EINTR;
79 return -1;
80 }
81 libc_hidden_def (__sigsuspend)
82 weak_alias (__sigsuspend, sigsuspend)