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

x/sys/unix: Missing AT_EACCESS on non-Linux Unix systems #59265

Closed
MKuranowski opened this issue Mar 27, 2023 · 3 comments
Closed

x/sys/unix: Missing AT_EACCESS on non-Linux Unix systems #59265

MKuranowski opened this issue Mar 27, 2023 · 3 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Milestone

Comments

@MKuranowski
Copy link

MKuranowski commented Mar 27, 2023

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

$ go version
go version go1.20.2 darwin/amd64
$ tail -n 1 go.mod
require golang.org/x/sys v0.6.0

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mk/Library/Caches/go-build"
GOENV="/Users/mk/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mk/.local/share/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mk/.local/share/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.20.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.20.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7l/56csh9n54g503487v94kb2pm0000gp/T/go-build1532737799=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://go.dev/play/p/yqd7iBRFmEV

package main

import (
	"fmt"

	"golang.org/x/sys/unix"
)

func main() {
	err := unix.Faccessat(unix.AT_FDCWD, "/bin/sh", unix.X_OK, unix.AT_EACCESS)
	fmt.Println(err)
}

What did you expect to see?

Program to run and (most likely) print <nil>.

What did you see instead?

Compilation error:

$ go run access.go
# command-line-arguments
./access.go:10:66: undefined: unix.AT_EACCESS

Comment

AT_EACCESS is specified by the POSIX standard, in the fcntl.h header; used by the faccessat syscall.

If the latter syscall is exposed, I don't see any reason why the AT_EACCESS constant is not provided.

Looking through the source code of the x/sys/unix package however, AT_EACCESS seems to only be available on Linux AT_EACCESS is missing from AIX and Darwin.

Workaround

I can workaround the issue by using CGo and manually poking at fcntl.h.

package main

import (
	"fmt"

	"golang.org/x/sys/unix"
)

// #include <fcntl.h>
import "C"

func main() {
	err := unix.Faccessat(unix.AT_FDCWD, "/bin/sh", unix.X_OK, C.AT_EACCESS)
	fmt.Println(err)
}
$ go run access.go
<nil>
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 27, 2023
@gopherbot gopherbot added this to the Unreleased milestone Mar 27, 2023
@ianlancetaylor ianlancetaylor added help wanted OS-Darwin NeedsFix The path to resolution is known, but the work has not been done. labels Mar 27, 2023
@ianlancetaylor
Copy link
Contributor

I think this is just missing. Want to send a patch?

@MKuranowski
Copy link
Author

Made a PR: golang/sys#153

@gopherbot
Copy link

Change https://go.dev/cl/480115 mentions this issue: unix: add AT_EACCESS on Darwin

@golang golang locked and limited conversation to collaborators Apr 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants