add current values to rlimit retrieval #346
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements the proposal in #344
During development of this, I uncovered a few issues with the current state of things.
RlimitStat
usesint32
for the limit values. This is insufficient as limits can overflow anint32
.Rlimit()
usesmath.MaxInt32
to denote unlimited. It's possible for this to be the actual value of a limit.RLIMIT_INFINITY
is typically-1
for this reason. Edit: This is really related to the first issue. The kernel uses-1
, but once we're usinguint64
, the max value of the type is accurate as the-1
underflows to the max uint64 value.There is one deficiency in this implementation. There is no way to differentiate between "no current value" and "current value is 0". We could use
int64(-1)
to indicate "no current value). This might make sense if we fix theRlimitStat
issue to also useint64(-1)
for unlimited. Open to suggestions.Also from a consumer point of view, working with the rlimits is very cumbersome. If the consumer of gopsutil wants to get a specific rlimit, they have to iterate through every one to find the one they want. A
map[int]RlimitStat
(with theint
key beingRLIMIT_*
constants) would be much easier to work with.From a consumer standpoint, it would also be convenient if there were a way to get the string name for a
RLIMIT_*
constant. Currently the consumer needs to maintain a map of the int values to their string names.Closes #344