Subject: bug#12040: closed (Re: bug#12040: 24.1.50; `term' hangs on FreeBSD 10.0-CURRENT without pty(4))

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 17 Aug 2012 07:31:02 +0000

Your bug report

#12040: 24.1.50; `term' hangs on FreeBSD 10.0-CURRENT without pty(4)

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
12040: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12040
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#12040: 24.1.50; `term' hangs on FreeBSD 10.0-CURRENT without pty(4)
From: Glenn Morris <[email-masked]>
To: [email-masked]
Date: Fri, 17 Aug 2012 03:21:49 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 24.3

Thanks, I'm convinced. I installed the posix_openpt change for freebsd
and netbsd to the trunk, currently expected to be released as 24.3. I
left darwin alone for the time being.

Subject: 24.1.50; `term' hangs on FreeBSD 10.0-CURRENT without pty(4)
From: Jan Beich <[email-masked]>
To: [email-masked]
Date: Mon, 23 Jul 2012 23:31:27 +1200
List-Id: <debbugs-submit.debbugs.gnu.org>

Starting with FreeBSD 8.0-RELEASE the system uses new tty layer that no
longer supports old style pseudo ttys *unless* pty(4) kernel module is
loaded. However, pty(4) device is still included in GENERIC kernel on
all releases except 10.0-CURRENT (removed in r233271).

  $ emacs -Q
  M-x term
  <hangs here>

  $ sudo kldload pty
  [try again]

A few ways to solve this:
- use openpty() in -lutil like darwin
- add use posix_openpt() support

http://svn.freebsd.org/changeset/base/233271
https://pub.allbsd.org/FreeBSD-snapshots/ # for testing, seems to be down atm

=== modified file 'configure.ac'
--- configure.ac	2012-07-17 07:30:25 +0000
+++ configure.ac	2012-07-21 09:10:00 +0000
@@ -1220,7 +1220,7 @@
   linux/version.h sys/systeminfo.h
   stdio_ext.h fcntl.h coff.h pty.h
   sys/vlimit.h sys/resource.h
-  sys/utsname.h pwd.h utmp.h dirent.h util.h)
+  sys/utsname.h pwd.h utmp.h dirent.h util.h libutil.h)
 
 AC_MSG_CHECKING(if personality LINUX32 can be set)
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/personality.h>]], [[personality (PER_LINUX32)]])],
@@ -3344,7 +3344,7 @@
     AC_DEFINE(PTY_TTY_NAME_SPRINTF, [] )
     ;;
 
-  darwin )
+  darwin | freebsd )
     AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)] )
     dnl Not used, because PTY_ITERATION is defined.
     AC_DEFINE(FIRST_PTY_LETTER, ['p'])
@@ -3356,7 +3356,7 @@
     AC_DEFINE(PTY_TTY_NAME_SPRINTF, [] )
     ;;
 
-  gnu | freebsd | netbsd | openbsd )
+  gnu | netbsd | openbsd )
     AC_DEFINE(FIRST_PTY_LETTER, ['p'])
     ;;

=== modified file 'src/process.c'
--- src/process.c	2012-07-20 07:29:04 +0000
+++ src/process.c	2012-07-21 09:10:00 +0000
@@ -83,6 +83,10 @@
 #include <util.h>
 #endif
 
+#ifdef HAVE_LIBUTIL_H
+#include <libutil.h>
+#endif
+
 #ifdef HAVE_PTY_H
 #include <pty.h>
 #endif

=== modified file 'configure.ac'
--- configure.ac	2012-07-17 07:30:25 +0000
+++ configure.ac	2012-07-23 10:52:48 +0000
@@ -2759,7 +2759,7 @@
 AC_CHECK_FUNCS(grantpt)
 
 # PTY-related GNU extensions.
-AC_CHECK_FUNCS(getpt)
+AC_CHECK_FUNCS(getpt posix_openpt)
 
 # Check this now, so that we will NOT find the above functions in ncurses.
 # That is because we have not set up to link ncurses in lib-src.
@@ -3356,11 +3356,11 @@
     AC_DEFINE(PTY_TTY_NAME_SPRINTF, [] )
     ;;
 
-  gnu | freebsd | netbsd | openbsd )
+  gnu | netbsd | openbsd )
     AC_DEFINE(FIRST_PTY_LETTER, ['p'])
     ;;
 
-  gnu-linux | gnu-kfreebsd )
+  gnu-linux | gnu-kfreebsd | freebsd )
     dnl if HAVE_GRANTPT
     if test "x$ac_cv_func_grantpt" = xyes; then
       AC_DEFINE(UNIX98_PTYS, 1, [Define if the system has Unix98 PTYs.])
@@ -3368,8 +3368,12 @@
       dnl Note that grantpt and unlockpt may fork.  We must block SIGCHLD
       dnl to prevent sigchld_handler from intercepting the child's death.
       AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptyname; sigblock (sigmask (SIGCHLD)); if (grantpt (fd) == -1 || unlockpt (fd) == -1 || !(ptyname = ptsname(fd))) { sigunblock (sigmask (SIGCHLD)); close (fd); return -1; } snprintf (pty_name, sizeof pty_name, "%s", ptyname); sigunblock (sigmask (SIGCHLD)); }] )
+      dnl if HAVE_POSIX_OPENPT
+      if test "x$ac_cv_func_posix_openpt" = xyes; then
+        AC_DEFINE(PTY_OPEN, [fd = posix_openpt (O_RDWR | O_NOCTTY)])
+        AC_DEFINE(PTY_NAME_SPRINTF, [] )
       dnl if HAVE_GETPT
-      if test "x$ac_cv_func_getpt" = xyes; then
+      elif test "x$ac_cv_func_getpt" = xyes; then
         AC_DEFINE(PTY_OPEN, [fd = getpt ()])
         AC_DEFINE(PTY_NAME_SPRINTF, [] )
       else