-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move parsing functions to pkg/parsers and the specific kernel handling
functions to pkg/parsers/kernel, and parsing filters to pkg/parsers/filter. Adjust imports and package references. Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <[email protected]> (github: erikh)
- Loading branch information
Erik Hollensbe
committed
Jul 29, 2014
1 parent
335e82f
commit 4398108
Showing
28 changed files
with
400 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Erik Hollensbe <[email protected]> (@erikh) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package kernel | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type KernelVersionInfo struct { | ||
Kernel int | ||
Major int | ||
Minor int | ||
Flavor string | ||
} | ||
|
||
func (k *KernelVersionInfo) String() string { | ||
return fmt.Sprintf("%d.%d.%d%s", k.Kernel, k.Major, k.Minor, k.Flavor) | ||
} | ||
|
||
// Compare two KernelVersionInfo struct. | ||
// Returns -1 if a < b, 0 if a == b, 1 it a > b | ||
func CompareKernelVersion(a, b *KernelVersionInfo) int { | ||
if a.Kernel < b.Kernel { | ||
return -1 | ||
} else if a.Kernel > b.Kernel { | ||
return 1 | ||
} | ||
|
||
if a.Major < b.Major { | ||
return -1 | ||
} else if a.Major > b.Major { | ||
return 1 | ||
} | ||
|
||
if a.Minor < b.Minor { | ||
return -1 | ||
} else if a.Minor > b.Minor { | ||
return 1 | ||
} | ||
|
||
return 0 | ||
} | ||
|
||
func GetKernelVersion() (*KernelVersionInfo, error) { | ||
var ( | ||
err error | ||
) | ||
|
||
uts, err := uname() | ||
if 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)] | ||
|
||
return ParseRelease(string(release)) | ||
} | ||
|
||
func ParseRelease(release string) (*KernelVersionInfo, error) { | ||
var ( | ||
kernel, major, minor, parsed int | ||
flavor, partial string | ||
) | ||
|
||
// Ignore error from Sscanf to allow an empty flavor. Instead, just | ||
// make sure we got all the version numbers. | ||
parsed, _ = fmt.Sscanf(release, "%d.%d%s", &kernel, &major, &partial) | ||
if parsed < 2 { | ||
return nil, errors.New("Can't parse kernel version " + release) | ||
} | ||
|
||
// sometimes we have 3.12.25-gentoo, but sometimes we just have 3.12-1-amd64 | ||
parsed, _ = fmt.Sscanf(partial, ".%d%s", &minor, &flavor) | ||
if parsed < 1 { | ||
flavor = partial | ||
} | ||
|
||
return &KernelVersionInfo{ | ||
Kernel: kernel, | ||
Major: major, | ||
Minor: minor, | ||
Flavor: flavor, | ||
}, nil | ||
} |
Oops, something went wrong.