fix: use unix.Utsname instead of syscall.Utsname

This commit is contained in:
mzz2017 2023-03-08 16:58:56 +08:00
parent 38abfcec99
commit c691d5b37a
3 changed files with 13 additions and 41 deletions

View File

@ -1,18 +0,0 @@
//go:build !(arm || arm64 || arm64be || armbe || riscv64)
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) 2023, v2rayA Organization <team@v2raya.org>
*/
package internal
// utsnameToString converts the utsname to a string and returns it.
func utsnameToString(unameArray [65]int8) string {
var byteString [65]byte
var indexLength int
for ; unameArray[indexLength] != 0; indexLength++ {
byteString[indexLength] = uint8(unameArray[indexLength])
}
return string(byteString[:indexLength])
}

View File

@ -1,18 +0,0 @@
//go:build arm || arm64 || arm64be || armbe || riscv64
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) 2023, v2rayA Organization <team@v2raya.org>
*/
package internal
// utsnameToString converts the utsname to a string and returns it.
func utsnameToString(unameArray [65]uint8) string {
var byteString [65]byte
var indexLength int
for ; unameArray[indexLength] != 0; indexLength++ {
byteString[indexLength] = unameArray[indexLength]
}
return string(byteString[:indexLength])
}

View File

@ -4,10 +4,8 @@ package internal
import (
"fmt"
"sync"
"syscall"
"github.com/v2rayA/dae/pkg/ebpf_internal/internal/unix"
"sync"
)
const (
@ -90,14 +88,24 @@ func (v Version) Kernel() uint32 {
return uint32(uint8(v[0]))<<16 | uint32(uint8(v[1]))<<8 | uint32(uint8(s))
}
// utsnameToString converts the utsname to a string and returns it.
func utsnameToString(unameArray [65]byte) string {
var byteString [65]byte
var indexLength int
for ; unameArray[indexLength] != 0; indexLength++ {
byteString[indexLength] = unameArray[indexLength]
}
return string(byteString[:indexLength])
}
// KernelVersion returns the version of the currently running kernel.
func KernelVersion() (Version, error) {
kernelVersion.once.Do(func() {
kernelVersion.version, kernelVersion.err = detectKernelVersion()
if kernelVersion.err != nil {
// Try syscall.
var utsname syscall.Utsname
if err := syscall.Uname(&utsname); err != nil {
var utsname unix.Utsname
if err := unix.Uname(&utsname); err != nil {
kernelVersion.err = fmt.Errorf("%w; %v", kernelVersion.err, err)
return
}