[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#244771: bogl-bterm-udeb: please add Unix98 pty support



Package: bogl-bterm-udeb
Version: 0.1.17-1
Severity: normal
Tags: d-i patch

It would be great to have support for Unix98 ptys in bogl-bterm, as well
as the traditional BSD-style ptys. The kernel I'm using (Jens
Schmalzing's not-quite-released-yet 2.6.5 powerpc package) doesn't
support legacy ptys.

Furthermore, bterm segfaults if it can't find a pty! It doesn't check
the return value of get_ptytty(), but carries on and tries to mess about
with ttyfd, which is just some random stuff off the stack, and
eventually falls over in a heap.

The patch below addresses both these related issues. I've tested it on a
full powerpc 2.6 install, with absolutely no problems, and on a powerpc
2.4 install which failed for other reasons after bterm started up
successfully.

diff -Nru bogl-0.1.17.orig/bterm.c bogl-0.1.17/bterm.c
--- bogl-0.1.17.orig/bterm.c	2004-01-21 02:23:51.000000000 +0000
+++ bogl-0.1.17/bterm.c	2004-04-19 22:56:44.000000000 +0100
@@ -23,6 +23,7 @@
  * so that it appears fast even when it isn't being fast.
  */
 
+#define _XOPEN_SOURCE 500
 #include <errno.h>
 #include <fcntl.h>
 #include <locale.h>
@@ -64,12 +65,30 @@
 static int child_pid = 0;
 static struct termios ttysave;
 
-/* This is the old-fashioned way of getting a pty. */
+/* This first tries the modern Unix98 way of getting a pty, followed by the
+ * old-fashioned BSD way in case that fails. */
 int get_ptytty(int *xptyfd, int *xttyfd)
 {
   char buf[16];
   int i, ptyfd, ttyfd;
 
+  ptyfd = open("/dev/ptmx", O_RDWR);
+  if (ptyfd >= 0) {
+    const char *slave = ptsname(ptyfd);
+    if (slave) {
+      if (grantpt(ptyfd) >= 0) {
+        if (unlockpt(ptyfd) >= 0) {
+          ttyfd = open(slave, O_RDWR);
+          if (ttyfd >= 0) {
+            *xptyfd = ptyfd, *xttyfd = ttyfd;
+            return 0;
+          }
+        }
+      }
+    }
+    close(ptyfd);
+  }
+
   for (i = 0; i < 32; i++) {
     sprintf(buf, "/dev/pty%c%x", "pqrs"[i/16], i%16);
     ptyfd = open(buf, O_RDWR);
@@ -254,7 +273,10 @@
 
   bogl_term_redraw(term);
 
-  get_ptytty(&ptyfd, &ttyfd);
+  if (get_ptytty(&ptyfd, &ttyfd)) {
+    perror("can't get a pty");
+    exit(1);
+  }
 
   spawn_shell(ptyfd, ttyfd, command == NULL ? "/bin/sh" : command);
 
diff -Nru bogl-0.1.17.orig/debian/changelog bogl-0.1.17/debian/changelog
--- bogl-0.1.17.orig/debian/changelog	2004-03-08 04:41:40.000000000 +0000
+++ bogl-0.1.17/debian/changelog	2004-04-19 22:43:51.000000000 +0100
@@ -1,3 +1,10 @@
+bogl (0.1.17-1.1) UNRELEASED; urgency=low
+
+  * Support Unix98 ptys.
+  * Make bterm exit cleanly if it fails to get a pty.
+
+ -- Colin Watson <cjwatson@debian.org>  Mon, 19 Apr 2004 22:43:04 +0100
+
 bogl (0.1.17-1) unstable; urgency=low
 
   * Fix a typo which broke bdftobogl on LP64 targets like ia64.

Thanks,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: