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 constants used with struct Timex on Linux #58012

Closed
jclark opened this issue Jan 26, 2023 · 3 comments
Closed

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

jclark opened this issue Jan 26, 2023 · 3 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jclark
Copy link

jclark commented Jan 26, 2023

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.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 26, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jan 26, 2023
@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 26, 2023
@bcmills
Copy link
Contributor

bcmills commented Jan 26, 2023

(CC @ianlancetaylor @tklauser)

@ianlancetaylor
Copy link
Contributor

A CL as you suggest sounds fine. Thanks.

@gopherbot
Copy link

Change https://go.dev/cl/464241 mentions this issue: unix: add missing constants used with struct Timex on Linux

@golang golang locked and limited conversation to collaborators Feb 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 NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants