Put remote boot UUID in ServerStatistics and RemoteMessage
This makes it so we can see when a remote reboots easily, and gives us a
stepping stone to putting it in the log file header.
RemoteMessage then goes to the logger, so we are ready to teach the
logger how to detect and handle reboots.
Change-Id: I943de46094b60535c92a677b430d6828933b820d
diff --git a/aos/events/logging/uuid.cc b/aos/events/logging/uuid.cc
index 376fa95..3914740 100644
--- a/aos/events/logging/uuid.cc
+++ b/aos/events/logging/uuid.cc
@@ -1,9 +1,14 @@
#include "aos/events/logging/uuid.h"
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <array>
#include <random>
#include <string_view>
+#include "glog/logging.h"
+
namespace aos {
namespace {
char ToHex(int val) {
@@ -57,9 +62,24 @@
return result;
}
-UUID UUID::Zero() {
+UUID UUID::Zero() { return FromString("00000000-0000-0000-0000-000000000000"); }
+
+UUID UUID::FromString(std::string_view str) {
UUID result;
- result.data_.fill(0);
+ CHECK_EQ(str.size(), kSize);
+
+ std::copy(str.begin(), str.end(), result.data_.begin());
+ return result;
+}
+
+UUID UUID::BootUUID() {
+ int fd = open("/proc/sys/kernel/random/boot_id", O_RDONLY);
+ PCHECK(fd != -1);
+
+ UUID result;
+ CHECK_EQ(static_cast<ssize_t>(kSize), read(fd, result.data_.begin(), kSize));
+ close(fd);
+
return result;
}