forked from zcalusic/sysinfo
/
kernel_linux.go
36 lines (28 loc) · 856 Bytes
/
kernel_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright © 2016 Zlatko Čalušić
//
// Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.
//
//go:build !darwin && !freebsd && !windows
// +build !darwin,!freebsd,!windows
//+build linux
package sysinfo
import (
"strings"
"syscall"
"unsafe"
)
// Kernel information.
type Kernel struct {
Release string `json:"release,omitempty"`
Version string `json:"version,omitempty"`
Architecture string `json:"architecture,omitempty"`
}
func (si *SysInfo) getKernelInfo() {
si.Kernel.Release = slurpFile("/proc/sys/kernel/osrelease")
si.Kernel.Version = slurpFile("/proc/sys/kernel/version")
var uname syscall.Utsname
if err := syscall.Uname(&uname); err != nil {
return
}
si.Kernel.Architecture = strings.TrimRight(string((*[65]byte)(unsafe.Pointer(&uname.Machine))[:]), "\000")
}