]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
uptime: Include VM sleep time in the "up" duration
authorBruno Haible <bruno@clisp.org>
Tue, 15 Aug 2023 19:01:13 +0000 (12:01 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 15 Aug 2023 21:01:58 +0000 (14:01 -0700)
* 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'.

bootstrap.conf
src/uptime.c

index 6ce27d5dd23a33f8a5effa6ee5d127ef92380d43..d758a9ff63c295297f773483f1b10a5b89ca9cc1 100644 (file)
@@ -285,7 +285,6 @@ gnulib_modules="
   unlocked-io
   unsetenv
   update-copyright
-  uptime
   useless-if-before-free
   userspec
   utimecmp
index 22a3bdb1998f14216709c3c10318d7232476a8e4..813d29430adbed7ceca40f863ad930948185a8e9 100644 (file)
@@ -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;