public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* ioctl: FIONREAD and ENOTTY
@ 2011-07-20  8:11 Yaakov (Cygwin/X)
  2011-07-20 15:47 ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: Yaakov (Cygwin/X) @ 2011-07-20  8:11 UTC (permalink / raw)
  To: cygwin

On Linux, ioctl(2) returns several different errors[1]:

EBADF  d is not a valid descriptor.
EFAULT argp references an inaccessible memory area.
EINVAL Request or argp is not valid.
ENOTTY d is not associated with a character special device.
ENOTTY The specified request does not apply to the kind of object that
       the descriptor d references.

In the case of FIONREAD, Cygwin doesn't seem to distinguish between
EINVAL and ENOTTY, and this causes at least one major bug:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536

I have patched GCJ and GNU classpath to work around it, but this really
needs to be fixed in Cygwin itself.


Yaakov

[1] http://www.kernel.org/doc/man-pages/online/pages/man2/ioctl.2.html



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ioctl: FIONREAD and ENOTTY
  2011-07-20  8:11 ioctl: FIONREAD and ENOTTY Yaakov (Cygwin/X)
@ 2011-07-20 15:47 ` Corinna Vinschen
  2011-07-20 22:37   ` Yaakov (Cygwin/X)
  0 siblings, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2011-07-20 15:47 UTC (permalink / raw)
  To: cygwin

On Jul 20 03:11, Yaakov (Cygwin/X) wrote:
> On Linux, ioctl(2) returns several different errors[1]:
> 
> EBADF  d is not a valid descriptor.
> EFAULT argp references an inaccessible memory area.
> EINVAL Request or argp is not valid.
> ENOTTY d is not associated with a character special device.
> ENOTTY The specified request does not apply to the kind of object that
>        the descriptor d references.
> 
> In the case of FIONREAD, Cygwin doesn't seem to distinguish between
> EINVAL and ENOTTY, and this causes at least one major bug:
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536
> 
> I have patched GCJ and GNU classpath to work around it, but this really
> needs to be fixed in Cygwin itself.

Would this patch be sufficient?

