Add in the kernel boot time to the uploaded report

This commit is contained in:
Richard Hughes 2018-01-12 09:47:40 +00:00
parent b0398b00cf
commit 59c2ebe5cd

View File

@ -1200,10 +1200,26 @@ fu_engine_get_item_by_wildcard (FuEngine *self, AsStore *store, GError **error)
return NULL;
}
static gchar *
fu_engine_get_boot_time (void)
{
g_autofree gchar *buf = NULL;
g_auto(GStrv) lines = NULL;
if (!g_file_get_contents ("/proc/stat", &buf, NULL, NULL))
return NULL;
lines = g_strsplit (buf, "\n", -1);
for (guint i = 0; lines[i] != NULL; i++) {
if (g_str_has_prefix (lines[i], "btime "))
return g_strdup (lines[i] + 6);
}
return NULL;
}
static GHashTable *
fu_engine_get_report_metadata (FuEngine *self)
{
GHashTable *hash;
gchar *btime;
struct utsname name_tmp = { 0 };
/* used by pretty much every plugin and are hard deps of fwupd */
@ -1234,6 +1250,11 @@ fu_engine_get_report_metadata (FuEngine *self)
g_strdup (name_tmp.release));
}
/* add the kernel boot time so we can detect a reboot */
btime = fu_engine_get_boot_time ();
if (btime != NULL)
g_hash_table_insert (hash, g_strdup ("BootTime"), btime);
return hash;
}