Tue Jul 9 09:37:55 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / hurd / ctty-input.c
blob71aef1b6cf0704a8bf37533f591de1d0adcc1497
1 /* _hurd_ctty_input -- Do an input RPC and generate SIGTTIN if necessary.
2 Copyright (C) 1995 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <hurd.h>
21 #include <hurd/signal.h>
23 /* Call *RPC on PORT and/or CTTY. If a call on CTTY returns EBACKGROUND,
24 generate SIGTTIN or EIO as appropriate. */
26 error_t
27 _hurd_ctty_input (io_t port, io_t ctty, error_t (*rpc) (io_t))
29 error_t err;
33 err = (*rpc) (ctty != MACH_PORT_NULL ? ctty : port);
34 if (ctty != MACH_PORT_NULL && err == EBACKGROUND)
36 /* We are a background job and tried to read from the tty.
37 We should probably get a SIGTTIN signal. */
38 struct hurd_sigstate *ss;
39 if (_hurd_orphaned)
40 /* Our process group is orphaned. Don't stop; just fail. */
41 err = EIO;
42 else
44 ss = _hurd_self_sigstate ();
45 __spin_lock (&ss->lock);
46 if (__sigismember (&ss->blocked, SIGTTIN) ||
47 ss->actions[SIGTTIN].sa_handler == SIG_IGN)
48 /* We are blocking or ignoring SIGTTIN. Just fail. */
49 err = EIO;
50 __spin_unlock (&ss->lock);
52 if (err == EBACKGROUND)
54 /* Send a SIGTTIN signal to our process group.
56 We must remember here not to clobber ERR, since
57 the loop condition below uses it to recall that
58 we should retry after a stop. */
60 __USEPORT (CTTYID, _hurd_sig_post (0, SIGTTIN, port));
61 /* XXX what to do if error here? */
63 /* At this point we should have just run the handler for
64 SIGTTIN or resumed after being stopped. Now this is
65 still a "system call", so check to see if we should
66 restart it. */
67 __spin_lock (&ss->lock);
68 if (!(ss->actions[SIGTTIN].sa_flags & SA_RESTART))
69 err = EINTR;
70 __spin_unlock (&ss->lock);
73 /* If the last RPC generated a SIGTTIN, loop to try it again. */
74 } while (err == EBACKGROUND);
76 return err;