]> granicus.if.org Git - procps-ng/commitdiff
library: tweak logic for /proc not mounted, <pids> api
authorJim Warner <james.warner@comcast.net>
Sun, 14 Feb 2021 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Thu, 18 Feb 2021 07:35:32 +0000 (18:35 +1100)
Since 'procps_uptime' will access the /proc filesystem
the <pids> 'new' guy should should protect against the
possibility /proc isn't mounted when 'boot_seconds' is
established. A zero is better than the negative value.

[ the only distortion would be to PIDS_TIME_ELAPSED. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/pids.c

index e99abdd1a4221d28f536146da4880a7fcde36331..b619b0e7d6e4df99b1a83e1e4e43761133c3d139 100644 (file)
@@ -1192,10 +1192,11 @@ PROCPS_EXPORT int procps_pids_new (
 
     pgsz = getpagesize();
     while (pgsz > 1024) { pgsz >>= 1; p->pgs2k_shift++; }
-
     p->hertz = procps_hertz_get();
-    procps_uptime(&uptime_secs, NULL);
-    p->boot_seconds = uptime_secs;
+
+    // in case 'fatal_proc_unmounted' wasn't called and /proc isn't mounted
+    if (0 >= procps_uptime(&uptime_secs, NULL))
+        p->boot_seconds = uptime_secs;
 
     numa_init();