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>
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned long getbtime(void) {
static unsigned long btime = 0;
+ bool found_btime = false;
FILE *f;
if (btime)
}
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);
}