Skip to content

unix: fix uv_uptime() on linux#3072

Closed
schamberg97 wants to merge 5 commits intolibuv:v1.xfrom
schamberg97:v1.x
Closed

unix: fix uv_uptime() on linux#3072
schamberg97 wants to merge 5 commits intolibuv:v1.xfrom
schamberg97:v1.x

Conversation

@schamberg97
Copy link
Contributor

This change fixes #3068 on OpenVZ Containers in Linux.

This change fixes libuv#3068 on OpenVZ Containers in Linux
@schamberg97
Copy link
Contributor Author

schamberg97 commented Dec 14, 2020

@bnoordhuis

Running make check on OpenVZ system with my patch produces this:

ok 1 - platform_output
# Output from process `platform_output`:
# uv_get_process_title: /home/nik/libuv/test/.libs/run-tests
# uv_cwd: /home/nik/libuv
# uv_resident_set_memory: 1056768
# uv_uptime: 621523.990000
...
...

checking /proc/uptime/ a bit later:

nik@vps1607355603:~/libuv$ cat /proc/uptime
621534.08 621342.55

Just to check that Host uptime is significantly bigger (with clock_gettime) and I have indeed solved the issue:

Code used:

#include <time.h>
#include <errno.h>
#include <stdio.h>

int main() {
  struct timespec now;
  int r;

  r = clock_gettime(CLOCK_BOOTTIME, &now);
  if (r != 0) {
    fprintf(stderr, "clock_gettime failed with %d\n", errno);
    return errno;
  }
  fprintf(stderr, "system uptime: %ld\n", now.tv_sec);
  return 0;
}

result after compiling and running: system uptime: 1899806

schamberg97 and others added 4 commits December 15, 2020 02:33
Reword comment

Co-authored-by: Ben Noordhuis <[email protected]>
Style + code fix

Co-authored-by: Ben Noordhuis <[email protected]>
Co-authored-by: Ben Noordhuis <[email protected]>
Fix styling (added missing newline)
@schamberg97
Copy link
Contributor Author

@bnoordhuis I've made the requested changes

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Member

@santigimeno santigimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@santigimeno
Copy link
Member

santigimeno commented Dec 28, 2020

Landed in b2ccbbb. Thanks!

santigimeno pushed a commit that referenced this pull request Dec 28, 2020
First check `/proc/uptime`, then fallback to `clock_gettime()`.

Fixes: #3068
PR-URL: #3072
Co-authored-by: Ben Noordhuis <[email protected]>
Reviewed-by: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
santigimeno added a commit to santigimeno/libuv that referenced this pull request Dec 28, 2020
As it was in the original version of
libuv#3072, `%lf` must be used in
`sscanf()` as the value is being stored in a `double` and not a `float`.
santigimeno added a commit to santigimeno/libuv that referenced this pull request Dec 30, 2020
As it was in the original version of
libuv#3072, `%lf` must be used in
`sscanf()` as the value is being stored in a `double` and not a `float`.

PR-URL: libuv#3080
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
targos added a commit to targos/node that referenced this pull request May 1, 2021
This reverts commit b9ffb82.

The bug was fixed in libuv 1.41.0.

Refs: libuv/libuv#3072
targos added a commit to nodejs/node that referenced this pull request May 3, 2021
This reverts commit b9ffb82.

The bug was fixed in libuv 1.41.0.

Refs: libuv/libuv#3072

PR-URL: #38494
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
targos added a commit to nodejs/node that referenced this pull request May 3, 2021
This reverts commit b9ffb82.

The bug was fixed in libuv 1.41.0.

Refs: libuv/libuv#3072

PR-URL: #38494
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
JeffroMF pushed a commit to JeffroMF/libuv that referenced this pull request May 16, 2022
First check `/proc/uptime`, then fallback to `clock_gettime()`.

Fixes: libuv#3068
PR-URL: libuv#3072
Co-authored-by: Ben Noordhuis <[email protected]>
Reviewed-by: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
JeffroMF pushed a commit to JeffroMF/libuv that referenced this pull request May 16, 2022
As it was in the original version of
libuv#3072, `%lf` must be used in
`sscanf()` as the value is being stored in a `double` and not a `float`.

PR-URL: libuv#3080
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
liujinye-sys pushed a commit to open-vela/apps_system_libuv that referenced this pull request Jul 23, 2025
First check `/proc/uptime`, then fallback to `clock_gettime()`.

Fixes: libuv/libuv#3068
PR-URL: libuv/libuv#3072
Co-authored-by: Ben Noordhuis <[email protected]>
Reviewed-by: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
liujinye-sys pushed a commit to open-vela/apps_system_libuv that referenced this pull request Jul 23, 2025
As it was in the original version of
libuv/libuv#3072, `%lf` must be used in
`sscanf()` as the value is being stored in a `double` and not a `float`.

PR-URL: libuv/libuv#3080
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
liujinye-sys pushed a commit to open-vela/apps_system_libuv that referenced this pull request Dec 16, 2025
First check `/proc/uptime`, then fallback to `clock_gettime()`.

Fixes: libuv/libuv#3068
PR-URL: libuv/libuv#3072
Co-authored-by: Ben Noordhuis <[email protected]>
Reviewed-by: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
liujinye-sys pushed a commit to open-vela/apps_system_libuv that referenced this pull request Dec 16, 2025
As it was in the original version of
libuv/libuv#3072, `%lf` must be used in
`sscanf()` as the value is being stored in a `double` and not a `float`.

PR-URL: libuv/libuv#3080
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv_uptime returns incorrect values on OpenVZ containers.

3 participants