From 59c2ebe5cdd30a53d7dd46688fc76f7245dcdeb9 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 12 Jan 2018 09:47:40 +0000 Subject: [PATCH] Add in the kernel boot time to the uploaded report --- src/fu-engine.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/fu-engine.c b/src/fu-engine.c index 8675a4393..3ded4fb85 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -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; }