uptime: correctly calculate boot-time #4440
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.
Correctly calculate boot-time on Unix systems that cannot access
/proc/uptime
(eg, macOS).The number of seconds since boot-time was calculated using the seconds component of OffsetDateTime (eg, boot-time of
2023-02-25 17:46:27
would returnSome(27_i64)
) rather the total number of seconds since the Unix epoch. Meaninguptime
would believe that the boot-time of the system would always be somewhere between1970-01-01 00:00:00
and1970-01-01 00:00:59
.And I can guarantee that my M1 mac has not been up for 53 years 😉
Example terminal output:
This was a very easy bug to miss, since (a) this would only be apparent on Unix systems that do not have a
/proc/uptime
, and (b) the tests could only validate that a value is returned and not whether that value was correct (to do so the tests would need to have knowledge of how long the underlying system has been up - needuptime
to testuptime
).