unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: EMACS_GET_TTY_PGRP vs. emacs_get_tty_pgrp
Date: Wed, 20 Oct 2010 14:39:50 -0400	[thread overview]
Message-ID: <4CBF3776.4030504@cornell.edu> (raw)
In-Reply-To: <m3r5fkew0x.fsf@hase.home>

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

On 10/20/2010 11:14 AM, Andreas Schwab wrote:
> Ken Brown<kbrown@cornell.edu>  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

[-- Attachment #2: tty.patch --]
[-- Type: text/plain, Size: 1782 bytes --]

=== 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.  */


  reply	other threads:[~2010-10-20 18:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-20 14:22 EMACS_GET_TTY_PGRP vs. emacs_get_tty_pgrp Ken Brown
2010-10-20 15:14 ` Andreas Schwab
2010-10-20 18:39   ` Ken Brown [this message]
2010-10-20 18:59 ` Dan Nicolaescu
2010-10-20 20:01   ` Ken Brown
2010-10-20 20:21     ` Eli Zaretskii
2010-10-20 20:28     ` Dan Nicolaescu
2010-10-20 21:28       ` Ken Brown
2010-10-20 21:36       ` Andreas Schwab

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=4CBF3776.4030504@cornell.edu \
    --to=kbrown@cornell.edu \
    --cc=emacs-devel@gnu.org \
    --cc=schwab@linux-m68k.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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).