all: use unix.ByteSliceToString for utsname fields
This also fixes the GetOperatingSystem function in
pkg/parsers/operatingsystem which mistakenly truncated utsname.Machine
to the index of \0 in utsname.Sysname.
Fixes: 7aeb3efcb4
Cc: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
1a0587bd76
commit
8a5c13155e
|
@ -6,9 +6,8 @@
|
||||||
package kernel // import "github.com/docker/docker/pkg/parsers/kernel"
|
package kernel // import "github.com/docker/docker/pkg/parsers/kernel"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetKernelVersion gets the current kernel version.
|
// 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
|
// 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)
|
// CheckKernelVersion checks if current kernel is newer than (or equal to)
|
||||||
|
|
|
@ -16,7 +16,7 @@ func GetOperatingSystem() (string, error) {
|
||||||
if err := unix.Uname(utsname); err != nil {
|
if err := unix.Uname(utsname); err != nil {
|
||||||
return "", err
|
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.
|
// GetOperatingSystemVersion gets the version of the current operating system, as a string.
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
package platform // import "github.com/docker/docker/pkg/platform"
|
package platform // import "github.com/docker/docker/pkg/platform"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,5 +15,5 @@ func runtimeArchitecture() (string, error) {
|
||||||
if err := unix.Uname(utsname); err != nil {
|
if err := unix.Uname(utsname); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]), nil
|
return unix.ByteSliceToString(utsname.Machine[:]), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package seccomp
|
package seccomp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ func getKernelVersion() (*KernelVersion, error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Remove the \x00 from the release for Atoi to parse correctly
|
// 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
|
return currentKernelVersion, kernelVersionError
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue