本文整理汇总了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
}
示例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)
}
}
示例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
}
示例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(¶ms, updateCheckPeriod, handleResponse)
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例10: uname
func uname() (*syscall.Utsname, error) {
uts := &syscall.Utsname{}
if err := syscall.Uname(uts); err != nil {
return nil, err
}
return uts, nil
}
示例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
}
示例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
}
示例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,
}
}
示例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")
}
示例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
}