1 /* Copyright (C) 1991-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
22 #include <hurd/signal.h>
24 /* If ACT is not NULL, change the action for SIG to *ACT.
25 If OACT is not NULL, put the old action for SIG in *OACT. */
27 __libc_sigaction (int sig
, const struct sigaction
*act
,
28 struct sigaction
*oact
)
30 struct hurd_sigstate
*ss
;
31 struct sigaction a
, old
;
34 if (act
!= NULL
&& act
->sa_handler
!= SIG_DFL
35 && ((__sigmask (sig
) & _SIG_CANT_MASK
) || act
->sa_handler
== SIG_ERR
))
36 return __hurd_fail (EINVAL
);
38 /* Copy so we fault before taking locks. */
42 ss
= _hurd_self_sigstate ();
44 __spin_lock (&ss
->critical_section_lock
);
45 _hurd_sigstate_lock (ss
);
46 old
= _hurd_sigstate_actions (ss
) [sig
];
48 _hurd_sigstate_actions (ss
) [sig
] = a
;
50 if (act
!= NULL
&& sig
== SIGCHLD
51 && (a
.sa_flags
& SA_NOCLDSTOP
) != (old
.sa_flags
& SA_NOCLDSTOP
))
53 _hurd_sigstate_unlock (ss
);
55 /* Inform the proc server whether or not it should send us SIGCHLD for
56 stopped children. We do this in a critical section so that no
57 SIGCHLD can arrive in the middle and be of indeterminate status. */
59 __proc_mod_stopchild (port
, !(a
.sa_flags
& SA_NOCLDSTOP
)));
61 _hurd_sigstate_lock (ss
);
62 pending
= _hurd_sigstate_pending (ss
) & ~ss
->blocked
;
64 else if (act
!= NULL
&& (a
.sa_handler
== SIG_IGN
|| a
.sa_handler
== SIG_DFL
))
65 /* We are changing to an action that might be to ignore SIG signals.
66 If SIG is blocked and pending and the new action is to ignore it, we
67 must remove it from the pending set now; if the action is changed
68 back and then SIG is unblocked, the signal pending now should not
69 arrive. So wake up the signal thread to check the new state and do
71 pending
= _hurd_sigstate_pending (ss
) & __sigmask (sig
);
75 _hurd_sigstate_unlock (ss
);
76 __spin_unlock (&ss
->critical_section_lock
);
79 __msg_sig_post (_hurd_msgport
, 0, 0, __mach_task_self ());
86 libc_hidden_def (__libc_sigaction
)