Skip to content

Commit 108f06d

Browse files
committed
sqlite: Read time after uptime
We should read time after we have read uptime. The reason is that if we for example read time at sec.999, then second will have wrapped when we read uptime. While we might risk that the same happens with the new order of operation, it is easier to work with a larger timestamp than a large uptime. For example, with a larger timestamp, we risk having one second as offset to the original boot time. With a small timestamp, we risk having -1 second as offset and that is slightly harder to deal with. The boot time is meant as an estimation anyway, so 100% accurate value is not needed.
1 parent 0bda3f1 commit 108f06d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

metadata_writer_sqlite.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,16 @@ static int md_sqlite_read_boot_time(struct md_writer_sqlite *mws, uint64_t *boot
300300
{
301301
struct timeval tv;
302302
uint64_t uptime;
303-
gettimeofday(&tv, NULL);
304303

305304
//read uptime
306305
if (system_helpers_read_uint64_from_file("/proc/uptime", &uptime)) {
307306
return RETVAL_FAILURE;
308307
}
309308

309+
gettimeofday(&tv, NULL);
310+
310311
*boot_time = tv.tv_sec - uptime;
312+
META_PRINT_SYSLOG(mws->parent, LOG_INFO, "%" PRIu64 " %ld %" PRIu64 "\n", *boot_time, tv.tv_sec, uptime);
311313
return RETVAL_SUCCESS;
312314
}
313315

0 commit comments

Comments
 (0)