store all files in /sys/fs/pstore in bootlog (#20875)
* store all files in /sys/fs/pstore in bootlog * whitespace * fix bootlog testalbatross
parent
2dc4d3584b
commit
4742f55749
2
cereal
2
cereal
|
@ -1 +1 @@
|
|||
Subproject commit bab2f2b95e38da4c968efc31369163056e938b30
|
||||
Subproject commit 48795401f2153ef0519e67f5f70231f587b5c971
|
|
@ -315,18 +315,7 @@ int Params::readAll(std::map<std::string, std::string> *params) {
|
|||
std::lock_guard<FileLock> lk(file_lock);
|
||||
|
||||
std::string key_path = params_path + "/d";
|
||||
DIR *d = opendir(key_path.c_str());
|
||||
if (!d) return -1;
|
||||
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(d))) {
|
||||
if (isalnum(de->d_name[0])) {
|
||||
(*params)[de->d_name] = util::read_file(key_path + "/" + de->d_name);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
return 0;
|
||||
return util::read_files_in_dir(key_path, params);
|
||||
}
|
||||
|
||||
void Params::clearAll(ParamKeyType key_type) {
|
||||
|
|
|
@ -72,6 +72,20 @@ std::string read_file(const std::string& fn) {
|
|||
return buffer.str();
|
||||
}
|
||||
|
||||
int read_files_in_dir(std::string path, std::map<std::string, std::string> *contents) {
|
||||
DIR *d = opendir(path.c_str());
|
||||
if (!d) return -1;
|
||||
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(d))) {
|
||||
if (isalnum(de->d_name[0])) {
|
||||
(*contents)[de->d_name] = util::read_file(path + "/" + de->d_name);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_file(const char* path, const void* data, size_t size, int flags, mode_t mode) {
|
||||
int fd = open(path, flags, mode);
|
||||
if (fd == -1) {
|
||||
|
@ -82,4 +96,5 @@ int write_file(const char* path, const void* data, size_t size, int flags, mode_
|
|||
return (n >= 0 && (size_t)n == size) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace util
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
|
@ -14,6 +15,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
|
||||
#ifndef sighandler_t
|
||||
typedef void (*sighandler_t)(int sig);
|
||||
|
@ -53,6 +55,8 @@ inline std::string string_format(const std::string& format, Args... args) {
|
|||
|
||||
std::string read_file(const std::string &fn);
|
||||
|
||||
int read_files_in_dir(std::string path, std::map<std::string, std::string> *contents);
|
||||
|
||||
int write_file(const char* path, const void* data, size_t size, int flags = O_WRONLY, mode_t mode = 0777);
|
||||
|
||||
inline std::string tohex(const uint8_t* buf, size_t buf_size) {
|
||||
|
|
|
@ -12,11 +12,18 @@ static kj::Array<capnp::word> build_boot_log() {
|
|||
|
||||
boot.setWallTimeNanos(nanos_since_epoch());
|
||||
|
||||
std::string lastKmsg = util::read_file("/sys/fs/pstore/console-ramoops");
|
||||
boot.setLastKmsg(capnp::Data::Reader((const kj::byte*)lastKmsg.data(), lastKmsg.size()));
|
||||
std::string pstore = "/sys/fs/pstore";
|
||||
std::map<std::string, std::string> pstore_map;
|
||||
util::read_files_in_dir(pstore, &pstore_map);
|
||||
|
||||
std::string lastPmsg = util::read_file("/sys/fs/pstore/pmsg-ramoops-0");
|
||||
boot.setLastPmsg(capnp::Data::Reader((const kj::byte*)lastPmsg.data(), lastPmsg.size()));
|
||||
auto lpstore = boot.initPstore().initEntries(pstore_map.size());
|
||||
int i = 0;
|
||||
for (auto& kv : pstore_map) {
|
||||
auto lentry = lpstore[i];
|
||||
lentry.setKey(kv.first);
|
||||
lentry.setValue(capnp::Data::Reader((const kj::byte*)kv.second.data(), kv.second.size()));
|
||||
i++;
|
||||
}
|
||||
|
||||
std::string launchLog = util::read_file("/tmp/launch_log");
|
||||
boot.setLaunchLog(capnp::Text::Reader(launchLog.data(), launchLog.size()));
|
||||
|
|
|
@ -153,12 +153,12 @@ class TestLoggerd(unittest.TestCase):
|
|||
assert abs(boot.wallTimeNanos - time.time_ns()) < 5*1e9 # within 5s
|
||||
assert boot.launchLog == launch_log
|
||||
|
||||
for field, path in [("lastKmsg", "console-ramoops"), ("lastPmsg", "pmsg-ramoops-0")]:
|
||||
path = Path(os.path.join("/sys/fs/pstore/", path))
|
||||
val = b""
|
||||
for fn in ["console-ramoops", "pmsg-ramoops-0"]:
|
||||
path = Path(os.path.join("/sys/fs/pstore/", fn))
|
||||
if path.is_file():
|
||||
val = open(path, "rb").read()
|
||||
self.assertEqual(getattr(boot, field), val)
|
||||
expected_val = open(path, "rb").read()
|
||||
bootlog_val = [e.value for e in boot.pstore.entries if e.key == fn][0]
|
||||
self.assertEqual(expected_val, bootlog_val)
|
||||
|
||||
def test_qlog(self):
|
||||
qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is not None]
|
||||
|
|
Loading…
Reference in New Issue