[DragonFlyBSD - Bug #3410] (New) FIONREAD on pty master returns 0 (wrong queue) — needs handler in ptyioctl()

afranke bugtracker-admin at leaf.dragonflybsd.org
Fri May 8 08:40:55 PDT 2026


Issue #3410 has been reported by afranke.

----------------------------------------
Bug #3410: FIONREAD on pty master returns 0 (wrong queue) — needs handler in ptyioctl()
http://bugs.dragonflybsd.org/issues/3410

* Author: afranke
* Status: New
* Priority: Normal
* Target version: 6.6
* Start date: 2026-05-08
----------------------------------------

On a pty master fd, @FIONREAD@ reports the wrong queue:
* @ptyioctl()@ has no @FIONREAD@ case, so 
* the request falls through to @ttioctl()@ → @ttnread()@, 
* which returns @t_canq.c_cc + t_rawq.c_cc@ (the slave's input). 

For a master fd the right queue is @t_outq@, which is what @ptcread()@ actually consumes:
* @sys/kern/tty_pty.c@ uses @clist_qtob(&tp->t_outq, ...)@.

h2. Reproducer

See attachment:
* @fionread-master-repro.c@

<pre><code class="shell">
$ cc -lutil fionread-master-repro.c -o repro
$ ./repro
T0 (just opened):        FIONREAD=0  (expect 0)
T1 (after slave write):  FIONREAD=0  (expect 5)  FAIL  ← bug
                         read(master) = 5 bytes        (data IS in t_outq)
T2 (after master drain): FIONREAD=0  (expect 0)
</code></pre>

With the patch applied, T1 reports 5 (PASS).

h2. Fix

Add a @FIONREAD@ case in the @D_MASTER@ branch of @ptyioctl()@, returning @tp->t_outq.c_cc@, see
* @0001-tty_pty-add-FIONREAD-handler-for-master-fds.patch@

h2. Cross-BSD note

Relates to FreeBSD PR 239604 / commit @30189156d325@ (kevans, 2024-01). That commit removed a @PTS_FINISHED at -special-case in @sys/kern/tty_pts.c@'s @ptsdev_ioctl()@ that returned @1@ on closed slave; the remaining @FIONREAD@ path is @ttydisc_getc_poll(tp)@ — master-side semantics matching Linux/OpenBSD/NetBSD. DragonFly has no @PTS_FINISHED@ to remove; the structural divergence is the missing handler entirely.


---Files--------------------------------
0001-tty_pty-add-FIONREAD-handler-for-master-fds.patch (2.17 KB)
fionread-master-repro.c (1.67 KB)


-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account


More information about the Bugs mailing list