Merge pull request #43616 from kolyshkin/byte-slice-to-string

all: use unix.ByteSliceToString for utsname fields
This commit is contained in:
Sebastiaan van Stijn 2022-05-19 11:28:07 +02:00 committed by GitHub
commit c9d04033d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 9 deletions

View file

@ -6,9 +6,8 @@
package kernel // import "github.com/docker/docker/pkg/parsers/kernel"
import (
"bytes"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
// GetKernelVersion gets the current kernel version.
@ -19,7 +18,7 @@ func GetKernelVersion() (*VersionInfo, error) {
}
// Remove the \x00 from the release for Atoi to parse correctly
return ParseRelease(string(uts.Release[:bytes.IndexByte(uts.Release[:], 0)]))
return ParseRelease(unix.ByteSliceToString(uts.Release[:]))
}
// CheckKernelVersion checks if current kernel is newer than (or equal to)

View file

@ -16,7 +16,7 @@ func GetOperatingSystem() (string, error) {
if err := unix.Uname(utsname); err != nil {
return "", err
}
return string(utsname.Machine[:bytes.IndexByte(utsname.Sysname[:], 0)]), nil
return unix.ByteSliceToString(utsname.Machine[:]), nil
}
// GetOperatingSystemVersion gets the version of the current operating system, as a string.

View file

@ -6,8 +6,6 @@
package platform // import "github.com/docker/docker/pkg/platform"
import (
"bytes"
"golang.org/x/sys/unix"
)
@ -17,5 +15,5 @@ func runtimeArchitecture() (string, error) {
if err := unix.Uname(utsname); err != nil {
return "", err
}
return string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]), nil
return unix.ByteSliceToString(utsname.Machine[:]), nil
}

View file

@ -1,7 +1,6 @@
package seccomp
import (
"bytes"
"fmt"
"sync"
@ -22,7 +21,7 @@ func getKernelVersion() (*KernelVersion, error) {
return
}
// Remove the \x00 from the release for Atoi to parse correctly
currentKernelVersion, kernelVersionError = parseRelease(string(uts.Release[:bytes.IndexByte(uts.Release[:], 0)]))
currentKernelVersion, kernelVersionError = parseRelease(unix.ByteSliceToString(uts.Release[:]))
})
return currentKernelVersion, kernelVersionError
}