This is a small test script that demonstrates the problem with leaking ptys in GENERIC RELENG_6 from Sep 28 02:59 UTC.

Each time the test program is run more and more ptys become unavailable (errno 5).

The problem is also described here.

#!/bin/sh

# pty leak investigation, run in single user mode

m=/dev/pty[p-sP-S][0-9a-v]
s=/dev/tty[p-sP-S][0-9a-v]

uname -v
id
while true; do
   good=0
   bad=0
   total=`echo $m | wc -w | sed 's/ //g'`
   for i in `echo $m`; do
      if dd if=/dev/null of=$i 2>/dev/null; then
         good=$(( good + 1 ))
      else
         bad=$(( bad + 1 ))
      fi
   done

   printf "%-s %3d %3d %3d\n" `date '+%T'` $good $bad $total
   [ $good -eq 0 ] && break
   /tmp/stress2/testcases/pty/pty -t 1m -i 100 -n
done
fstat $m $s

ktrace script notachance
kdump | tail -40


FreeBSD 6.0-BETA5 #0: Wed Sep 28 08:17:22 CEST 2005
    	root@crashbox.osted.lan:/usr/src/sys/i386/compile/Generic 
uid=1001(pho) gid=1001(pho) groups=1001(pho), 0(wheel)
21:55:46   1   0   1
21:56:47   6  62  68
21:57:47   9  77  86
21:58:48   8  80  88
21:59:48   6  90  96
22:00:49   7  98 105
22:01:50   9 101 110
22:02:50   7 104 111
22:03:51   8 107 115
22:04:51   3 117 120
:
pty: openpty: No such file or directory
pty: openpty: No such file or directory
pty: openpty: No such file or directory
00:20:48   0 256 256
USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W NAME
script: openpty: No such file or directory
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  open(0xbfbfe2d0,0x2,0)
 38710 script   NAMI  "/dev/ptySp"
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  open(0xbfbfe2d0,0x2,0)
 38710 script   NAMI  "/dev/ptySq"
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  open(0xbfbfe2d0,0x2,0)
 38710 script   NAMI  "/dev/ptySr"
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  open(0xbfbfe2d0,0x2,0)
 38710 script   NAMI  "/dev/ptySs"
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  open(0xbfbfe2d0,0x2,0)
 38710 script   NAMI  "/dev/ptySt"
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  open(0xbfbfe2d0,0x2,0)
 38710 script   NAMI  "/dev/ptySu"
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  open(0xbfbfe2d0,0x2,0)
 38710 script   NAMI  "/dev/ptySv"
 38710 script   RET   open -1 errno 5 Input/output error
 38710 script   CALL  write(0x2,0xbfbfdcc0,0x8)
 38710 script   GIO   fd 2 wrote 8 bytes
       "script: "
 38710 script   RET   write 8
 38710 script   CALL  write(0x2,0xbfbfdce0,0x7)
 38710 script   GIO   fd 2 wrote 7 bytes
       "openpty"
 38710 script   RET   write 7
 38710 script   CALL  write(0x2,0x28139264,0x2)
 38710 script   GIO   fd 2 wrote 2 bytes
       ": "
 38710 script   RET   write 2
 38710 script   CALL  write(0x2,0xbfbfdcc0,0x1a)
 38710 script   GIO   fd 2 wrote 26 bytes
       "No such file or directory
       "
 38710 script   RET   write 26/0x1a
 38710 script   CALL  exit(0x1)