summaryrefslogtreecommitdiff
path: root/proc
diff options
context:
space:
mode:
authorMarkus Mayer <mmayer@broadcom.com>2013-05-08 16:34:44 -0700
committerCraig Small <csmall@enc.com.au>2013-05-12 07:17:07 +1000
commita6c79231067e6f12de2c4f363e263f69ef38888f (patch)
tree0c48f8513cc153774abe0127dc6ab7852368992d /proc
parent25201bc9fea611b22674f8a2460f4858281352bc (diff)
downloadprocps-ng-a6c79231067e6f12de2c4f363e263f69ef38888f.tar.gz
Fix btime handling reading from /proc/stat
Function getbtime() currently makes the assumption that btime==0 equals btime not being present in /proc/stat. This is not quite accurate, as timestamp 0 is, in fact, also a valid time (Epoch), and /proc/stat may report it as such. We introduce a flag to indicate whether btime was found in /proc/stat. In this way, btime==0 becomes a valid case, provided /proc/stat actually reports this as the boot time. procps can still detect the case of btime actually not being reported by the kernel. Signed-off-by: Markus Mayer <mmayer@broadcom.com>
Diffstat (limited to 'proc')
-rw-r--r--proc/sysinfo.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/proc/sysinfo.c b/proc/sysinfo.c
index 1f9b1fb..15cdb83 100644
--- a/proc/sysinfo.c
+++ b/proc/sysinfo.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -105,6 +106,7 @@ int uptime(double *restrict uptime_secs, double *restrict idle_secs) {
unsigned long getbtime(void) {
static unsigned long btime = 0;
+ bool found_btime = false;
FILE *f;
if (btime)
@@ -119,12 +121,14 @@ unsigned long getbtime(void) {
}
while ((fgets(buf, sizeof buf, f))) {
- if (sscanf(buf, "btime %lu", &btime) == 1)
+ if (sscanf(buf, "btime %lu", &btime) == 1) {
+ found_btime = true;
break;
+ }
}
fclose(f);
- if (!btime) {
+ if (!found_btime) {
fputs("missing btime in " STAT_FILE "\n", stderr);
exit(1);
}