From e24d28fd4512d8fd41a4a9ba610b1d450a3734a0 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 8 May 2023 19:21:22 -0700 Subject: [PATCH] loggerd: log HW-specific extras (#28084) * loggerd: log HW-specific extras * fix value --------- Co-authored-by: Comma Device --- system/hardware/base.h | 4 ++++ system/hardware/tici/hardware.h | 7 +++++++ system/loggerd/logger.cc | 12 +++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/system/hardware/base.h b/system/hardware/base.h index 6cfc1d874..546009972 100644 --- a/system/hardware/base.h +++ b/system/hardware/base.h @@ -18,6 +18,10 @@ public: static std::string get_serial() { return "cccccc"; } + static std::map get_init_logs() { + return {}; + } + static void reboot() {} static void poweroff() {} static void set_brightness(int percent) {} diff --git a/system/hardware/tici/hardware.h b/system/hardware/tici/hardware.h index 765b53ba6..ca67ee9a8 100644 --- a/system/hardware/tici/hardware.h +++ b/system/hardware/tici/hardware.h @@ -73,6 +73,13 @@ public: std::system(("pactl set-sink-volume @DEFAULT_SINK@ " + std::string(volume_str)).c_str()); } + + static std::map get_init_logs() { + return { + {"/BUILD", util::read_file("/BUILD")}, + }; + } + static bool get_ssh_enabled() { return Params().getBool("SshEnabled"); }; static void set_ssh_enabled(bool enabled) { Params().putBool("SshEnabled", enabled); }; }; diff --git a/system/loggerd/logger.cc b/system/loggerd/logger.cc index 0599aa1e5..a3152aa88 100644 --- a/system/loggerd/logger.cc +++ b/system/loggerd/logger.cc @@ -70,7 +70,9 @@ kj::Array logger_build_init_data() { "df -h", // usage for all filesystems }; - auto commands = init.initCommands().initEntries(log_commands.size()); + auto hw_logs = Hardware::get_init_logs(); + + auto commands = init.initCommands().initEntries(log_commands.size() + hw_logs.size()); for (int i = 0; i < log_commands.size(); i++) { auto lentry = commands[i]; @@ -80,6 +82,14 @@ kj::Array logger_build_init_data() { lentry.setValue(capnp::Data::Reader((const kj::byte*)result.data(), result.size())); } + int i = log_commands.size(); + for (auto [key, value] : hw_logs) { + auto lentry = commands[i]; + lentry.setKey(key); + lentry.setValue(capnp::Data::Reader((const kj::byte*)value.data(), value.size())); + i++; + } + return capnp::messageToFlatArray(msg); }