-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: IsPermission returns false when reading a write-only file descriptor. #15629
Comments
EBADF is not a permission error.
|
@minux EBADF is used for this permission error as shown and explained ( |
Show us an example in which you do not construct the error value yourself. |
Reading a write only fd is a programmer error and it's not because you
don't have permission to read (maybe it is, but you didn't ask the OS for
reading in the first place.)
|
You need a special device node to reproduce this. My exact case is a tty, but go playground's stdout is a pipe, so here is the exact same error I get with a correctly opened TTY device in write-only mode: @minux the open flag plays a role twice: at open time and at read/write time. |
Thanks for the example. I guess this hinges on what we want "permission error" to mean. |
"Bad use of file descriptor" is not a permission error, any more than closing an already-closed file descriptor is. |
go version
)?go version go1.6.1 linux/amd64
go env
)?Given any file descriptor correctly opened with a write-only access level, reading from it correctly returns the errno
EBADF
as specified inread(2)
:But
os.IsPermission()
does not check this case and returnsfalse
instead oftrue
.https://play.golang.org/p/sPZWxH5JA7
The context provided by
os.PathError
should allow to return true correctly.Regarding the case "fd is not a valid file descriptor", it could be excluded by also checking that the file descriptor is valid with something like
fcntl(fd, F_GETFD)
(but the fd is not in the error context).The text was updated successfully, but these errors were encountered: