]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* _hurd_ctty_input -- Do an input RPC and generate SIGTTIN if necessary. |
1d67062e | 2 | Copyright (C) 1995,97,99 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 AJ |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, write to the Free | |
17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | 02111-1307 USA. */ | |
28f540f4 RM |
19 | |
20 | #include <hurd.h> | |
21 | #include <hurd/signal.h> | |
22 | ||
23 | /* Call *RPC on PORT and/or CTTY. If a call on CTTY returns EBACKGROUND, | |
24 | generate SIGTTIN or EIO as appropriate. */ | |
25 | ||
26 | error_t | |
27 | _hurd_ctty_input (io_t port, io_t ctty, error_t (*rpc) (io_t)) | |
28 | { | |
29 | error_t err; | |
30 | ||
1d67062e RM |
31 | if (ctty == MACH_PORT_NULL) |
32 | return (*rpc) (port); | |
33 | ||
28f540f4 RM |
34 | do |
35 | { | |
1d67062e RM |
36 | err = (*rpc) (ctty); |
37 | if (err == EBACKGROUND) | |
28f540f4 RM |
38 | { |
39 | /* We are a background job and tried to read from the tty. | |
40 | We should probably get a SIGTTIN signal. */ | |
28f540f4 RM |
41 | if (_hurd_orphaned) |
42 | /* Our process group is orphaned. Don't stop; just fail. */ | |
43 | err = EIO; | |
44 | else | |
45 | { | |
1d67062e | 46 | struct hurd_sigstate *ss = _hurd_self_sigstate (); |
28f540f4 RM |
47 | __spin_lock (&ss->lock); |
48 | if (__sigismember (&ss->blocked, SIGTTIN) || | |
49 | ss->actions[SIGTTIN].sa_handler == SIG_IGN) | |
50 | /* We are blocking or ignoring SIGTTIN. Just fail. */ | |
51 | err = EIO; | |
52 | __spin_unlock (&ss->lock); | |
c84142e8 | 53 | |
1d67062e RM |
54 | if (err == EBACKGROUND) |
55 | { | |
56 | /* Send a SIGTTIN signal to our process group. | |
28f540f4 | 57 | |
1d67062e RM |
58 | We must remember here not to clobber ERR, since |
59 | the loop condition below uses it to recall that | |
60 | we should retry after a stop. */ | |
28f540f4 | 61 | |
1d67062e RM |
62 | __USEPORT (CTTYID, _hurd_sig_post (0, SIGTTIN, port)); |
63 | /* XXX what to do if error here? */ | |
64 | ||
65 | /* At this point we should have just run the handler for | |
66 | SIGTTIN or resumed after being stopped. Now this is | |
67 | still a "system call", so check to see if we should | |
68 | restart it. */ | |
69 | __spin_lock (&ss->lock); | |
70 | if (!(ss->actions[SIGTTIN].sa_flags & SA_RESTART)) | |
71 | err = EINTR; | |
72 | __spin_unlock (&ss->lock); | |
73 | } | |
28f540f4 RM |
74 | } |
75 | } | |
76 | /* If the last RPC generated a SIGTTIN, loop to try it again. */ | |
77 | } while (err == EBACKGROUND); | |
78 | ||
79 | return err; | |
80 | } |