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