本文整理汇总了Golang中syscall.Sysctl函数的典型用法代码示例。如果您正苦于以下问题:Golang Sysctl函数的具体用法?Golang Sysctl怎么用?Golang Sysctl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sysctl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
// Seems like kern.osreldate is veiled on latest OS X. We use
// kern.osrelease instead.
osver, err := syscall.Sysctl("kern.osrelease")
if err != nil {
return
}
var i int
for i = range osver {
if osver[i] != '.' {
continue
}
}
// The IPV6_RECVPATHMTU and IPV6_PATHMTU options were
// introduced in OS X 10.7 (Darwin 11.0.0).
// See http://support.apple.com/kb/HT1633.
if i > 2 || i == 2 && osver[0] >= '1' && osver[1] >= '1' {
ctlOpts[ctlTrafficClass].name = sysIPV6_TCLASS
ctlOpts[ctlTrafficClass].length = 4
ctlOpts[ctlTrafficClass].marshal = marshalTrafficClass
ctlOpts[ctlTrafficClass].parse = parseTrafficClass
ctlOpts[ctlHopLimit].name = sysIPV6_HOPLIMIT
ctlOpts[ctlHopLimit].marshal = marshalHopLimit
ctlOpts[ctlPacketInfo].name = sysIPV6_PKTINFO
ctlOpts[ctlPacketInfo].marshal = marshalPacketInfo
sockOpts[ssoReceiveTrafficClass].level = ianaProtocolIPv6
sockOpts[ssoReceiveTrafficClass].name = sysIPV6_RECVTCLASS
sockOpts[ssoReceiveTrafficClass].typ = ssoTypeInt
sockOpts[ssoReceiveHopLimit].name = sysIPV6_RECVHOPLIMIT
sockOpts[ssoReceivePacketInfo].name = sysIPV6_RECVPKTINFO
sockOpts[ssoReceivePathMTU].level = ianaProtocolIPv6
sockOpts[ssoReceivePathMTU].name = sysIPV6_RECVPATHMTU
sockOpts[ssoReceivePathMTU].typ = ssoTypeInt
}
}
示例2: getInfo
func getInfo() ([]Info, error) {
cpu, err := syscall.Sysctl("machdep.cpu.vendor")
if err != nil {
return nil, err
}
fmt.Println(cpu)
/*
type Info struct {
CPU int32 `json:"cpu"`
VendorId string `json:"vendorId"`
Family string `json:"family"`
Model string `json:"model"`
Stepping int32 `json:"stepping"`
PhysicalId string `json:"physicalId"`
CoreId string `json:"coreId"`
Cores int32 `json:"cores"`
ModelName string `json:"modelName"`
Mhz float64 `json:"mhz"`
CacheSize int32 `json:"cacheSize"`
Flags []string `json:"flags"`
}*/
return nil, nil
}
示例3: osVersion
// osVersion returns the OS version.
func osVersion() string {
release, err := syscall.Sysctl("kern.osrelease")
if err != nil {
return "0.0"
}
return release
}
示例4: supportsIPv6MulticastDeliveryOnLoopback
func supportsIPv6MulticastDeliveryOnLoopback() bool {
switch runtime.GOOS {
case "freebsd":
// See http://www.freebsd.org/cgi/query-pr.cgi?pr=180065.
// Even after the fix, it looks like the latest
// kernels don't deliver link-local scoped multicast
// packets correctly.
return false
case "darwin":
// See http://support.apple.com/kb/HT1633.
s, err := syscall.Sysctl("kern.osrelease")
if err != nil {
return false
}
ss := strings.Split(s, ".")
if len(ss) == 0 {
return false
}
// OS X 10.9 (Darwin 13) or above seems to do the
// right thing; preserving the packet header as it's
// needed for the checksum calcuration with pseudo
// header on loopback multicast delivery process.
// If not, you'll probably see what is the slow-acting
// kernel crash caused by lazy mbuf corruption.
// See ip6_mloopback in netinet6/ip6_output.c.
if mjver, err := strconv.Atoi(ss[0]); err != nil || mjver < 13 {
return false
}
return true
default:
return true
}
}
示例5: LoadAvg
func LoadAvg() (s []string) {
v, err := syscall.Sysctl(sysctl)
t := time.Now()
etime := strconv.FormatInt(t.Unix(), 10)
if err != nil {
fmt.Println(err)
}
b := []byte(v)
var l loadavg = *(*loadavg)(unsafe.Pointer(&b[0]))
scale := float64(l.scale)
c := strconv.FormatFloat(float64(l.ldavg[0])/scale, 'f', 2, 64)
d := strconv.FormatFloat(float64(l.ldavg[1])/scale, 'f', 2, 64)
e := strconv.FormatFloat(float64(l.ldavg[2])/scale, 'f', 2, 64)
// returning as load.load.metric because that's what collectd does
f := fmt.Sprintf("load.load.shortterm %s %s", c, etime)
s = append(s, f)
g := fmt.Sprintf("load.load.midterm %s %s", d, etime)
s = append(s, g)
h := fmt.Sprintf("load.load.longterm %s %s", e, etime)
s = append(s, h)
return s
}
示例6: init
func init() {
// Seems like kern.osreldate is veiled on latest OS X. We use
// kern.osrelease instead.
osver, err := syscall.Sysctl("kern.osrelease")
if err != nil {
return
}
var i int
for i = range osver {
if osver[i] != '.' {
continue
}
}
// The IP_PKTINFO was introduced in OS X 10.7 (Darwin
// 11.0.0). See http://support.apple.com/kb/HT1633.
if i > 2 || i == 2 && osver[0] >= '1' && osver[1] >= '1' {
ctlOpts[ctlPacketInfo].name = sysIP_PKTINFO
ctlOpts[ctlPacketInfo].length = sysSizeofInetPktinfo
ctlOpts[ctlPacketInfo].marshal = marshalPacketInfo
ctlOpts[ctlPacketInfo].parse = parsePacketInfo
sockOpts[ssoPacketInfo].name = sysIP_RECVPKTINFO
sockOpts[ssoPacketInfo].typ = ssoTypeInt
sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
}
}
示例7: hostname
func hostname() (name string, err error) {
name, err = syscall.Sysctl("kern.hostname")
if err != nil {
return "", NewSyscallError("sysctl kern.hostname", err)
}
return name, nil
}
示例8: osName
// osName returns the name of the OS.
func osName() string {
name, err := syscall.Sysctl("kern.ostype")
if err != nil {
return runtime.GOOS
}
return name
}
示例9: IsVTXDisabled
// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start.
// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started.
func (d *Driver) IsVTXDisabled() bool {
features, err := syscall.Sysctl("machdep.cpu.features")
if err != nil {
log.Debugf("Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v", err)
return false
}
return isVTXDisabled(features)
}
示例10: Hostname
func Hostname() (name string, err Error) {
var errno int
name, errno = syscall.Sysctl("kern.hostname")
if errno != 0 {
return "", NewSyscallError("sysctl kern.hostname", errno)
}
return name, nil
}
示例11: trySysctl
func trySysctl() (string, error) {
v, err := syscall.Sysctl("osxfuse.version.number")
if err != nil {
log.Debug("mount: sysctl osxfuse.version.number:", "failed")
return "", err
}
log.Debug("mount: sysctl osxfuse.version.number:", v)
return v, nil
}
示例12: getOSInfo
func getOSInfo() (*OSInfo, error) {
osinfo := &OSInfo{}
var err error
osinfo.Name, err = syscall.Sysctl("kern.ostype")
if err != nil {
return nil, err
}
osinfo.Version, err = syscall.Sysctl("kern.osrelease")
if err != nil {
return nil, err
}
osinfo.Id = osinfo.Name
osinfo.IdLike = osinfo.Name
osinfo.PrettyName = osinfo.Name + " Kernel Version " + osinfo.Version
osinfo.VersionId = osinfo.Version
osinfo.HomeURL = "www.apple.com"
return osinfo, nil
}
示例13: getSystemUptime
// Returns system uptime as time.Duration.
func getSystemUptime() (uptime time.Duration, err error) {
val, err := syscall.Sysctl("kern.boottime")
if err != nil {
return 0, err
}
buf := []byte(val)
tv := *syscall.Timeval(unsafe.Pointer(&buf[0]))
return time.Since(time.Unix(tv.Unix())), nil
}
示例14: GetSystemInfo
// GetSystemInfo return system info
func GetSystemInfo() (*SystemInfo, error) {
hostname, err := syscall.Sysctl("kern.hostname")
if err != nil || hostname == "" {
return nil, errors.New("Can't read hostname info")
}
os, err := syscall.Sysctl("kern.ostype")
if err != nil || os == "" {
return nil, errors.New("Can't read os info")
}
kernel, err := syscall.Sysctl("kern.osrelease")
if err != nil || kernel == "" {
return nil, errors.New("Can't read kernel info")
}
arch, err := syscall.Sysctl("kern.version")
if err != nil || arch == "" {
return nil, errors.New("Can't read arch info")
}
archSlice := strings.Split(arch, "/")
if len(archSlice) != 2 {
return nil, errors.New("Can't read arch info")
}
cleanArch := strings.ToLower(strings.Replace(archSlice[len(archSlice)-1], "RELEASE_", "", -1))
return &SystemInfo{
Hostname: hostname,
OS: os,
Distribution: DARWIN_OSX,
Version: getOSXVersion(),
Kernel: kernel,
Arch: cleanArch,
}, nil
}
示例15: init
func init() {
if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
archs, _ := syscall.Sysctl("kern.supported_archs")
for _, s := range strings.Split(archs, " ") {
if strings.TrimSpace(s) == "amd64" {
freebsd32o64 = true
break
}
}
}
}