From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13780 invoked by alias); 3 Aug 2006 07:04:50 -0000 Received: (qmail 13771 invoked by uid 22791); 3 Aug 2006 07:04:49 -0000 X-Spam-Check-By: sourceware.org Received: from potter.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 03 Aug 2006 07:04:46 +0000 Received: (qmail 10759 invoked by uid 1010); 3 Aug 2006 07:04:45 -0000 From: Richard Sandiford To: gdb-patches@sourceware.org Mail-Followup-To: gdb-patches@sourceware.org, richard@codesourcery.com Subject: gdbserver leaves the terminal without a foreground group Date: Thu, 03 Aug 2006 07:04:00 -0000 Message-ID: <8764hawb8z.fsf@talisman.home> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-08/txt/msg00029.txt.bz2 [This is a resend, sorry; it looks like yesterday's attempt didn't get through. I've tweaked the wording a little in case the first version was spam-filtered.] This patch fixes the problem described here: http://www.cygwin.com/ml/gdb/2003-08/msg00037.html namely, gdbserver leaves the terminal without a foreground group. This is usually harmless on shells with job control, as the shell will put itself back into the foreground, but it causes shells like busybox's msh to exit. The patch makes gdbserver restore the original foreground group on 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. */