diff --git a/cereal b/cereal index 12162ac4de..a6965af402 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 12162ac4dee9537611ee6d075e4b9b2873c6e741 +Subproject commit a6965af4020f21f6a1981fc2f68e075a086c32ad diff --git a/selfdrive/common/util.cc b/selfdrive/common/util.cc index 63e3f6fa00..f115b13dc7 100644 --- a/selfdrive/common/util.cc +++ b/selfdrive/common/util.cc @@ -209,6 +209,22 @@ std::string dir_name(std::string const &path) { return path.substr(0, pos); } +std::string check_output(const std::string& command) { + char buffer[128]; + std::string result; + std::unique_ptr pipe(popen(command.c_str(), "r"), pclose); + + if (!pipe) { + return ""; + } + + while (fgets(buffer, std::size(buffer), pipe.get()) != nullptr) { + result += std::string(buffer); + } + + return result; +} + struct tm get_time() { time_t rawtime; time(&rawtime); diff --git a/selfdrive/common/util.h b/selfdrive/common/util.h index c8e99faeaf..a47cce68ff 100644 --- a/selfdrive/common/util.h +++ b/selfdrive/common/util.h @@ -89,6 +89,8 @@ std::string readlink(const std::string& path); bool file_exists(const std::string& fn); bool create_directories(const std::string &dir, mode_t mode); +std::string check_output(const std::string& command); + inline void sleep_for(const int milliseconds) { std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); } diff --git a/selfdrive/loggerd/bootlog.cc b/selfdrive/loggerd/bootlog.cc index a5fbf78e2c..481b3ee47c 100644 --- a/selfdrive/loggerd/bootlog.cc +++ b/selfdrive/loggerd/bootlog.cc @@ -5,7 +5,14 @@ #include "selfdrive/common/swaglog.h" #include "selfdrive/loggerd/logger.h" + static kj::Array build_boot_log() { + std::vector bootlog_commands; + if (Hardware::TICI()) { + bootlog_commands.push_back("journalctl"); + bootlog_commands.push_back("sudo nvme smart-log --output-format=json /dev/nvme0"); + } + MessageBuilder msg; auto boot = msg.initEvent().initBoot(); @@ -30,6 +37,20 @@ static kj::Array build_boot_log() { } } + // Gather output of commands + i = 0; + auto commands = boot.initCommands().initEntries(bootlog_commands.size()); + for (auto &command : bootlog_commands) { + auto lentry = commands[i]; + + lentry.setKey(command); + + const std::string result = util::check_output(command); + lentry.setValue(capnp::Data::Reader((const kj::byte*)result.data(), result.size())); + + i++; + } + boot.setLaunchLog(util::read_file("/tmp/launch_log")); return capnp::messageToFlatArray(msg); }