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

Fix Proc.Limits limit name matching #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion proc_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"regexp"
"strconv"
"strings"
)

// ProcLimits represents the soft limits for each of the process's resource
Expand Down Expand Up @@ -106,7 +107,7 @@ func (p Proc) Limits() (ProcLimits, error) {
return ProcLimits{}, fmt.Errorf("%w: couldn't parse %q line %q", ErrFileParse, f.Name(), s.Text())
}

switch fields[1] {
switch strings.TrimSpace(fields[1]) {
case "Max cpu time":
l.CPUTime, err = parseUint(fields[2])
case "Max file size":
Expand Down
13 changes: 12 additions & 1 deletion proc_limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ func TestLimits(t *testing.T) {
have uint64
}{
{name: "cpu time", want: 18446744073709551615, have: l.CPUTime},
{name: "file size", want: 18446744073709551615, have: l.FileSize},
{name: "data size", want: 18446744073709551615, have: l.DataSize},
{name: "stack size", want: 8388608, have: l.StackSize},
{name: "core file size", want: 0, have: l.CoreFileSize},
{name: "resident set", want: 18446744073709551615, have: l.ResidentSet},
{name: "processes", want: 62898, have: l.Processes},
{name: "open files", want: 2048, have: l.OpenFiles},
{name: "locked memory", want: 18446744073708503040, have: l.LockedMemory},
{name: "address space", want: 8589934592, have: l.AddressSpace},
{name: "file locks", want: 18446744073709551615, have: l.FileLocks},
{name: "pending signals", want: 62898, have: l.PendingSignals},
{name: "msgqueue size", want: 819200, have: l.MsqqueueSize},
{name: "nice priority", want: 0, have: l.NicePriority},
{name: "address space", want: 8589934592, have: l.AddressSpace},
{name: "realtime priority", want: 0, have: l.RealtimePriority},
{name: "realtime timeout", want: 18446744073709551615, have: l.RealtimeTimeout},
} {
if test.want != test.have {
t.Errorf("want %s %d, have %d", test.name, test.want, test.have)
Expand Down