tech-userlevel archive

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

hangup in close(2) after posix_openpt(3)



The following test program posted on Japanese ruby-dev mailing list in 2015
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/41993
still causes hangup on NetBSD/i386 7.0:

--- cut here ---
freebsd8% cat tst.c

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int m, s;
  char *slavedev;

  if ((m = posix_openpt(O_RDWR|O_NOCTTY)) == -1) {
perror("posix_openpt"); exit(1); }
  if (grantpt(m) == -1) { perror("grantpt"); exit(1); }
  if (unlockpt(m) == -1) { perror("unlockpt"); exit(1); }
  if ((slavedev = ptsname(m)) == NULL) { perror("ptsname"); exit(1); }
  if ((s = open(slavedev, O_RDWR|O_NOCTTY, 0)) == -1) {
perror("open"); exit(1); }

  if (write(m, "a", 1) == -1) { perror("write"); exit(1); }

  fprintf(stderr, "before close(s)\n");
  if (close(s) == -1) { perror("close"); exit(1); }
  fprintf(stderr, "after close(s)\n");

  return 0;
}
freebsd8% gcc -Wall tst.c
freebsd8% ./a.out
before close(s)
 [ hangup here ]

--- cut here ---

The ruby-dev guys found out that it was caused by tty's echo
and they disabled echo in their tests, then the ticket was closed.

My question is:

 Is this expected behavior on *BSD systems?

The ticket said there was no problem (the test programs exited normally)
on Ubuntu 8.04 and OS X 10.6.

---
Izumi Tsutsui


Home | Main Index | Thread Index | Old Index