Back to index

glibc  2.9
ctty-output.c
Go to the documentation of this file.
00001 /* _hurd_ctty_output -- Do an output RPC and generate SIGTTOU if necessary.
00002    Copyright (C) 1995,97,99 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <hurd.h>
00021 #include <hurd/signal.h>
00022 
00023 /* Call *RPC on PORT and/or CTTY.  If a call on CTTY returns EBACKGROUND,
00024    generate SIGTTOU if appropriate.  */
00025 
00026 error_t
00027 _hurd_ctty_output (io_t port, io_t ctty, error_t (*rpc) (io_t))
00028 {
00029   if (ctty == MACH_PORT_NULL)
00030     return (*rpc) (port);
00031   else
00032     {
00033       struct hurd_sigstate *ss = _hurd_self_sigstate ();
00034       error_t err;
00035 
00036       do
00037        {
00038          /* Don't use the ctty io port if we are blocking or ignoring
00039             SIGTTOU.  We redo this check at the top of the loop in case
00040             the signal handler changed the state.  */
00041          __spin_lock (&ss->lock);
00042          if (__sigismember (&ss->blocked, SIGTTOU) ||
00043              ss->actions[SIGTTOU].sa_handler == SIG_IGN)
00044            err = EIO;
00045          else
00046            err = 0;
00047          __spin_unlock (&ss->lock);
00048 
00049          if (err)
00050            return (*rpc) (port);
00051 
00052          err = (*rpc) (ctty);
00053          if (err == EBACKGROUND)
00054            {
00055              if (_hurd_orphaned)
00056               /* Our process group is orphaned, so we never generate a
00057                  signal; we just fail.  */
00058               err = EIO;
00059              else
00060               {
00061                 /* Send a SIGTTOU signal to our process group.
00062 
00063                    We must remember here not to clobber ERR, since
00064                    the loop condition below uses it to recall that
00065                 we should retry after a stop.  */
00066 
00067                 __USEPORT (CTTYID, _hurd_sig_post (0, SIGTTOU, port));
00068                 /* XXX what to do if error here? */
00069 
00070                 /* At this point we should have just run the handler for
00071                    SIGTTOU or resumed after being stopped.  Now this is
00072                    still a "system call", so check to see if we should
00073                 restart it.  */
00074                 __spin_lock (&ss->lock);
00075                 if (!(ss->actions[SIGTTOU].sa_flags & SA_RESTART))
00076                   err = EINTR;
00077                 __spin_unlock (&ss->lock);
00078               }
00079            }
00080          /* If the last RPC generated a SIGTTOU, loop to try it again.  */
00081        } while (err == EBACKGROUND);
00082 
00083       return err;
00084     }
00085 }