Back to index

glibc  2.9
ctty-input.c
Go to the documentation of this file.
00001 /* _hurd_ctty_input -- Do an input RPC and generate SIGTTIN 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 SIGTTIN or EIO as appropriate.  */
00025 
00026 error_t
00027 _hurd_ctty_input (io_t port, io_t ctty, error_t (*rpc) (io_t))
00028 {
00029   error_t err;
00030 
00031   if (ctty == MACH_PORT_NULL)
00032     return (*rpc) (port);
00033 
00034   do
00035     {
00036       err = (*rpc) (ctty);
00037       if (err == EBACKGROUND)
00038        {
00039          /* We are a background job and tried to read from the tty.
00040             We should probably get a SIGTTIN signal.  */
00041          if (_hurd_orphaned)
00042            /* Our process group is orphaned.  Don't stop; just fail.  */
00043            err = EIO;
00044          else
00045            {
00046              struct hurd_sigstate *ss = _hurd_self_sigstate ();
00047              __spin_lock (&ss->lock);
00048              if (__sigismember (&ss->blocked, SIGTTIN) ||
00049                 ss->actions[SIGTTIN].sa_handler == SIG_IGN)
00050               /* We are blocking or ignoring SIGTTIN.  Just fail.  */
00051               err = EIO;
00052              __spin_unlock (&ss->lock);
00053 
00054              if (err == EBACKGROUND)
00055               {
00056                 /* Send a SIGTTIN signal to our process group.
00057 
00058                    We must remember here not to clobber ERR, since
00059                    the loop condition below uses it to recall that
00060                 we should retry after a stop.  */
00061 
00062                 __USEPORT (CTTYID, _hurd_sig_post (0, SIGTTIN, port));
00063                 /* XXX what to do if error here? */
00064 
00065                 /* At this point we should have just run the handler for
00066                    SIGTTIN or resumed after being stopped.  Now this is
00067                    still a "system call", so check to see if we should
00068                 restart it.  */
00069                 __spin_lock (&ss->lock);
00070                 if (!(ss->actions[SIGTTIN].sa_flags & SA_RESTART))
00071                   err = EINTR;
00072                 __spin_unlock (&ss->lock);
00073               }
00074            }
00075        }
00076       /* If the last RPC generated a SIGTTIN, loop to try it again.  */
00077     } while (err == EBACKGROUND);
00078 
00079   return err;
00080 }