Skip to content

x/sys/unix: missing Linux clock_adjtime  #57618

@jclark

Description

@jclark

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

$ go version
go version go1.19.4 linux/amd64

Does this issue reproduce with the latest release?

Yes (with 1.19.4)

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jjc/.cache/go-build"
GOENV="/home/jjc/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jjc/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jjc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jjc/gps2phc/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4114271922=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.19.4 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.19.4
uname -sr: Linux 6.0.12-300.fc37.x86_64
/lib64/libc.so.6: GNU C Library (GNU libc) stable release version 2.36.
gdb --version: GNU gdb (GDB) Fedora Linux 12.1-6.fc37

What did you do?

Try to use unix.ClockAdjtime

What did you expect to see?

ClockAdjtime available in unix package.

clock_adjtime is like adjtimex but takes a clockid_t as it's first arg.

https://man7.org/linux/man-pages/man2/adjtimex.2.html

The unix pkg provides adjtimex and the associated Timex struct. It also provides the other functions that take a clockid_t (like ClockGettime).

clock_adjtime is needed by programs that use PTP Hardware Clocks (e.g. https://github.com/facebook/time/blob/ecba0ea401caa4cd45f6bb2d261946cc5cc52a5d/phc/phc.go#L131)

What did you see instead?

I got an error:

ClockAdjtime is not declared by package unix

Fix

It can be written using Syscall like this:

func ClockAdjtime(clockid uint32, buf *unix.Timex) (state int, err error) {
	err = nil
	r0, _, e1 := unix.Syscall(unix.SYS_CLOCK_ADJTIME, uintptr(clockid), uintptr(unsafe.Pointer(buf)), 0)
	state = int(r0)
	if e1 != 0 {
		err = e1
	}
	return
}

I think it can be fixed in the unix package just by adding

//sys ClockAdjtime(clockid int32, buf *Timex) (state int, err error)

to syscall_unix.go around line 1802.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions