]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* _hurd_ctty_output -- Do an output RPC and generate SIGTTOU if necessary. |
dff8da6b | 2 | Copyright (C) 1995-2024 Free Software Foundation, Inc. |
c84142e8 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
c84142e8 | 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 | |
c84142e8 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 RM |
18 | |
19 | #include <hurd.h> | |
20 | #include <hurd/signal.h> | |
21 | ||
22 | /* Call *RPC on PORT and/or CTTY. If a call on CTTY returns EBACKGROUND, | |
23 | generate SIGTTOU if appropriate. */ | |
24 | ||
25 | error_t | |
26 | _hurd_ctty_output (io_t port, io_t ctty, error_t (*rpc) (io_t)) | |
27 | { | |
28f540f4 | 28 | if (ctty == MACH_PORT_NULL) |
1d67062e | 29 | return (*rpc) (port); |
28f540f4 RM |
30 | else |
31 | { | |
1d67062e RM |
32 | struct hurd_sigstate *ss = _hurd_self_sigstate (); |
33 | error_t err; | |
28f540f4 | 34 | |
1d67062e | 35 | do |
28f540f4 | 36 | { |
653d74f1 JK |
37 | struct sigaction *actions; |
38 | ||
1d67062e RM |
39 | /* Don't use the ctty io port if we are blocking or ignoring |
40 | SIGTTOU. We redo this check at the top of the loop in case | |
41 | the signal handler changed the state. */ | |
653d74f1 JK |
42 | _hurd_sigstate_lock (ss); |
43 | actions = _hurd_sigstate_actions (ss); | |
34a5a146 | 44 | if (__sigismember (&ss->blocked, SIGTTOU) |
653d74f1 | 45 | || actions[SIGTTOU].sa_handler == SIG_IGN) |
28f540f4 RM |
46 | err = EIO; |
47 | else | |
1d67062e | 48 | err = 0; |
653d74f1 | 49 | _hurd_sigstate_unlock (ss); |
1d67062e RM |
50 | |
51 | if (err) | |
52 | return (*rpc) (port); | |
53 | ||
54 | err = (*rpc) (ctty); | |
55 | if (err == EBACKGROUND) | |
28f540f4 | 56 | { |
1d67062e RM |
57 | if (_hurd_orphaned) |
58 | /* Our process group is orphaned, so we never generate a | |
59 | signal; we just fail. */ | |
60 | err = EIO; | |
61 | else | |
62 | { | |
63 | /* Send a SIGTTOU signal to our process group. | |
c84142e8 | 64 | |
1d67062e RM |
65 | We must remember here not to clobber ERR, since |
66 | the loop condition below uses it to recall that | |
67 | we should retry after a stop. */ | |
28f540f4 | 68 | |
1d67062e RM |
69 | __USEPORT (CTTYID, _hurd_sig_post (0, SIGTTOU, port)); |
70 | /* XXX what to do if error here? */ | |
28f540f4 | 71 | |
1d67062e RM |
72 | /* At this point we should have just run the handler for |
73 | SIGTTOU or resumed after being stopped. Now this is | |
74 | still a "system call", so check to see if we should | |
75 | restart it. */ | |
653d74f1 JK |
76 | _hurd_sigstate_lock (ss); |
77 | actions = _hurd_sigstate_actions (ss); | |
78 | if (!(actions[SIGTTOU].sa_flags & SA_RESTART)) | |
1d67062e | 79 | err = EINTR; |
653d74f1 | 80 | _hurd_sigstate_unlock (ss); |
1d67062e | 81 | } |
28f540f4 | 82 | } |
1d67062e RM |
83 | /* If the last RPC generated a SIGTTOU, loop to try it again. */ |
84 | } while (err == EBACKGROUND); | |
28f540f4 | 85 | |
1d67062e RM |
86 | return err; |
87 | } | |
28f540f4 | 88 | } |