Subject: Truncated output from ptys at slave exit
To: None <current-users@netbsd.org>
From: Michael Eriksson <Michael.Eriksson@era-t.ericsson.se>
List: current-users
Date: 09/05/2003 10:18:16
Tjupp!

I've recently upgraded one of my machines to -current (1.6X as of
about August 31).

I now have a problem that the output from ptys gets truncated when the
slave process exits. This leads to truncated output in emacs for,
e.g., compilations and manual page generation, because emacs runs its
subprocesses in ptys. I have not seen any other complaints about this,
which is strange, but I would be surprised if this is a local issue (I
have some local kernel patches, but they are in my 1.6.1 tree too, and
should not affect this).

Here's a small test program (cc foo.c -lutil) plus slave script, which
shows the problem:

--- foo.c ------------------------------------------------------
#include <util.h>

main()
{
  int n, master;
  char buf[128];

  switch (forkpty(&master, buf, 0, 0)) {
  case -1:
    err(1, "forkpty");
  case 0:
    execl("./doit", "./doit", 0);
    break;
  default:
    /* printf("slave=%s\n", buf); */
    while ((n = read(master, buf, sizeof buf)) > 0)
      write(1, buf, n);
  }
}
----------------------------------------------------------------

--- ./doit  ----------------------------------------------------
#! /bin/sh

cat /etc/gettytab
exec <&- >&- 2>&-
----------------------------------------------------------------

The last line of ./doit will close stdin, stdout and stderr. If this
line is commented out, the output from the test program will be
truncated in -current. In 1.6.1, the test program will give complete
output in both cases.

Does this ring a bell for anyone? If I don't get any useful
suggestions, I will send-pr this. If anybody sees the same problem
that I do, that would be interresting information for the PR, of
course.

-- 
Michael Eriksson <eramore@era-t.ericsson.se>
/usr/sys/ken/slp.c:	 * You are not expected to understand this.