From 41d9844225ef363a5dd4f7d504053e96ba725f90 Mon Sep 17 00:00:00 2001 From: Andy Bradshaw Date: Mon, 3 Apr 2023 12:24:26 -0400 Subject: [PATCH] Fix cpu.shares content parsing (#321) Fix cpu.shares content parsing --- changelog/@unreleased/pr-321.v2.yml | 5 +++++ launchlib/processors.go | 2 +- launchlib/processors_test.go | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelog/@unreleased/pr-321.v2.yml diff --git a/changelog/@unreleased/pr-321.v2.yml b/changelog/@unreleased/pr-321.v2.yml new file mode 100644 index 00000000..e976ea6e --- /dev/null +++ b/changelog/@unreleased/pr-321.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Fix cpu.shares content parsing + links: + - https://github.com/palantir/go-java-launcher/pull/321 diff --git a/launchlib/processors.go b/launchlib/processors.go index c3e1a5e0..4bccc35f 100644 --- a/launchlib/processors.go +++ b/launchlib/processors.go @@ -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") } diff --git a/launchlib/processors_test.go b/launchlib/processors_test.go index efcad816..c2e84326 100644 --- a/launchlib/processors_test.go +++ b/launchlib/processors_test.go @@ -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(``) )