From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Brown Newsgroups: gmane.emacs.devel Subject: Re: EMACS_GET_TTY_PGRP vs. emacs_get_tty_pgrp Date: Wed, 20 Oct 2010 14:39:50 -0400 Message-ID: <4CBF3776.4030504@cornell.edu> References: <4CBEFB15.5050303@cornell.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030601050008080103090807" X-Trace: dough.gmane.org 1287600052 4077 80.91.229.12 (20 Oct 2010 18:40:52 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 20 Oct 2010 18:40:52 +0000 (UTC) Cc: emacs-devel To: Andreas Schwab Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 20 20:40:51 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P8dal-0002cZ-0c for ged-emacs-devel@m.gmane.org; Wed, 20 Oct 2010 20:40:51 +0200 Original-Received: from localhost ([127.0.0.1]:52837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8daf-0000pX-N4 for ged-emacs-devel@m.gmane.org; Wed, 20 Oct 2010 14:40:45 -0400 Original-Received: from [140.186.70.92] (port=59021 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8daO-0000lL-8A for emacs-devel@gnu.org; Wed, 20 Oct 2010 14:40:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8daG-0002ah-8c for emacs-devel@gnu.org; Wed, 20 Oct 2010 14:40:28 -0400 Original-Received: from granite1.mail.cornell.edu ([128.253.83.141]:37147 helo=authusersmtp.mail.cornell.edu) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8daG-0002a6-5D for emacs-devel@gnu.org; Wed, 20 Oct 2010 14:40:20 -0400 Original-Received: from [127.0.0.1] (cpe-67-249-196-94.twcny.res.rr.com [67.249.196.94]) (authenticated bits=0) by authusersmtp.mail.cornell.edu (8.14.4/8.12.10) with ESMTP id o9KIeIXe011917; Wed, 20 Oct 2010 14:40:18 -0400 (EDT) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 In-Reply-To: X-Antivirus: avast! (VPS 101020-1, 10/20/2010), Outbound message X-Antivirus-Status: Clean X-detected-operating-system: by eggs.gnu.org: Solaris 9 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:131905 Archived-At: This is a multi-part message in MIME format. --------------030601050008080103090807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 10/20/2010 11:14 AM, Andreas Schwab wrote: > Ken Brown writes: > >> The macro EMACS_GET_TTY_PGRP defined in src/systty.h uses either >> tcgetpgrp or TIOCGPGRP to get the PGID of a terminal's foreground >> process group. But src/process.c defines and uses its own >> emacs_get_tty_pgrp that only works on systems that have TIOCGPGRP. Is >> there a good reason for this? > > Is "historical accident" a good reason? :-) Sure. It turned out that emacs_get_tty_pgrp has different arguments than its uppercase cousin, so I didn't get rid of it. But I used the macro inside the function instead and got rid of all ifdefs involving TIOCGPGRP. Does the attached patch look OK? Ken --------------030601050008080103090807 Content-Type: text/plain; name="tty.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="tty.patch" === modified file 'src/process.c' --- src/process.c 2010-09-30 04:28:34 +0000 +++ src/process.c 2010-10-20 17:32:57 +0000 @@ -6009,23 +6009,21 @@ { int gid = -1; -#ifdef TIOCGPGRP - if (ioctl (p->infd, TIOCGPGRP, &gid) == -1 && ! NILP (p->tty_name)) + if (EMACS_GET_TTY_PGRP (p->infd, &gid) <= 0 && ! NILP (p->tty_name)) { int fd; - /* Some OS:es (Solaris 8/9) does not allow TIOCGPGRP from the - master side. Try the slave side. */ + /* Some OS:es (Solaris 8/9) do not allow TIOCGPGRP/tcgetpgrp + from the master side. Try the slave side. */ fd = emacs_open (SDATA (p->tty_name), O_RDONLY, 0); if (fd != -1) { - ioctl (fd, TIOCGPGRP, &gid); + EMACS_GET_TTY_PGRP (fd, &gid); emacs_close (fd); } } -#endif /* defined (TIOCGPGRP ) */ - - return gid; + /* On some systems EMACS_GET_TTY_PGRP can return 0 if it fails. */ + return (gid > 0 ? gid : -1); } DEFUN ("process-running-child-p", Fprocess_running_child_p, @@ -6206,7 +6204,7 @@ handle the signal. */ #endif /* defined (SIGNALS_VIA_CHARACTERS) */ -#ifdef TIOCGPGRP +#ifdef EMACS_HAVE_TTY_PGRP /* Get the current pgrp using the tty itself, if we have that. Otherwise, use the pty to get the pgrp. On pfa systems, saka@pfu.fujitsu.co.JP writes: @@ -6227,11 +6225,11 @@ Or perhaps this is vestigial. */ if (gid == -1) no_pgrp = 1; -#else /* ! defined (TIOCGPGRP ) */ +#else /* ! defined (EMACS_HAVE_TTY_PGRP) */ /* Can't select pgrps on this system, so we know that the child itself heads the pgrp. */ gid = p->pid; -#endif /* ! defined (TIOCGPGRP ) */ +#endif /* ! defined (EMACS_HAVE_TTY_PGRP) */ /* If current_group is lambda, and the shell owns the terminal, don't send any signal. */ --------------030601050008080103090807--