Skip to content
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

syscall: syscall.FD_CLOEXEC is not equal with syscall.O_CLOEXEC #25515

Closed
hustcat opened this issue May 23, 2018 · 2 comments
Closed

syscall: syscall.FD_CLOEXEC is not equal with syscall.O_CLOEXEC #25515

hustcat opened this issue May 23, 2018 · 2 comments

Comments

@hustcat
Copy link

hustcat commented May 23, 2018

Why syscall.FD_CLOEXEC is not equal with syscall.O_CLOEXEC?However, FD_CLOEXEC is equal with O_CLOEXEC in glibc.

In go:

    fmt.Printf("FD_CLOEXEC=%x\n", syscall.FD_CLOEXEC)
    fmt.Printf("O_CLOEXEC=%x\n", syscall.O_CLOEXEC)
    fmt.Printf("O_NONBLOCK=%x\n", syscall.O_NONBLOCK)

FD_CLOEXEC=1
O_CLOEXEC=80000
O_NONBLOCK=800

In glibc:

#include <sys/eventfd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

int main(int argc, char *argv[]){
    printf("EFD_NONBLOCK=%x\n", EFD_NONBLOCK);
    printf("O_NONBLOCK=%x\n", O_NONBLOCK);
    printf("EFD_CLOEXEC=%x\n", EFD_CLOEXEC);
    printf("O_CLOEXEC=%x\n", O_CLOEXEC);
}

EFD_NONBLOCK=800
O_NONBLOCK=800
EFD_CLOEXEC=80000
O_CLOEXEC=80000

And more, why EFD_NONBLOCK is not exist in go?

What version of Go are you using (go version)?

# go version     
go version go1.7.1 linux/amd64

What operating system and processor architecture are you using (go env)?

# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/data/go"
GORACE=""
GOROOT="/usr/local/go_1.7.1"
GOTOOLDIR="/usr/local/go_1.7.1/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build674153237=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
@hustcat hustcat changed the title syscall.FD_CLOEXEC is not equal with syscall.O_CLOEXEC syscall: syscall.FD_CLOEXEC is not equal with syscall.O_CLOEXEC May 23, 2018
@tklauser
Copy link
Member

And more, EFD_NONBLOCK is not exist in go.

EFD_NONBLOCK is part of golang.org/x/sys/unix which should be used instead of package syscall.

@tklauser
Copy link
Member

Also, the given C program is checking the EFD_* constants while the Go program tests the FD_* constants. These are different things. As I see it, the current values of FD_CLOEXEC and FD_NONBLOCK match the respective values in glibc. FD_CLOEXEC is not the same value as O_CLOEXEC in glibc either, i.e. it matches the values in package syscall:

cat foo.c && gcc foo.c && ./a.out
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

int main(int argc, char *argv[]){
	printf("FD_CLOEXEC=%x\n", FD_CLOEXEC);
	printf("O_CLOEXEC=%x\n", O_CLOEXEC);
}

FD_CLOEXEC=1
O_CLOEXEC=80000

@golang golang locked and limited conversation to collaborators May 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants