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


Golang syscall.Uname函数代码示例

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


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

示例1: runtimeArchitecture

// 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
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:8,代码来源:architecture_linux.go

示例2: main

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)
	}
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:30,代码来源:domainname.go

示例3: getKernelVersion

// 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
}
开发者ID:JioCloud,项目名称:docker,代码行数:61,代码来源:getKernelVersion_linux.go

示例4: checkForUpdates

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(&params, updateCheckPeriod, handleResponse)
}
开发者ID:n054,项目名称:weave,代码行数:34,代码来源:checkpoint.go

示例5: getUname

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

}
开发者ID:0xef53,项目名称:phoenix-guest-agent,代码行数:29,代码来源:sysinfo.go

示例6: Uname

// 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
}
开发者ID:u-root,项目名称:u-root,代码行数:8,代码来源:uname_ppc64le.go

示例7: osVersion

// 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)
}
开发者ID:Cdim,项目名称:pholcus,代码行数:9,代码来源:agent_linux.go

示例8: osName

// 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)
}
开发者ID:Cdim,项目名称:pholcus,代码行数:9,代码来源:agent_linux.go

示例9: GetString

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
}
开发者ID:akkakks,项目名称:osversion,代码行数:8,代码来源:osversion_linux.go

示例10: uname

func uname() (*syscall.Utsname, error) {
	uts := &syscall.Utsname{}

	if err := syscall.Uname(uts); err != nil {
		return nil, err
	}
	return uts, nil
}
开发者ID:CtrlZvi,项目名称:public-ipv6-bridge,代码行数:8,代码来源:uname_linux.go

示例11: Platform

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
}
开发者ID:piaobocpp,项目名称:platform,代码行数:10,代码来源:Platform_linux.go

示例12: genInfo

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
}
开发者ID:patrickToca,项目名称:go-coreutils,代码行数:11,代码来源:uname_linux.go

示例13: GenInfo

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,
	}
}
开发者ID:HarryBird,项目名称:go-coreutils,代码行数:12,代码来源:uname.go

示例14: uname

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")
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:13,代码来源:modinfo.go

示例15: getKernelVersion

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
}
开发者ID:dilgerma,项目名称:scope,代码行数:13,代码来源:proc_linux.go


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