Skip to content

x/sys/unix: missing constants used with struct Timex on Linux #58012

@jclark

Description

@jclark

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

$ go version
go version go1.19.5 linux/amd64

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="/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.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build458273904=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Try to use constants to initialize fields of struct Timex, e.g.

tx := unix.Timex{Modes: unix.ADJ_SETOFFSET | unix.ADJ_NANO}

The Timex value would then be used with unix.Adjtimex or with unix.ClockAdjtime #57618.

What did you expect to see?

Successful compilation.

What did you see instead?

Compiler errors

ADJ_SETOFFSET is not declared by package unix
ADJ_NANO is not declared by package unix

Background

<sys/timex.h> defines constants with 4 different prefixes:

  1. TIME_ - used for return value of adjtimex and clock_adjtime (e.g. TIME_OK)
  2. ADJ_ - used for the modes field of struct timex (e.g. ADJ_SETOFFSET)
  3. STA_ - use for the status field of struct timex (e.g. STA_INS)
  4. MOD_ - alternative names for ADJ_ constants defined by ntp_adjtime kernel API

These are documented in adjtimex(2): https://manpages.ubuntu.com/manpages/focal/man2/adjtimex.2.html

The unix package already defines the TIME_ constants for linux, but it doesn't define any of the others. I would like to add the ADJ_ and STA_ ones; most uses of adjtimex require the ADJ_ constants. I will do a CL if that sounds reasonable.

I don't propose adding the MOD_ ones at this stage, since the unix package does not provide ntp_adjtime. It would be possible for the unix package to provide the ntp_adjtime syscall on the various BSD flavors, at which point it would make sense for linux to provide ntp_adjtime (including the MOD_ constants) implemented in terms of adjtimex (and the ADJ_ constants), which would allow for Go code to use NtpAdjtime and be portable between Linux and BSD. But that seems like a separable issue to me. If the package owners would prefer to include the MOD_ constants now, I can do that also.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions