// runtimeArchitecture gets the name of the current architecture (x86, x86_64, …) func runtimeArchitecture() (string, error) { utsname := &syscall.Utsname{} if err := syscall.Uname(utsname); err != nil { return "", err } return charsToString(utsname.Machine), nil }
func main() { flag.Usage = usage flag.Parse() var err error switch flag.NArg() { case 0: var uts syscall.Utsname err = syscall.Uname(&uts) if err == nil { name := "" for _, r := range uts.Domainname { if r == 0 { break } name += string(r) } fmt.Println(name) } case 1: name := []byte(flag.Arg(0)) err = syscall.Setdomainname(name) default: usage() } if err != nil { fmt.Fprintln(os.Stderr, "domainname:", err) os.Exit(1) } }
// FIXME: Move this to utils package func getKernelVersion() (*utils.KernelVersionInfo, error) { var ( uts syscall.Utsname flavor string kernel, major, minor int err error ) if err := syscall.Uname(&uts); err != nil { return nil, err } release := make([]byte, len(uts.Release)) i := 0 for _, c := range uts.Release { release[i] = byte(c) i++ } // Remove the \x00 from the release for Atoi to parse correctly release = release[:bytes.IndexByte(release, 0)] tmp := strings.SplitN(string(release), "-", 2) tmp2 := strings.SplitN(tmp[0], ".", 3) if len(tmp2) > 0 { kernel, err = strconv.Atoi(tmp2[0]) if err != nil { return nil, err } } if len(tmp2) > 1 { major, err = strconv.Atoi(tmp2[1]) if err != nil { return nil, err } } if len(tmp2) > 2 { minor, err = strconv.Atoi(tmp2[2]) if err != nil { return nil, err } } if len(tmp) == 2 { flavor = tmp[1] } else { flavor = "" } return &utils.KernelVersionInfo{ Kernel: kernel, Major: major, Minor: minor, Flavor: flavor, }, nil }
func checkForUpdates(dockerVersion string, network string) { newVersion.Store("") handleResponse := func(r *checkpoint.CheckResponse, err error) { if err != nil { Log.Printf("Error checking version: %v", err) return } if r.Outdated { newVersion.Store(r.CurrentVersion) Log.Printf("Weave version %s is available; please update at %s", r.CurrentVersion, r.CurrentDownloadURL) } } var uts syscall.Utsname syscall.Uname(&uts) flags := map[string]string{ "docker-version": dockerVersion, "kernel-version": charsToString(uts.Release[:]), } if network != "" { flags["network"] = network } // Start background version checking params := checkpoint.CheckParams{ Product: "weave-net", Version: version, SignatureFile: "", Flags: flags, } checker = checkpoint.CheckInterval(¶ms, updateCheckPeriod, handleResponse) }
func getUname() (*Utsname, error) { u := syscall.Utsname{} if err := syscall.Uname(&u); err != nil { return nil, err } toString := func(f [65]int8) string { out := make([]byte, 0, 64) for _, v := range f[:] { if v == 0 { break } out = append(out, uint8(v)) } return string(out) } uname := Utsname{ Sysname: toString(u.Sysname), Nodename: toString(u.Nodename), Release: toString(u.Release), Version: toString(u.Version), Machine: toString(u.Machine), Domainname: toString(u.Domainname), } return &uname, nil }
// uname does a uname and returns a uroot.Utsname func Uname() (*Utsname, error) { var u syscall.Utsname if err := syscall.Uname(&u); err != nil { return nil, err } return &Utsname{Sysname: toString(u.Sysname[:]), Nodename: toString(u.Nodename[:]), Release: toString(u.Release[:]), Version: toString(u.Version[:]), Machine: toString(u.Machine[:]), Domainname: toString(u.Domainname[:])}, nil }
// osVersion returns the OS version. func osVersion() string { buf := &syscall.Utsname{} err := syscall.Uname(buf) if err != nil { return "0.0" } return charsToString(buf.Release) }
// osName returns the name of the OS. func osName() string { buf := &syscall.Utsname{} err := syscall.Uname(buf) if err != nil { return runtime.GOOS } return charsToString(buf.Sysname) }
func GetString() (string, error) { var uts syscall.Utsname err := syscall.Uname(&uts) if err != nil { return "", errors.New(fmt.Sprintf("Error calling system function 'uname': %s", err)) } return fmt.Sprintf("%s", int8SliceToString(uts.Release[:])), nil }
func uname() (*syscall.Utsname, error) { uts := &syscall.Utsname{} if err := syscall.Uname(uts); err != nil { return nil, err } return uts, nil }
func Platform() (platform string) { var buf syscall.Utsname err := syscall.Uname(&buf) if err != nil { log.Fatal(err) } s := []string{charsToString(buf.Sysname[:]), charsToString(buf.Release[:]), charsToString(buf.Version[:])} platform = strings.Join(s, "-") return }
func genInfo() (*info, error) { var name syscall.Utsname err := syscall.Uname(&name) return &info{ sysname: intToString(name.Sysname), nodename: intToString(name.Nodename), release: intToString(name.Release), version: intToString(name.Version), machine: intToString(name.Machine), }, err }
func GenInfo() *info { _ = syscall.Uname(&name) return &info{ kname: IntToString(name.Sysname), node: IntToString(name.Nodename), release: IntToString(name.Release), kversion: IntToString(name.Version), machine: IntToString(name.Machine), processor: Proc(), os: GOOS, } }
func uname() string { var uts syscall.Utsname ck(syscall.Uname(&uts)) b := make([]byte, len(uts.Release)) for i := range b { b[i] = byte(uts.Release[i]) if b[i] == 0 { break } } return strings.TrimRight(string(b), "\x00") }
func getKernelVersion() (major, minor int, err error) { var u syscall.Utsname if err = syscall.Uname(&u); err != nil { return } // Kernel versions are not always a semver, so we have to do minimal parsing. release := marshal.FromUtsname(u.Release) if n, err := fmt.Sscanf(release, "%d.%d", &major, &minor); err != nil || n != 2 { return 0, 0, fmt.Errorf("Malformed version: %s", release) } return }
// s390/s390x changes func getMachineArch() (string, error) { uname := syscall.Utsname{} err := syscall.Uname(&uname) if err != nil { return "", err } var arch string for _, val := range uname.Machine { arch += string(int(val)) } return arch, nil }
// Version returns our version, os and Go runtime info. func Version() (os string, rt string) { var osinfo syscall.Utsname if err := syscall.Uname(&osinfo); err == nil { os = fmt.Sprintf("%s %s %s", Atos(osinfo.Sysname), Atos(osinfo.Release), Atos(osinfo.Machine)) } if lsb, err := exec.Command("lsb_release", "-ds").Output(); err == nil { os = fmt.Sprintf("%s %s %s", strings.Trim(string(lsb), "\"\n"), Atos(osinfo.Release), Atos(osinfo.Machine)) } rt = fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH) return os, BOTVERSION + " (" + rt + ")" }
func hostname() (name string, err error) { var u syscall.Utsname if errno := syscall.Uname(&u); errno != nil { return "", NewSyscallError("uname", errno) } b := make([]byte, len(u.Nodename)) i := 0 for ; i < len(u.Nodename); i++ { if u.Nodename[i] == 0 { break } b[i] = byte(u.Nodename[i]) } return string(b[:i]), nil }
func Sysinfo() Systeminfo { var uts syscall.Utsname syscall.Uname(&uts) sysname := charToStr(uts.Sysname) nodename := charToStr(uts.Nodename) release := charToStr(uts.Release) version := charToStr(uts.Version) machine := charToStr(uts.Machine) model := cpuModel() numCPU := runtime.NumCPU() memInfo, _ := getMemInfo() memory := float64(memInfo.MemTotal) / (1024 * 1024) memstr := strconv.FormatFloat(memory, 'f', 2, 64) + "GB" return Systeminfo{sysname, nodename, release, version, machine, model, numCPU, memstr} }
func GetPlatform() Platform { var uname syscall.Utsname err := syscall.Uname(&uname) if err != nil { panic("Unable to provide a uname call for this platform") } return Platform{ OSName: charsToString(uname.Sysname[:]), Release: charsToString(uname.Release[:]), Architecture: charsToString(uname.Machine[:]), } }
func machineArch() string { utsname := syscall.Utsname{} err := syscall.Uname(&utsname) if err != nil { log.Fatal("Can't get uname:", err) } s := "" for _, v := range utsname.Machine { if v > 0 { s += string(rune(v)) } } return s }
func getArch() (string, error) { var uname syscall.Utsname err := syscall.Uname(&uname) if err != nil { return "", err } var arch [65]byte for i, c := range uname.Machine { if c == 0 { return string(arch[:i]), nil } arch[i] = byte(c) } return string(arch[:]), nil }
// getSystemInfo returns a sysinfo struct containing system information. func getSystemInfo() *sysinfo { var utsname syscall.Utsname _ = syscall.Uname(&utsname) sys := sysinfo{ name: utsnameToString(utsname.Sysname), node: utsnameToString(utsname.Nodename), release: utsnameToString(utsname.Release), version: utsnameToString(utsname.Version), machine: utsnameToString(utsname.Machine), domain: utsnameToString(utsname.Domainname), os: getOS(), processor: getProcessorName(), } return &sys }
// FIXME: this doens't build on Darwin func GetKernelVersion() (*KernelVersionInfo, error) { var uts syscall.Utsname if err := syscall.Uname(&uts); err != nil { return nil, err } release := make([]byte, len(uts.Release)) i := 0 for _, c := range uts.Release { release[i] = byte(c) i++ } tmp := strings.SplitN(string(release), "-", 2) if len(tmp) != 2 { return nil, fmt.Errorf("Unrecognized kernel version") } tmp2 := strings.SplitN(tmp[0], ".", 3) if len(tmp2) != 3 { return nil, fmt.Errorf("Unrecognized kernel version") } kernel, err := strconv.Atoi(tmp2[0]) if err != nil { return nil, err } major, err := strconv.Atoi(tmp2[1]) if err != nil { return nil, err } minor, err := strconv.Atoi(tmp2[2]) if err != nil { return nil, err } flavor := tmp[1] return &KernelVersionInfo{ Kernel: kernel, Major: major, Minor: minor, Flavor: flavor, }, nil }
func ArchitectureGetLocal() (string, error) { uname := syscall.Utsname{} if err := syscall.Uname(&uname); err != nil { return ArchitectureDefault, err } architectureName := "" for _, c := range uname.Machine { if c == 0 { break } architectureName += string(byte(c)) } return architectureName, nil }
func (c unameCollector) Update(ch chan<- prometheus.Metric) error { var uname syscall.Utsname if err := syscall.Uname(&uname); err != nil { return err } ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1, unameToString(uname.Sysname), unameToString(uname.Release), unameToString(uname.Version), unameToString(uname.Machine), unameToString(uname.Nodename), unameToString(uname.Domainname), ) return nil }
func main() { log.SetFlags(0) flag.Usage = usage flag.Parse() flags := false flag.Visit(func(*flag.Flag) { flags = true }) if !flags { *kernel = true } var uts syscall.Utsname err := syscall.Uname(&uts) if err != nil { log.Fatal(err) } buf := new(bytes.Buffer) if *all || *kernel { xprint(buf, uts.Sysname[:]) } if *all || *node { xprint(buf, uts.Nodename[:]) } if *all || *release { xprint(buf, uts.Release[:]) } if *all || *version { xprint(buf, uts.Version[:]) } if *all || *machine { xprint(buf, uts.Machine[:]) } if *all || *domain { xprint(buf, uts.Domainname[:]) } str := buf.String() fmt.Println(str[:len(str)-1]) }
func getKernelVersion() string { uname := &syscall.Utsname{} if err := syscall.Uname(uname); err != nil { return "Unknown" } release := make([]byte, len(uname.Release)) i := 0 for _, c := range uname.Release { release[i] = byte(c) i++ } release = release[:bytes.IndexByte(release, 0)] return string(release) }
// Write an event into the Wtmp file. An error is returned if the event // cannot be appended to the Wtmp file. func WriteWtmp(user, id string, pid int32, utype int16, line string) error { u := new(Utmp) u.Time.GetTimeOfDay() u.Pid = pid u.Type = utype _ = copy(u.User[:], []byte(user)) _ = copy(u.Id[:], []byte(id)) _ = copy(u.Line[:], []byte(line)) name := new(syscall.Utsname) if err := syscall.Uname(name); err == nil { _ = copy(u.Host[:], general.Int8ToByte(name.Release[:])) } return u.UpdWtmp(WtmpFile) }
func newSystemInfo() SystemInfo { var sysInfo SystemInfo var unameInfo syscall.Utsname if err := syscall.Uname(&unameInfo); err != nil { return sysInfo } sysInfo.Sysname = nativeCharsToString(unameInfo.Sysname) sysInfo.Nodename = nativeCharsToString(unameInfo.Nodename) sysInfo.Release = nativeCharsToString(unameInfo.Release) sysInfo.Version = nativeCharsToString(unameInfo.Version) sysInfo.Machine = nativeCharsToString(unameInfo.Machine) sysInfo.Domainname = nativeCharsToString(unameInfo.Domainname) return sysInfo }