Index: fhandler.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
retrieving revision 1.397
diff -u -p -r1.397 fhandler.cc
--- fhandler.cc	5 Jul 2011 12:02:10 -0000	1.397
+++ fhandler.cc	20 Jul 2011 15:46:40 -0000
@@ -1151,6 +1151,10 @@ fhandler_base::ioctl (unsigned int cmd, 
       set_nonblocking (*(int *) buf);
       res = 0;
       break;
+    case FIONREAD:
+      set_errno (ENOTTY);
+      res = -1;
+      break;
     default:
       set_errno (EINVAL);
       res = -1;


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ioctl: FIONREAD and ENOTTY
  2011-07-20 15:47 ` Corinna Vinschen
@ 2011-07-20 22:37   ` Yaakov (Cygwin/X)
  2011-07-21 14:40     ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: Yaakov (Cygwin/X) @ 2011-07-20 22:37 UTC (permalink / raw)
  To: cygwin

On Wed, 2011-07-20 at 17:46 +0200, Corinna Vinschen wrote:
> On Jul 20 03:11, Yaakov (Cygwin/X) wrote:
> > On Linux, ioctl(2) returns several different errors[1]:
> > 
> > EBADF  d is not a valid descriptor.
> > EFAULT argp references an inaccessible memory area.
> > EINVAL Request or argp is not valid.
> > ENOTTY d is not associated with a character special device.
> > ENOTTY The specified request does not apply to the kind of object that
> >        the descriptor d references.
> > 
> > In the case of FIONREAD, Cygwin doesn't seem to distinguish between
> > EINVAL and ENOTTY, and this causes at least one major bug:
> > 
> > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536
> > 
> > I have patched GCJ and GNU classpath to work around it, but this really
> > needs to be fixed in Cygwin itself.
> 
> Would this patch be sufficient?
> 
> Index: fhandler.cc
> ===================================================================
> RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
> retrieving revision 1.397
> diff -u -p -r1.397 fhandler.cc
> --- fhandler.cc	5 Jul 2011 12:02:10 -0000	1.397
> +++ fhandler.cc	20 Jul 2011 15:46:40 -0000
> @@ -1151,6 +1151,10 @@ fhandler_base::ioctl (unsigned int cmd, 
>        set_nonblocking (*(int *) buf);
>        res = 0;
>        break;
> +    case FIONREAD:
> +      set_errno (ENOTTY);
> +      res = -1;
> +      break;
>      default:
>        set_errno (EINVAL);
>        res = -1;

Given my testcases, give me a few days to check this out.


Yaakov



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ioctl: FIONREAD and ENOTTY
  2011-07-20 22:37   ` Yaakov (Cygwin/X)
@ 2011-07-21 14:40     ` Corinna Vinschen
  2011-07-21 17:06       ` Christopher Faylor
  0 siblings, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2011-07-21 14:40 UTC (permalink / raw)
  To: cygwin

On Jul 20 17:37, Yaakov (Cygwin/X) wrote:
> On Wed, 2011-07-20 at 17:46 +0200, Corinna Vinschen wrote:
> > On Jul 20 03:11, Yaakov (Cygwin/X) wrote:
> > > On Linux, ioctl(2) returns several different errors[1]:
> > > 
> > > EBADF  d is not a valid descriptor.
> > > EFAULT argp references an inaccessible memory area.
> > > EINVAL Request or argp is not valid.
> > > ENOTTY d is not associated with a character special device.
> > > ENOTTY The specified request does not apply to the kind of object that
> > >        the descriptor d references.
> > > 
> > > In the case of FIONREAD, Cygwin doesn't seem to distinguish between
> > > EINVAL and ENOTTY, and this causes at least one major bug:
> > > 
> > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536
> > > 
> > > I have patched GCJ and GNU classpath to work around it, but this really
> > > needs to be fixed in Cygwin itself.
> > 
> > Would this patch be sufficient?
> > 
> > Index: fhandler.cc
> > ===================================================================
> > RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
> > retrieving revision 1.397
> > diff -u -p -r1.397 fhandler.cc
> > --- fhandler.cc	5 Jul 2011 12:02:10 -0000	1.397
> > +++ fhandler.cc	20 Jul 2011 15:46:40 -0000
> > @@ -1151,6 +1151,10 @@ fhandler_base::ioctl (unsigned int cmd, 
> >        set_nonblocking (*(int *) buf);
> >        res = 0;
> >        break;
> > +    case FIONREAD:
> > +      set_errno (ENOTTY);
> > +      res = -1;
> > +      break;
> >      default:
> >        set_errno (EINVAL);
> >        res = -1;
> 
> Given my testcases, give me a few days to check this out.

Ok, but the patch doesn't build as is.  You have to add

  #include <asm/socket.h>

to get the FIONREAD definition.  Sorry about that.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ioctl: FIONREAD and ENOTTY
  2011-07-21 14:40     ` Corinna Vinschen
@ 2011-07-21 17:06       ` Christopher Faylor
  2011-07-21 17:48         ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: Christopher Faylor @ 2011-07-21 17:06 UTC (permalink / raw)
  To: cygwin

On Thu, Jul 21, 2011 at 04:39:31PM +0200, Corinna Vinschen wrote:
>On Jul 20 17:37, Yaakov (Cygwin/X) wrote:
>> On Wed, 2011-07-20 at 17:46 +0200, Corinna Vinschen wrote:
>> > On Jul 20 03:11, Yaakov (Cygwin/X) wrote:
>> > > On Linux, ioctl(2) returns several different errors[1]:
>> > > 
>> > > EBADF  d is not a valid descriptor.
>> > > EFAULT argp references an inaccessible memory area.
>> > > EINVAL Request or argp is not valid.
>> > > ENOTTY d is not associated with a character special device.
>> > > ENOTTY The specified request does not apply to the kind of object that
>> > >        the descriptor d references.
>> > > 
>> > > In the case of FIONREAD, Cygwin doesn't seem to distinguish between
>> > > EINVAL and ENOTTY, and this causes at least one major bug:
>> > > 
>> > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536
>> > > 
>> > > I have patched GCJ and GNU classpath to work around it, but this really
>> > > needs to be fixed in Cygwin itself.
>> > 
>> > Would this patch be sufficient?
>> > 
>> > Index: fhandler.cc
>> > ===================================================================
>> > RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
>> > retrieving revision 1.397
>> > diff -u -p -r1.397 fhandler.cc
>> > --- fhandler.cc	5 Jul 2011 12:02:10 -0000	1.397
>> > +++ fhandler.cc	20 Jul 2011 15:46:40 -0000
>> > @@ -1151,6 +1151,10 @@ fhandler_base::ioctl (unsigned int cmd, 
>> >        set_nonblocking (*(int *) buf);
>> >        res = 0;
>> >        break;
>> > +    case FIONREAD:
>> > +      set_errno (ENOTTY);
>> > +      res = -1;
>> > +      break;
>> >      default:
>> >        set_errno (EINVAL);
>> >        res = -1;
>> 
>> Given my testcases, give me a few days to check this out.
>
>Ok, but the patch doesn't build as is.  You have to add
>
>  #include <asm/socket.h>
>
>to get the FIONREAD definition.  Sorry about that.

Btw, I don't think the above is sufficient.  I think you'll have to add a
similar test to other fhandlers (like fhandler_windows) which completely
implement ioctl without reverting to fhandler_base.

cgf

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ioctl: FIONREAD and ENOTTY
  2011-07-21 17:06       ` Christopher Faylor
@ 2011-07-21 17:48         ` Corinna Vinschen
  2011-07-21 19:58           ` Christopher Faylor
  0 siblings, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2011-07-21 17:48 UTC (permalink / raw)
  To: cygwin

On Jul 21 13:05, Christopher Faylor wrote:
> On Thu, Jul 21, 2011 at 04:39:31PM +0200, Corinna Vinschen wrote:
> >On Jul 20 17:37, Yaakov (Cygwin/X) wrote:
> >> On Wed, 2011-07-20 at 17:46 +0200, Corinna Vinschen wrote:
> >> > On Jul 20 03:11, Yaakov (Cygwin/X) wrote:
> >> > > On Linux, ioctl(2) returns several different errors[1]:
> >> > > 
> >> > > EBADF  d is not a valid descriptor.
> >> > > EFAULT argp references an inaccessible memory area.
> >> > > EINVAL Request or argp is not valid.
> >> > > ENOTTY d is not associated with a character special device.
> >> > > ENOTTY The specified request does not apply to the kind of object that
> >> > >        the descriptor d references.
> >> > > 
> >> > > In the case of FIONREAD, Cygwin doesn't seem to distinguish between
> >> > > EINVAL and ENOTTY, and this causes at least one major bug:
> >> > > 
> >> > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536
> >> > > 
> >> > > I have patched GCJ and GNU classpath to work around it, but this really
> >> > > needs to be fixed in Cygwin itself.
> >> > 
> >> > Would this patch be sufficient?
> >> > 
> >> > Index: fhandler.cc
> >> > ===================================================================
> >> > RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
> >> > retrieving revision 1.397
> >> > diff -u -p -r1.397 fhandler.cc
> >> > --- fhandler.cc	5 Jul 2011 12:02:10 -0000	1.397
> >> > +++ fhandler.cc	20 Jul 2011 15:46:40 -0000
> >> > @@ -1151,6 +1151,10 @@ fhandler_base::ioctl (unsigned int cmd, 
> >> >        set_nonblocking (*(int *) buf);
> >> >        res = 0;
> >> >        break;
> >> > +    case FIONREAD:
> >> > +      set_errno (ENOTTY);
> >> > +      res = -1;
> >> > +      break;
> >> >      default:
> >> >        set_errno (EINVAL);
> >> >        res = -1;
> >> 
> >> Given my testcases, give me a few days to check this out.
> >
> >Ok, but the patch doesn't build as is.  You have to add
> >
> >  #include <asm/socket.h>
> >
> >to get the FIONREAD definition.  Sorry about that.
> 
> Btw, I don't think the above is sufficient.  I think you'll have to add a
> similar test to other fhandlers (like fhandler_windows) which completely
> implement ioctl without reverting to fhandler_base.

Hmm, isn't that just a bug in these ioctl methods?  I think they
all should fall through to fhandler_base::ioctl.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ioctl: FIONREAD and ENOTTY
  2011-07-21 17:48         ` Corinna Vinschen
@ 2011-07-21 19:58           ` Christopher Faylor
  2011-07-21 20:22             ` Christopher Faylor
  0 siblings, 1 reply; 8+ messages in thread
From: Christopher Faylor @ 2011-07-21 19:58 UTC (permalink / raw)
  To: cygwin

On Thu, Jul 21, 2011 at 07:47:17PM +0200, Corinna Vinschen wrote:
>On Jul 21 13:05, Christopher Faylor wrote:
>> On Thu, Jul 21, 2011 at 04:39:31PM +0200, Corinna Vinschen wrote:
>> >On Jul 20 17:37, Yaakov (Cygwin/X) wrote:
>> >> On Wed, 2011-07-20 at 17:46 +0200, Corinna Vinschen wrote:
>> >> > On Jul 20 03:11, Yaakov (Cygwin/X) wrote:
>> >> > > On Linux, ioctl(2) returns several different errors[1]:
>> >> > > 
>> >> > > EBADF  d is not a valid descriptor.
>> >> > > EFAULT argp references an inaccessible memory area.
>> >> > > EINVAL Request or argp is not valid.
>> >> > > ENOTTY d is not associated with a character special device.
>> >> > > ENOTTY The specified request does not apply to the kind of object that
>> >> > >        the descriptor d references.
>> >> > > 
>> >> > > In the case of FIONREAD, Cygwin doesn't seem to distinguish between
>> >> > > EINVAL and ENOTTY, and this causes at least one major bug:
>> >> > > 
>> >> > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536
>> >> > > 
>> >> > > I have patched GCJ and GNU classpath to work around it, but this really
>> >> > > needs to be fixed in Cygwin itself.
>> >> > 
>> >> > Would this patch be sufficient?
>> >> > 
>> >> > Index: fhandler.cc
>> >> > ===================================================================
>> >> > RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
>> >> > retrieving revision 1.397
>> >> > diff -u -p -r1.397 fhandler.cc
>> >> > --- fhandler.cc	5 Jul 2011 12:02:10 -0000	1.397
>> >> > +++ fhandler.cc	20 Jul 2011 15:46:40 -0000
>> >> > @@ -1151,6 +1151,10 @@ fhandler_base::ioctl (unsigned int cmd, 
>> >> >        set_nonblocking (*(int *) buf);
>> >> >        res = 0;
>> >> >        break;
>> >> > +    case FIONREAD:
>> >> > +      set_errno (ENOTTY);
>> >> > +      res = -1;
>> >> > +      break;
>> >> >      default:
>> >> >        set_errno (EINVAL);
>> >> >        res = -1;
>> >> 
>> >> Given my testcases, give me a few days to check this out.
>> >
>> >Ok, but the patch doesn't build as is.  You have to add
>> >
>> >  #include <asm/socket.h>
>> >
>> >to get the FIONREAD definition.  Sorry about that.
>> 
>> Btw, I don't think the above is sufficient.  I think you'll have to add a
>> similar test to other fhandlers (like fhandler_windows) which completely
>> implement ioctl without reverting to fhandler_base.
>
>Hmm, isn't that just a bug in these ioctl methods?  I think they
>all should fall through to fhandler_base::ioctl.

Yep.  I think you're right.  I'll handle that if you want.

cgf

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ioctl: FIONREAD and ENOTTY
  2011-07-21 19:58           ` Christopher Faylor
@ 2011-07-21 20:22             ` Christopher Faylor
  0 siblings, 0 replies; 8+ messages in thread
From: Christopher Faylor @ 2011-07-21 20:22 UTC (permalink / raw)
  To: cygwin

On Thu, Jul 21, 2011 at 03:57:46PM -0400, Christopher Faylor wrote:
>On Thu, Jul 21, 2011 at 07:47:17PM +0200, Corinna Vinschen wrote:
>>On Jul 21 13:05, Christopher Faylor wrote:
>>> On Thu, Jul 21, 2011 at 04:39:31PM +0200, Corinna Vinschen wrote:
>>> >On Jul 20 17:37, Yaakov (Cygwin/X) wrote:
>>> >> On Wed, 2011-07-20 at 17:46 +0200, Corinna Vinschen wrote:
>>> >> > On Jul 20 03:11, Yaakov (Cygwin/X) wrote:
>>> >> > > On Linux, ioctl(2) returns several different errors[1]:
>>> >> > > 
>>> >> > > EBADF  d is not a valid descriptor.
>>> >> > > EFAULT argp references an inaccessible memory area.
>>> >> > > EINVAL Request or argp is not valid.
>>> >> > > ENOTTY d is not associated with a character special device.
>>> >> > > ENOTTY The specified request does not apply to the kind of object that
>>> >> > >        the descriptor d references.
>>> >> > > 
>>> >> > > In the case of FIONREAD, Cygwin doesn't seem to distinguish between
>>> >> > > EINVAL and ENOTTY, and this causes at least one major bug:
>>> >> > > 
>>> >> > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35536
>>> >> > > 
>>> >> > > I have patched GCJ and GNU classpath to work around it, but this really
>>> >> > > needs to be fixed in Cygwin itself.
>>> >> > 
>>> >> > Would this patch be sufficient?
>>> >> > 
>>> >> > Index: fhandler.cc
>>> >> > ===================================================================
>>> >> > RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
>>> >> > retrieving revision 1.397
>>> >> > diff -u -p -r1.397 fhandler.cc
>>> >> > --- fhandler.cc	5 Jul 2011 12:02:10 -0000	1.397
>>> >> > +++ fhandler.cc	20 Jul 2011 15:46:40 -0000
>>> >> > @@ -1151,6 +1151,10 @@ fhandler_base::ioctl (unsigned int cmd, 
>>> >> >        set_nonblocking (*(int *) buf);
>>> >> >        res = 0;
>>> >> >        break;
>>> >> > +    case FIONREAD:
>>> >> > +      set_errno (ENOTTY);
>>> >> > +      res = -1;
>>> >> > +      break;
>>> >> >      default:
>>> >> >        set_errno (EINVAL);
>>> >> >        res = -1;
>>> >> 
>>> >> Given my testcases, give me a few days to check this out.
>>> >
>>> >Ok, but the patch doesn't build as is.  You have to add
>>> >
>>> >  #include <asm/socket.h>
>>> >
>>> >to get the FIONREAD definition.  Sorry about that.
>>> 
>>> Btw, I don't think the above is sufficient.  I think you'll have to add a
>>> similar test to other fhandlers (like fhandler_windows) which completely
>>> implement ioctl without reverting to fhandler_base.
>>
>>Hmm, isn't that just a bug in these ioctl methods?  I think they
>>all should fall through to fhandler_base::ioctl.
>
>Yep.  I think you're right.  I'll handle that if you want.

I made this modification and added the above patch as well.  We can
always pull it out or modify it if it doesn't do the right thing.

A snapshot is building now.

cgf

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-07-21 20:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-20  8:11 ioctl: FIONREAD and ENOTTY Yaakov (Cygwin/X)
2011-07-20 15:47 ` Corinna Vinschen
2011-07-20 22:37   ` Yaakov (Cygwin/X)
2011-07-21 14:40     ` Corinna Vinschen
2011-07-21 17:06       ` Christopher Faylor
2011-07-21 17:48         ` Corinna Vinschen
2011-07-21 19:58           ` Christopher Faylor
2011-07-21 20:22             ` Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).