Пример #1
0
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)
}
Пример #2
0
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
	}
}
Пример #3
0
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
	}
	return int(n)
}
Пример #4
0
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
	}
}
Пример #5
0
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
}
Пример #6
0
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
			}
		}
	}
}
Пример #7
0
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)
}
Пример #8
0
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")
		}
	}
}
Пример #9
0
func ext۰syscall۰SysctlUint32(fr *frame, args []value) value {
	r, err := syscall.SysctlUint32(args[0].(string))
	return tuple{r, wrapError(err)}
}
Пример #10
0
func init() {
	freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
	if freebsdVersion >= 1000000 {
		sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
	}
}
Пример #11
0
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,
	}
}
Пример #12
0
func init() {
	freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
}