]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/mach/hurd/sigsuspend.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / mach / hurd / sigsuspend.c
CommitLineData
2b778ceb 1/* Copyright (C) 1991-2021 Free Software Foundation, Inc.
3dadfa7e 2
ebbad4cc 3 This file is part of the GNU C Library.
28f540f4 4
ebbad4cc 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 9
ebbad4cc
UD
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
41bdb6e2 13 Lesser General Public License for more details.
28f540f4 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
28f540f4 18
28f540f4
RM
19#include <errno.h>
20#include <hurd.h>
21#include <hurd/signal.h>
22#include <hurd/msg.h>
f5123211 23#include <sysdep-cancel.h>
28f540f4
RM
24
25/* Change the set of blocked signals to SET,
26 wait until a signal arrives, and restore the set of blocked signals. */
27int
bd2260a2 28__sigsuspend (const sigset_t *set)
28f540f4
RM
29{
30 struct hurd_sigstate *ss;
31 sigset_t newmask, oldmask, pending;
32 mach_port_t wait;
33 mach_msg_header_t msg;
f5123211 34 int cancel_oldtype;
28f540f4
RM
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
653d74f1 45 _hurd_sigstate_lock (ss);
28f540f4
RM
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. */
653d74f1 53 pending = _hurd_sigstate_pending (ss) & ~ss->blocked;
28f540f4
RM
54
55 /* Tell the signal thread to message us when a signal arrives. */
56 ss->suspended = wait;
653d74f1 57 _hurd_sigstate_unlock (ss);
28f540f4
RM
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. */
f5123211
ST
64
65 cancel_oldtype = LIBC_CANCEL_ASYNC();
28f540f4
RM
66 __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait,
67 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
f5123211 68 LIBC_CANCEL_RESET (cancel_oldtype);
28f540f4
RM
69 __mach_port_destroy (__mach_task_self (), wait);
70
653d74f1
JK
71 /* Restore the old mask and check for pending signals again. */
72 _hurd_sigstate_lock (ss);
73 ss->blocked = oldmask;
74 pending = _hurd_sigstate_pending(ss) & ~ss->blocked;
75 _hurd_sigstate_unlock (ss);
28f540f4
RM
76
77 if (pending)
78 /* Tell the signal thread to check for pending signals. */
8f0c527e
RM
79 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
80
28f540f4
RM
81 /* We've been interrupted! And a good thing, too.
82 Otherwise we'd never return.
83 That's right; this function always returns an error. */
84 errno = EINTR;
85 return -1;
86}
37ba7d66 87libc_hidden_def (__sigsuspend)
a9ddb793 88weak_alias (__sigsuspend, sigsuspend)