]> git.ipfire.org Git - thirdparty/glibc.git/blame - hurd/ctty-input.c
contrib.texi: update
[thirdparty/glibc.git] / hurd / ctty-input.c
CommitLineData
28f540f4 1/* _hurd_ctty_input -- Do an input RPC and generate SIGTTIN 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 SIGTTIN or EIO as appropriate. */
24
25error_t
26_hurd_ctty_input (io_t port, io_t ctty, error_t (*rpc) (io_t))
27{
28 error_t err;
29
1d67062e
RM
30 if (ctty == MACH_PORT_NULL)
31 return (*rpc) (port);
32
28f540f4
RM
33 do
34 {
1d67062e
RM
35 err = (*rpc) (ctty);
36 if (err == EBACKGROUND)
28f540f4
RM
37 {
38 /* We are a background job and tried to read from the tty.
39 We should probably get a SIGTTIN signal. */
28f540f4
RM
40 if (_hurd_orphaned)
41 /* Our process group is orphaned. Don't stop; just fail. */
42 err = EIO;
43 else
44 {
1d67062e 45 struct hurd_sigstate *ss = _hurd_self_sigstate ();
653d74f1
JK
46 struct sigaction *actions;
47
48 _hurd_sigstate_lock (ss);
49 actions = _hurd_sigstate_actions (ss);
34a5a146 50 if (__sigismember (&ss->blocked, SIGTTIN)
653d74f1 51 || actions[SIGTTIN].sa_handler == SIG_IGN)
28f540f4
RM
52 /* We are blocking or ignoring SIGTTIN. Just fail. */
53 err = EIO;
653d74f1 54 _hurd_sigstate_unlock (ss);
c84142e8 55
1d67062e
RM
56 if (err == EBACKGROUND)
57 {
58 /* Send a SIGTTIN signal to our process group.
28f540f4 59
1d67062e
RM
60 We must remember here not to clobber ERR, since
61 the loop condition below uses it to recall that
62 we should retry after a stop. */
28f540f4 63
1d67062e
RM
64 __USEPORT (CTTYID, _hurd_sig_post (0, SIGTTIN, port));
65 /* XXX what to do if error here? */
66
67 /* At this point we should have just run the handler for
68 SIGTTIN or resumed after being stopped. Now this is
69 still a "system call", so check to see if we should
70 restart it. */
653d74f1
JK
71 _hurd_sigstate_lock (ss);
72 actions = _hurd_sigstate_actions (ss);
73 if (!(actions[SIGTTIN].sa_flags & SA_RESTART))
1d67062e 74 err = EINTR;
653d74f1 75 _hurd_sigstate_unlock (ss);
1d67062e 76 }
28f540f4
RM
77 }
78 }
79 /* If the last RPC generated a SIGTTIN, loop to try it again. */
80 } while (err == EBACKGROUND);
81
82 return err;
83}