maybe_give_terminal_to (opgrp, npgrp, flags)
     pid_t opgrp, npgrp;
     int flags;
{
  int tpgrp;

  tpgrp = tcgetpgrp (shell_tty);
  if (tpgrp < 0 && errno == ENOTTY)
    return -1;
  if (tpgrp == npgrp)
    {
      terminal_pgrp = npgrp;
      return 0;
    }
  else if (tpgrp != opgrp)
    {
#if defined (DEBUG)
      internal_warning ("%d: maybe_give_terminal_to: terminal pgrp == %d shell pgrp = %d new pgrp = %d in_background = %d", (int)getpid(), tpgrp, opgrp, npgrp, running_in_background);
#endif
      return -1;
    }
  else
    return (give_terminal_to (npgrp, flags));     
}
maybe_give_terminal_to (opgrp, npgrp, flags)
     pid_t opgrp, npgrp;
     int flags;
{
  int tpgrp;

  tpgrp = tcgetpgrp (shell_tty);
  if (tpgrp < 0 && errno == ENOTTY)
    return -1;
  if (tpgrp == npgrp)
    {
      terminal_pgrp = npgrp;
      return 0;
    }
  else if (tpgrp != opgrp)
    {
#if defined (DEBUG)
      internal_warning ("%d: maybe_give_terminal_to: terminal pgrp == %d shell pgrp = %d new pgrp = %d in_background = %d", (int)getpid(), tpgrp, opgrp, npgrp, running_in_background);
#endif
      return -1;
    }
  else
    return (give_terminal_to (npgrp, flags));     
}