Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Richard Sandiford <richard@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: Get gdbserver to relinquish control of the terminal
Date: Wed, 02 Aug 2006 14:53:00 -0000	[thread overview]
Message-ID: <87bqr3jiis.fsf@talisman.home> (raw)

This patch fixes the problem described here:

    http://www.cygwin.com/ml/gdb/2003-08/msg00037.html

namely, gdbserver does not hand back control of the terminal to
the original foreground group.  This is usually harmless on shells
with job control, as the shell will claim the terminal back itself,
but it causes shells like busybox's msh to exit.

Tested on m68k-uclinux.  OK to install?

Richard


gdb/gdbserver/
	* server.c (terminal_fd): New variable.
	(old_foreground_pgrp): Likewise.
	(restore_old_foreground_pgrp): New function.
	(start_inferior): Record the terminal file descriptor in terminal_fd
	and its original foreground group in old_foreground_pgrp.  Register
	restore_old_foreground_pgrp with atexit().

Index: gdb/gdbserver/server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.38
diff -u -p -r1.38 server.c
--- gdb/gdbserver/server.c	27 Jul 2006 00:06:12 -0000	1.38
+++ gdb/gdbserver/server.c	2 Aug 2006 14:43:15 -0000
@@ -45,6 +45,22 @@ jmp_buf toplevel;
 
 unsigned long signal_pid;
 
+#ifdef SIGTTOU
+/* A file descriptor for the controlling terminal.  */
+int terminal_fd;
+
+/* TERMINAL_FD's original foreground group.  */
+pid_t old_foreground_pgrp;
+
+/* Hand back terminal ownership to the original foreground group.  */
+
+static void
+restore_old_foreground_pgrp (void)
+{
+  tcsetpgrp (terminal_fd, old_foreground_pgrp);
+}
+#endif
+
 static int
 start_inferior (char *argv[], char *statusptr)
 {
@@ -62,7 +78,10 @@ start_inferior (char *argv[], char *stat
 #ifdef SIGTTOU
   signal (SIGTTOU, SIG_IGN);
   signal (SIGTTIN, SIG_IGN);
-  tcsetpgrp (fileno (stderr), signal_pid);
+  terminal_fd = fileno (stderr);
+  old_foreground_pgrp = tcgetpgrp (terminal_fd);
+  tcsetpgrp (terminal_fd, signal_pid);
+  atexit (restore_old_foreground_pgrp);
 #endif
 
   /* Wait till we are at 1st instruction in program, return signal number.  */


                 reply	other threads:[~2006-08-02 14:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bqr3jiis.fsf@talisman.home \
    --to=richard@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox