当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.SysctlUint32函数代码示例

本文整理汇总了Golang中syscall.SysctlUint32函数的典型用法代码示例。如果您正苦于以下问题:Golang SysctlUint32函数的具体用法?Golang SysctlUint32怎么用?Golang SysctlUint32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SysctlUint32函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: maxListenerBacklog

func maxListenerBacklog() int {
	var (
		n   uint32
		err error
	)

	switch runtime.GOOS {
	case "darwin", "freebsd":
		n, err = syscall.SysctlUint32("kern.ipc.somaxconn")
	case "netbsd":
		// NOTE: NetBSD has no somaxconn-like kernel state so far
	case "openbsd":
		n, err = syscall.SysctlUint32("kern.somaxconn")
	}

	if n == 0 || err != nil {
		return syscall.SOMAXCONN
	}

	// FreeBSD stores the backlog in a uint16, as does Linux.
	// Assume the other BSDs do too. Truncate number to avoid wrapping.
	// See issue 5030.
	if n > 1<<16-1 {
		n = 1<<16 - 1
	}
	return int(n)
}
开发者ID:kavu,项目名称:go_reuseport,代码行数:27,代码来源:reuseport_bsd.go

示例2: init

func init() {
	b1, err1 := syscall.SysctlUint32("kern.features.security_capabilities")
	b2, err2 := syscall.SysctlUint32("kern.features.security_capability_mode")
	if b1 != 0 && b2 != 0 && err1 == nil && err2 == nil {
		hasCapabilities = true
	}
}
开发者ID:hansstimer,项目名称:gocapsicum,代码行数:7,代码来源:exec_freebsd.go

示例3: init

func init() {
	osrel, err := syscall.SysctlUint32("kern.osreldate")
	if err != nil {
		return
	}
	// The O_CLOEXEC flag was introduced in FreeBSD 8.3.
	// See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
	if osrel >= 803000 {
		supportsCloseOnExec = true
	}
}
开发者ID:2thetop,项目名称:go,代码行数:11,代码来源:sys_freebsd.go

示例4: cpuInfo

func cpuInfo() (map[string]interface{}, error) {
	info := make(map[string]interface{})

	cpuKeys := map[string]string{"vendor": "vendor_id", "brand_string": "model_name"}
	for sysctlName, gohaiName := range cpuKeys {
		k, err := syscall.Sysctl("machdep.cpu." + sysctlName)
		if err != nil {
			return nil, err
		}
		info[gohaiName] = k
	}
	cpuKeyInts := map[string]string{"model": "model", "family": "family", "stepping": "stepping"}
	for sysctlName, gohaiName := range cpuKeyInts {
		k, err := syscall.SysctlUint32("machdep.cpu." + sysctlName)
		if err != nil {
			return nil, err
		}
		info[gohaiName] = k
	}
	hwKeyInts := map[string]string{"physicalcpu": "real", "logicalcpu": "total", "cpufrequency": "mhz"}
	for sysctlName, gohaiName := range hwKeyInts {
		k, err := syscall.SysctlUint32("hw." + sysctlName)
		if err != nil {
			return nil, err
		}
		info[gohaiName] = k
	}
	info["mhz"] = info["mhz"].(uint32) / 1000000

	cpuFlags, err := syscall.Sysctl("machdep.cpu.features")
	if err != nil {
		return nil, err
	}
	info["flags"] = strings.Split(strings.ToLower(cpuFlags), " ")

	return info, nil
}
开发者ID:ctdk,项目名称:gosudar,代码行数:37,代码来源:gosudar_mac.go

示例5: init

func init() {
	freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
	if freebsdVersion >= 1000000 {
		sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
	}
	if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
		archs, _ := syscall.Sysctl("kern.supported_archs")
		for _, s := range strings.Fields(archs) {
			if s == "amd64" {
				freebsd32o64 = true
				break
			}
		}
	}
}
开发者ID:2722,项目名称:lantern,代码行数:15,代码来源:sys_freebsd.go

示例6: maxListenerBacklog

func maxListenerBacklog() int {
	var (
		n   uint32
		err error
	)
	n, err = syscall.SysctlUint32("kern.ipc.somaxconn")
	if n == 0 || err != nil {
		return syscall.SOMAXCONN
	}
	// FreeBSD stores the backlog in a uint16, as does Linux.
	// Assume the other BSDs do too. Truncate number to avoid wrapping.
	// See issue 5030.
	if n > 1<<16-1 {
		n = 1<<16 - 1
	}
	return int(n)
}
开发者ID:htee,项目名称:hteed,代码行数:17,代码来源:socket_darwin.go

示例7: printUptime

func printUptime(us []utmp.Utmp) {

	var (
		bootTime int32
		entries  int64
		now      utmp.TimeVal

		days, hours, mins int
		uptime            float64
	)

	request := "kern.boottime"
	secs, err := syscall.SysctlUint32(request)
	if err != nil {
		panic(err)
	}
	secs = float64(secs)

	if 0 <= secs || secs < math.MaxFloat64 {
		uptime = secs
	} else {
		uptime = -1
	}

	for _, v := range us {

		if v.IsUserProcess() {
			entries++
		}

		if v.Type == utmp.BootTime {
			bootTime = v.Time.Sec
		}
	}

	now.GetTimeOfDay()
	if uptime == 0 {
		if bootTime == 0 {
			fatal.Fatalln("couldn't get boot time")
		}

		uptime = float64(now.Sec - bootTime)
	}

	days = int(uptime) / 86400
	hours = (int(uptime) - (days * 86400)) / 3600
	mins = (int(uptime) - (days * 86400) - (hours * 3600)) / 60

	fmt.Print(time.Now().Local().Format(" 15:04pm  "))

	if uptime == -1 {
		fmt.Print("up ???? days ??:??,  ")
	} else {
		if 0 < days {
			if days > 1 {
				fmt.Printf("up %d days %2d:%02d,  ", days, hours, mins)
			} else {
				fmt.Printf("up %d day %2d:%02d,  ", days, hours, mins)
			}
		} else {
			fmt.Printf("up  %2d:%02d,  ", hours, mins)
		}
	}

	if len(us) > 1 || len(us) == 0 {
		fmt.Printf("%d users", entries)
	} else {
		fmt.Printf("%d user", entries)
	}

	var avg [3]float64
	loads := stdlib.GetLoadAvg(&avg)

	if loads == -1 {
		fmt.Printf("%s", "\n")
	} else {
		if loads > 0 {
			fmt.Printf(",  load average: %.2f", avg[0])
		}

		if loads > 1 {
			fmt.Printf(", %.2f", avg[1])
		}

		if loads > 2 {
			fmt.Printf(", %.2f", avg[2])
		}

		if loads > 0 {
			fmt.Printf("%s", "\n")
		}
	}
}
开发者ID:postfix,项目名称:go-coreutils,代码行数:93,代码来源:uptime_freebsd.go

示例8:

func ext۰syscall۰SysctlUint32(fr *frame, args []value) value {
	r, err := syscall.SysctlUint32(args[0].(string))
	return tuple{r, wrapError(err)}
}
开发者ID:2722,项目名称:lantern,代码行数:4,代码来源:external_freebsd.go

示例9: init

func init() {
	freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
	if freebsdVersion >= 1000000 {
		sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
	}
}
开发者ID:XavierBerger,项目名称:go.net,代码行数:6,代码来源:sys_freebsd.go

示例10: probeRoutingStack

func probeRoutingStack() (int, map[int]parseFn) {
	var p uintptr
	wordSize := int(unsafe.Sizeof(p))
	align := int(unsafe.Sizeof(p))
	// In the case of kern.supported_archs="amd64 i386", we need
	// to know the underlying kernel's architecture because the
	// alignment for routing facilities are set at the build time
	// of the kernel.
	conf, _ := syscall.Sysctl("kern.conftxt")
	for i, j := 0, 0; j < len(conf); j++ {
		if conf[j] != '\n' {
			continue
		}
		s := conf[i:j]
		i = j + 1
		if len(s) > len("machine") && s[:len("machine")] == "machine" {
			s = s[len("machine"):]
			for k := 0; k < len(s); k++ {
				if s[k] == ' ' || s[k] == '\t' {
					s = s[1:]
				}
				break
			}
			if s == "amd64" {
				align = 8
			}
			break
		}
	}
	var rtm, ifm, ifam, ifmam, ifanm *wireFormat
	if align != wordSize { // 386 emulation on amd64
		rtm = &wireFormat{extOff: sizeofRtMsghdrFreeBSD10Emu - sizeofRtMetricsFreeBSD10Emu, bodyOff: sizeofRtMsghdrFreeBSD10Emu}
		ifm = &wireFormat{extOff: 16}
		ifam = &wireFormat{extOff: sizeofIfaMsghdrFreeBSD10Emu, bodyOff: sizeofIfaMsghdrFreeBSD10Emu}
		ifmam = &wireFormat{extOff: sizeofIfmaMsghdrFreeBSD10Emu, bodyOff: sizeofIfmaMsghdrFreeBSD10Emu}
		ifanm = &wireFormat{extOff: sizeofIfAnnouncemsghdrFreeBSD10Emu, bodyOff: sizeofIfAnnouncemsghdrFreeBSD10Emu}
	} else {
		rtm = &wireFormat{extOff: sizeofRtMsghdrFreeBSD10 - sizeofRtMetricsFreeBSD10, bodyOff: sizeofRtMsghdrFreeBSD10}
		ifm = &wireFormat{extOff: 16}
		ifam = &wireFormat{extOff: sizeofIfaMsghdrFreeBSD10, bodyOff: sizeofIfaMsghdrFreeBSD10}
		ifmam = &wireFormat{extOff: sizeofIfmaMsghdrFreeBSD10, bodyOff: sizeofIfmaMsghdrFreeBSD10}
		ifanm = &wireFormat{extOff: sizeofIfAnnouncemsghdrFreeBSD10, bodyOff: sizeofIfAnnouncemsghdrFreeBSD10}
	}
	rel, _ := syscall.SysctlUint32("kern.osreldate")
	switch {
	case rel < 800000:
		if align != wordSize { // 386 emulation on amd64
			ifm.bodyOff = sizeofIfMsghdrFreeBSD7Emu
		} else {
			ifm.bodyOff = sizeofIfMsghdrFreeBSD7
		}
	case 800000 <= rel && rel < 900000:
		if align != wordSize { // 386 emulation on amd64
			ifm.bodyOff = sizeofIfMsghdrFreeBSD8Emu
		} else {
			ifm.bodyOff = sizeofIfMsghdrFreeBSD8
		}
	case 900000 <= rel && rel < 1000000:
		if align != wordSize { // 386 emulation on amd64
			ifm.bodyOff = sizeofIfMsghdrFreeBSD9Emu
		} else {
			ifm.bodyOff = sizeofIfMsghdrFreeBSD9
		}
	case 1000000 <= rel && rel < 1100000:
		if align != wordSize { // 386 emulation on amd64
			ifm.bodyOff = sizeofIfMsghdrFreeBSD10Emu
		} else {
			ifm.bodyOff = sizeofIfMsghdrFreeBSD10
		}
	default:
		if align != wordSize { // 386 emulation on amd64
			ifm.bodyOff = sizeofIfMsghdrFreeBSD11Emu
		} else {
			ifm.bodyOff = sizeofIfMsghdrFreeBSD11
		}
	}
	return align, map[int]parseFn{
		sysRTM_ADD:        rtm.parseRouteMessage,
		sysRTM_DELETE:     rtm.parseRouteMessage,
		sysRTM_CHANGE:     rtm.parseRouteMessage,
		sysRTM_GET:        rtm.parseRouteMessage,
		sysRTM_LOSING:     rtm.parseRouteMessage,
		sysRTM_REDIRECT:   rtm.parseRouteMessage,
		sysRTM_MISS:       rtm.parseRouteMessage,
		sysRTM_LOCK:       rtm.parseRouteMessage,
		sysRTM_RESOLVE:    rtm.parseRouteMessage,
		sysRTM_NEWADDR:    ifam.parseInterfaceAddrMessage,
		sysRTM_DELADDR:    ifam.parseInterfaceAddrMessage,
		sysRTM_IFINFO:     ifm.parseInterfaceMessage,
		sysRTM_NEWMADDR:   ifmam.parseInterfaceMulticastAddrMessage,
		sysRTM_DELMADDR:   ifmam.parseInterfaceMulticastAddrMessage,
		sysRTM_IFANNOUNCE: ifanm.parseInterfaceAnnounceMessage,
	}
}
开发者ID:2thetop,项目名称:go,代码行数:94,代码来源:sys_freebsd.go

示例11: init

func init() {
	freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:3,代码来源:sys_freebsd.go


注:本文中的syscall.SysctlUint32函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。