Subject: ENOIOCTL fix for ioctl code
To: None <tech-kern@netbsd.org>
From: Andrew Brown <atatat@atatdot.net>
List: tech-kern
Date: 03/10/2002 03:21:02
first, some background:

ioctl() calls don't get restarted properly if they get interrupted,
and if they do get interrupted, the ioctl() call will return -1, and
the process will usually get an erroneous errno value back.  this is
usually ENOTTY.

the problem:

nullioctl() returns -1 to indicate that it did nothing, yet elsewhere
in the kernel, if a process is blocked and interruptable (as a call to
tcsetattr() is), ERESTART is returned.  ERESTART is, unfortunately,
also -1.  interrupted ioctl() calls are mistaken for invalid ioctl()
calls.

the solution:

move ERESTART to some other value, introduce ENOIOCTL, a pseudo error
number that doesn't get exported from the kernel (like ERESTART and
EJUSTRETURN), but gets changed to ENOTTY at the bottom of the main
ioctl() function code in the kernel, and change the ioctl() code path
to check for an intermediate return value of ENOIOCTL before calling a
different layer, instead of checking for "!= 0" or "< 0".  ioctl()
calls can now get restarted properly, and processes should no longer
get erroneous errno values.

i've finished putting together a jumbo patch to implement ENOIOCTL and
altered the code path in the ioctl() code accordingly.  i've placed a
copy of the patch in

	ftp://ftp.netbsd.org/pub/NetBSD/misc/atatat/

SHA1 (enoioctl.patch.20020307) = 15b859cabc4f17a4a7b82546ce18e839849cd9b3
SHA1 (enoioctl.patch.20020309) = 63d07d039aa9f537578a98f8d54ad263b519bdb0

the code i tweaked is all wrapped in #ifdef __USE_ENOIOCTL / #endif,
so anyone willing to test this code can still build "normal" kernels.

i'd be happy if anyone could volunteer.  it's a large patch (5100+
lines, 170+ files patched) and touches on lots of pieces of mi and md
code for machines and devices i don't have.

so give it a try and let me know if you find any problems.

thanks.

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
andrew@crossbar.com       * "information is power -- share the wealth."