mgmt icon indicating copy to clipboard operation
mgmt copied to clipboard

uptime_fact_posix.go: return type mismatch error

Open mfossen opened this issue 6 years ago • 2 comments

Versions:

  • mgmt version (eg: mgmt --version):

  • operating system/distribution (eg: uname -a):

Linux localhost 3.10.18 #1 SMP Sun Mar 3 22:48:34 PST 2019 armv7l GNU/Linux

  • golang version (eg: go version):

go version go1.11.5 linux/arm

Description:

Running make build throws an error lang/funcs/core/sys/uptime_fact_posix.go:32:16: cannot use sysinfo.Uptime (type int32) as type int64 in return argument

Casting it as an int64 in the return lets it build fine. What I'm confused about is the struct contains Uptime as an int64 in it, so the error is probably related to the weird machine setup I'm using? An older Acer ARM Chromebook with a Debian chroot using crouton.

If you know why that's happening, that's great! If not then feel free to close this, I can PR a return int64(sysinfo.Uptime), nil if you'd like, even though it should be working as is...

FWIW, the error exists with the regular syscall import or by switching it out for https://godoc.org/golang.org/x/sys/unix.

mfossen avatar Mar 23 '19 05:03 mfossen

Perhaps you have a 32 bit machine, and golang doesn't have an int64 on that (or at least not in the struct?) I don't know, but if you dig some more, please let us know. Also, you can fix this by adding a

lang/funcs/core/sys/uptime_fact_WHATEVER.go

where WHATEVER is the specific arch.

LMK

purpleidea avatar Mar 23 '19 16:03 purpleidea

Since this issue wasn't solved yet:

I had that exact error while compiling for armhf, which indeed is a 32-bit SoC. Creating a architecture specific uptime_fact_armhf.go file didnt work out since the error was still thrown in the _posix file (so both files were included). In the end I simply casted it to int64 in the return, which is the best solution for both 64 bit and 32 bit architectures (as far as I understood with my very limited golang knowdlege).

The good thing is, I got it to successfully to compile after fixing a few other similiar places that had overflow issues on 32-bit architectures in structs and maps. The bad thing is that 3 of those were within an external dependency, so I can't just do a simple PR here for now.

Anyway, mgmt compiles and works on armhf (armv7)

thiscantbeserious avatar Jan 27 '20 05:01 thiscantbeserious