1 /* _hurd_ctty_input -- Do an input RPC and generate SIGTTIN if necessary.
2 Copyright (C) 1995-2018 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 <http://www.gnu.org/licenses/>. */
20 #include <hurd/signal.h>
22 /* Call *RPC on PORT and/or CTTY. If a call on CTTY returns EBACKGROUND,
23 generate SIGTTIN or EIO as appropriate. */
26 _hurd_ctty_input (io_t port
, io_t ctty
, error_t (*rpc
) (io_t
))
30 if (ctty
== MACH_PORT_NULL
)
36 if (err
== EBACKGROUND
)
38 /* We are a background job and tried to read from the tty.
39 We should probably get a SIGTTIN signal. */
41 /* Our process group is orphaned. Don't stop; just fail. */
45 struct hurd_sigstate
*ss
= _hurd_self_sigstate ();
46 __spin_lock (&ss
->lock
);
47 if (__sigismember (&ss
->blocked
, SIGTTIN
) ||
48 ss
->actions
[SIGTTIN
].sa_handler
== SIG_IGN
)
49 /* We are blocking or ignoring SIGTTIN. Just fail. */
51 __spin_unlock (&ss
->lock
);
53 if (err
== EBACKGROUND
)
55 /* Send a SIGTTIN signal to our process group.
57 We must remember here not to clobber ERR, since
58 the loop condition below uses it to recall that
59 we should retry after a stop. */
61 __USEPORT (CTTYID
, _hurd_sig_post (0, SIGTTIN
, port
));
62 /* XXX what to do if error here? */
64 /* At this point we should have just run the handler for
65 SIGTTIN or resumed after being stopped. Now this is
66 still a "system call", so check to see if we should
68 __spin_lock (&ss
->lock
);
69 if (!(ss
->actions
[SIGTTIN
].sa_flags
& SA_RESTART
))
71 __spin_unlock (&ss
->lock
);
75 /* If the last RPC generated a SIGTTIN, loop to try it again. */
76 } while (err
== EBACKGROUND
);