diff src/term.c @ 83154:ae72b7a6c292

Dissociate from the controlling tty correctly on FreeBSD. * src/term.c (dissociate_if_controlling_tty): On some systems TIOCNOTTY works only on /dev/tty. Adapt the function accordingly. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-194
author Karoly Lorentey <lorentey@elte.hu>
date Tue, 08 Jun 2004 00:46:13 +0000
parents 9b7814160efe
children f948c9fd910c
line wrap: on
line diff
--- a/src/term.c	Tue Jun 08 00:41:04 2004 +0000
+++ b/src/term.c	Tue Jun 08 00:46:13 2004 +0000
@@ -2256,26 +2256,29 @@
 void
 dissociate_if_controlling_tty (int fd)
 {
-#if defined (USG) && !defined (BSD_PGRPS)
   int pgid;
-  EMACS_GET_TTY_PGRP (fd, &pgid);
+  EMACS_GET_TTY_PGRP (fd, &pgid); /* If tcgetpgrp succeeds, fd is the ctty. */
   if (pgid != -1)
     {
+#if defined (USG) && !defined (BSD_PGRPS)
       setpgrp ();
       no_controlling_tty = 1;
-    }
 #else
 #ifdef TIOCNOTTY                /* Try BSD ioctls. */
-  sigblock (sigmask (SIGTTOU));
-  if (ioctl (fd, TIOCNOTTY, 0) != -1)
-    {
-      no_controlling_tty = 1;
+      sigblock (sigmask (SIGTTOU));
+      fd = emacs_open ("/dev/tty", O_RDWR, 0);
+      if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1)
+        {
+          no_controlling_tty = 1;
+        }
+      if (fd != -1)
+        emacs_close (fd);
+      sigunblock (sigmask (SIGTTOU));
+#else
+      /* Unknown system. */
+      croak ();
+#endif  /* ! TIOCNOTTY */
     }
-  sigunblock (sigmask (SIGTTOU));
-#else
-  /* Unknown system. */
-  croak ();
-#endif  /* ! TIOCNOTTY */
 #endif  /* ! USG */
 }