Subject: write(2) return codes
From: "david f" <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Wed, 01 May 2002 13:17:01 -0700

Hi,

I've been doing some work on porting gnome to run on cygwin. One problem 
which I recently discovered in testing bonobo is that the write(2) system 
call seems to return the EACCES in the case where it should return EBADF. 
Here is a piece of code which demonstrates it:

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
main () {
int fd = open("/tmp/test1", O_RDONLY);
int ret = write(fd, "foo", 3);
fprintf(stderr,"%d\n", errno);
}

And the strace output from it

   98  342468 [main] a 4016 _open: 3 = open (/tmp/test1, 0x0)
  125  342593 [main] a 4016 _write: write (3, 0x40104F, 3)
  104  342697 [main] a 4016 fhandler_base::write: binary write
  119  342816 [main] a 4016 seterrno_from_win_error: 
/cygnus/netrel/src/cygwin-1.3.10-1/winsup/cygwin/fhandler.cc:279 errno 5
  102  342918 [main] a 4016 geterrno_from_win_error: windows error 5 == 
errno 13
   95  343013 [main] a 4016 fhandler_base::write: -1 = write (0x40104F, 3)
   95  343108 [main] a 4016 _write: -1 = write (3, 0x40104F, 3)

Note that windows returns error code 5, access denied, which is mapped on to 
EACCES. Bonobo expects either EBADF (which solaris returns in this case) or 
EINVAL.

Perhaps the single global error map is not the right approach. It is clearly 
not the correct behavior to always map windows ERROR_ACCESS_DENIED on to 
either EACCES or EBADF.

I'm not a cygwin hacker, but I'll make a patch if there is some consensus on 
how to fix this. There also used to be tools for testing POSIX compliance 
that might catch some other cases of this, but I don't have any info on that 
at the moment.

Please CC me on any mail, as I'm not on the mailing list.

Thanks,

David F

>From: Steven O'Brien To: "david f" <[email-masked]>
>Subject: Re: bonobo and gal patches
>Date: Wed, 1 May 2002 19:24:08 +0100
>
>Hi David
>I've had a look at SUSv2 which is the first reference point for cygwin,
>and definitely in that specification write() *never* sets errno EACCESS.
>I think EBADF, as used by solaris, is the correct errno according to
>SUSv2. You may want to raise this on the cygwin mailing listl certainly
>if you submit a patch there is a reasonable chance of it being accepted,
>given cygwin's aim of susv2 compliance whereever sensible and practical.
>A quick google search of the cygwin site for EACCESS does not show up
>anything. In the meantime I would put a #ifdef __CYGWIN__ conditional in
>the bonobo source to get the desired behaviour.
>
>Steven
>
>On Wed, 01 May 2002 10:52:22 -0700
>"david f" <[email-masked]> wrote:
>
> > Hi,
> >
> > Thanks for the patches. I haven't tested the gal patches yet, but the
> > bonobo patch is definitely an improvement over my first attempt.
> >
> > I have investigated the cause of the failure of the 1st test in
> > bonobo, and I now have a partial answer. The fragment of the test that
> > fails is a write to a file opened read-only. Bonobo expects this to
> > return EBADF or EINVAL, but cygwin returns EACCES. I've attached a
> > piece of strace output from a simple test case I wrote. Note the
> > geterrno_from_win_error returns error code 5, which is
> > "5L    ERROR_ACCESS_DENIED                   Access is denied."
> > according to MS. This is mapped on to EACCES.
> >
> > This is annoying, but it is not clear to me whether this should be
> > fixed in cygwin or bonobo. Ideally, cygwin should return EBADF or
> > EINVAL depending on whatever POSIX says (solaris seems to return
> > EBADF), but maybe windows should return ERROR_INVALID_HANDLE instead
> > of ERROR_ACCESS_DENIED. If we fix this in bonobo, we'll probably run
> > into this again. Maybe cygwin shouldn't map error codes from windows
> > to unix on global basis, and provide function-specific mappings for
> > greater compatibility.
> >
> > If you have any insight here let me know. I have only just realized
> > this problem, and perhaps there has already been some discussion of
> > this problem on cygwin mailing lists.
> >
> > Dave
> >
> > >From: Steven O'Brien <[email-masked]>
> > >To: [email-masked]
> > >Subject: bonobo and gal patches
> > >Date: Sat, 27 Apr 2002 13:55:16 +0100
> > >
> > >David
> > >Here are the 2 patches I promised you. As I said, bonobo test1 is
> > >failing with a permission denied exception, and I have only tried
> > >"make check", not run any other test program.
> > >Gal does not perform so well in its tests, but it should give you a
> > >start. Steven
> > ><< bonobo-1.0.20-cygwin.patch >>
> > ><< gal-0.19.1-cygwin.patch >>
> >
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at
> > http://explorer.msn.com/intl.asp.
> >

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/