Skip to content

Commit

Permalink
Fix cpu.shares content parsing (#321)
Browse files Browse the repository at this point in the history
Fix cpu.shares content parsing
  • Loading branch information
andybradshaw authored Apr 3, 2023
1 parent ce89fb7 commit 41d9844
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-321.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Fix cpu.shares content parsing
links:
- https://github.com/palantir/go-java-launcher/pull/321
2 changes: 1 addition & 1 deletion launchlib/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c CGroupV1ProcessorCounter) ProcessorCount() (uint, error) {
if err != nil {
return 0, errors.Wrapf(err, "unable to read cpu.shares")
}
cpuShares, err := strconv.Atoi(string(cpuShareBytes))
cpuShares, err := strconv.Atoi(strings.TrimSpace(string(cpuShareBytes)))
if err != nil {
return 0, errors.New("unable to convert cpu.shares value to expected type")
}
Expand Down
4 changes: 2 additions & 2 deletions launchlib/processors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ var (
3473 5088 0:435 / /proc/scsi ro,relatime - tmpfs tmpfs ro
3474 5092 0:436 / /sys/firmware ro,relatime - tmpfs tmpfs ro`)

lowCPUSharesContent = []byte(`100`)
highCPUSharesContent = []byte(`10000`)
lowCPUSharesContent = []byte("100\n")
highCPUSharesContent = []byte("10000\n")
badCPUSharesContent = []byte(``)
)

Expand Down

0 comments on commit 41d9844

Please sign in to comment.