Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/parsers/kernel: simplify #1889

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions pkg/parsers/kernel/kernel_unix.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
//go:build linux || freebsd || solaris || openbsd
// +build linux freebsd solaris openbsd

// Package kernel provides helper function to get, parse and compare kernel
// versions for different platforms.
package kernel

import (
"bytes"

"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

// GetKernelVersion gets the current kernel version.
func GetKernelVersion() (*VersionInfo, error) {
uts, err := uname()
if err != nil {
return nil, err
}
uts := &unix.Utsname{}

release := make([]byte, len(uts.Release))

i := 0
for _, c := range uts.Release {
release[i] = byte(c)
i++
if err := unix.Uname(uts); err != nil {
return nil, err
}

// Remove the \x00 from the release for Atoi to parse correctly
release = release[:bytes.IndexByte(release, 0)]

return ParseRelease(string(release))
return ParseRelease(unix.ByteSliceToString(uts.Release[:]))
}

// CheckKernelVersion checks if current kernel is newer than (or equal to)
Expand Down
17 changes: 0 additions & 17 deletions pkg/parsers/kernel/uname_freebsd.go

This file was deleted.

17 changes: 0 additions & 17 deletions pkg/parsers/kernel/uname_linux.go

This file was deleted.

14 changes: 0 additions & 14 deletions pkg/parsers/kernel/uname_solaris.go

This file was deleted.

14 changes: 0 additions & 14 deletions pkg/parsers/kernel/uname_unsupported.go

This file was deleted.

11 changes: 0 additions & 11 deletions pkg/parsers/kernel/uname_unsupported_type.go

This file was deleted.