[DragonFlyBSD - Bug #3252] tcsetattr/tcgetattr set errno incorrectly on non-TTY

sigttou bugtracker-admin at leaf.dragonflybsd.org
Mon Sep 28 22:58:02 PDT 2026


Issue #3252 has been updated by sigttou.

File mem-ioctl-enotty.patch added

/dev/null is a mem device, it has no own driver.

 make_dev(&mem_ops, 2, ..., "null");   /* sys/kern/kern_memio.c */
mem_ops.d_ioctl = mmioctl;

So devfs -> dev_dioctl -> mem_ops.d_ioctl -> mmioctl. mmioctl handles
minor 0 (mem) and 3/4 (random/urandom); /dev/null is minor 2, so it hits
default:.

ENOTTY is correct:
* ioctl(2): ENOTTY = the request does not apply to this kind of object.
* POSIX tcgetattr/tcsetattr: ENOTTY when the fd is not a terminal.
* ENODEV means "no such device", but /dev/null exists.
* mem_ioctl() already returns ENOTTY for unknown commands.

Safe: default: only covers the mem minors with no ioctl handler (kmem,
null, zero, upmap, ...). They support no ioctls, so only the errno for
unsupported requests changes. It also fixes tcdrain(), tcflush(),
tcflow() and tcsendbreak().



----------------------------------------
Bug #3252: tcsetattr/tcgetattr set errno incorrectly on non-TTY
http://bugs.dragonflybsd.org/issues/3252#change-14716

* Author: tonyc
* Status: New
* Priority: Normal
* Category: Kernel
* Target version: 6.4
* Start date: 2020-10-26
----------------------------------------
tcsetattr() and tcgetattr() are documented to fail as follows:

     Upon successful completion, the functions tcgetattr() and tcsetattr()
     return a value of 0.  Otherwise, they return -1 and the global variable
     errno is set to indicate the error, as follows:

...

     [ENOTTY]           The file associated with the fd argument to
                        tcgetattr() or tcsetattr() is not a terminal.

which matches POSIX, but they do not set errno correctly:

$ cc -otcerror tcerror.c
$ ./tcerror
OK: tcgetattr on /dev/null failed as expected
FAIL: tcgetattr on /dev/null set errno incorrectly: Operation not supported by device
OK: tcsetattr failed as expected
FAIL: tcsetattr failure set errno incorrectly: Operation not supported by device
$ uname -a
DragonFly  5.8-RELEASE DragonFly v5.8.3-RELEASE #10: Thu Sep 24 19:19:45 EDT 2020     root at www.shiningsilence.com:/usr/obj/home/justin/release/5_8/sys/X86_64_GENERIC  x86_64

This was discovered while diagnosing perl test failures.

---Files--------------------------------
tcerror.c (1.03 KB)
mem-ioctl-enotty.patch (317 Bytes)


-- 
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