- restore program group on exit
- also set program group in attach mode

---
 gdb-6.3.50/gdb/gdbserver/server.c |   12 ++++++++++++
 1 files changed, 12 insertions(+)

Index: b/gdb-6.3.50/gdb/gdbserver/server.c
===================================================================
--- a/gdb-6.3.50/gdb/gdbserver/server.c
+++ b/gdb-6.3.50/gdb/gdbserver/server.c
@@ -43,6 +43,7 @@ jmp_buf toplevel;
    when no longer debugging it.  */
 
 unsigned long signal_pid;
+int old_pgrp;
 
 char *commname, **debuggee;
 int baudrate = -1;
@@ -82,6 +83,9 @@ attach_inferior (int pid, char *statuspt
      attach function, so that it can be the main thread instead of
      whichever we were told to attach to.  */
   signal_pid = pid;
+  signal (SIGTTOU, SIG_IGN);
+  signal (SIGTTIN, SIG_IGN);
+  tcsetpgrp (fileno (stderr), signal_pid);
 
   *sigptr = mywait (statusptr, 0);
 
@@ -350,9 +354,13 @@ main (int argc, char *argv[])
 	val: 'a'} };
 
 
+  /* save current process group */
+  old_pgrp = tcgetpgrp (fileno (stderr));
+
   if (setjmp (toplevel))
     {
       fprintf (stderr, "Exiting\n");
+      tcsetpgrp (fileno (stderr), old_pgrp);
       exit (1);
     }
 
@@ -452,6 +460,7 @@ main (int argc, char *argv[])
 		  } while (ret != -1 || errno != ECHILD);
 		}
 
+	      tcsetpgrp (fileno (stderr), old_pgrp);
 	      exit (0);
 
 	    case '!':
@@ -638,6 +647,7 @@ main (int argc, char *argv[])
 		}
 	      else
 		{
+	 	  tcsetpgrp (fileno (stderr), old_pgrp);
 		  exit (0);
 		  break;
 		}
@@ -718,6 +728,7 @@ main (int argc, char *argv[])
 	      else
 		{
 		  fprintf (stderr, "GDBserver exiting\n");
+		  tcsetpgrp (fileno (stderr), old_pgrp);
 		  exit (0);
 		}
 	    }
@@ -733,6 +744,7 @@ main (int argc, char *argv[])
       if (extended_protocol)
 	{
 	  remote_close ();
+	  tcsetpgrp (fileno (stderr), old_pgrp);
 	  exit (0);
 	}
       else

