diff options
| author | Bruno Haible <bruno@clisp.org> | 2023-08-15 12:01:13 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-08-15 14:01:58 -0700 |
| commit | d8cfa5db49641f39b63aba2037c6a9e6bd95c0e0 (patch) | |
| tree | ab5143fca855f82f9926293c8c4b0a13e7fdec3c | |
| parent | build: update gnulib submodule to latest (diff) | |
| download | coreutils-d8cfa5db49641f39b63aba2037c6a9e6bd95c0e0.tar.gz coreutils-d8cfa5db49641f39b63aba2037c6a9e6bd95c0e0.zip | |
uptime: Include VM sleep time in the "up" duration
* src/uptime.c: Don't include c-strtod.h.
(print_uptime): Don't read /proc/uptime, because the value it provides
does not change when a date adjustment occurs.
* bootstrap.conf (gnulib_modules): Remove 'uptime'.
| -rw-r--r-- | bootstrap.conf | 1 | ||||
| -rw-r--r-- | src/uptime.c | 36 |
2 files changed, 6 insertions, 31 deletions
diff --git a/bootstrap.conf b/bootstrap.conf index 6ce27d5dd..d758a9ff6 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -285,7 +285,6 @@ gnulib_modules=" unlocked-io unsetenv update-copyright - uptime useless-if-before-free userspec utimecmp diff --git a/src/uptime.c b/src/uptime.c index 22a3bdb19..813d29430 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -30,7 +30,6 @@ # include <OS.h> #endif -#include "c-strtod.h" #include "long-options.h" #include "quote.h" #include "readutmp.h" @@ -50,33 +49,13 @@ print_uptime (idx_t n, struct gl_utmp const *this) idx_t entries = 0; time_t boot_time = 0; time_t time_now; - time_t uptime = 0; + time_t uptime; intmax_t updays; int uphours; int upmins; struct tm *tmn; double avg[3]; int loads; -#ifdef HAVE_PROC_UPTIME - FILE *fp; - - fp = fopen ("/proc/uptime", "r"); - if (fp != nullptr) - { - char buf[BUFSIZ]; - char *b = fgets (buf, BUFSIZ, fp); - if (b == buf) - { - char *end_ptr; - double upsecs = c_strtod (buf, &end_ptr); - if (buf != end_ptr) - uptime = (0 <= upsecs && upsecs < TYPE_MAXIMUM (time_t) - ? upsecs : -1); - } - - fclose (fp); - } -#endif /* HAVE_PROC_UPTIME */ #if HAVE_SYSCTL && ! defined __GLIBC__ \ && defined CTL_KERN && defined KERN_BOOTTIME @@ -109,16 +88,13 @@ print_uptime (idx_t n, struct gl_utmp const *this) boot_time = this->ut_ts.tv_sec; ++this; } + /* The gnulib module 'readutmp' is supposed to provide a BOOT_TIME entry + on all platforms. */ + if (boot_time == 0) + error (EXIT_FAILURE, errno, _("couldn't get boot time")); time_now = time (nullptr); -#if defined HAVE_PROC_UPTIME - if (uptime == 0) -#endif - { - if (boot_time == 0) - error (EXIT_FAILURE, errno, _("couldn't get boot time")); - uptime = time_now - boot_time; - } + uptime = time_now - boot_time; updays = uptime / 86400; uphours = uptime % 86400 / 3600; upmins = uptime % 86400 % 3600 / 60; |
