|
|
|
@ -10,9 +10,7 @@ |
|
|
|
|
#include <sys/resource.h> |
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
|
|
#include <iostream> |
|
|
|
|
#include <fstream> |
|
|
|
|
#include <streambuf> |
|
|
|
|
|
|
|
|
|
#include <thread> |
|
|
|
|
#include <mutex> |
|
|
|
|
#include <condition_variable> |
|
|
|
@ -20,11 +18,6 @@ |
|
|
|
|
#include <random> |
|
|
|
|
|
|
|
|
|
#include <ftw.h> |
|
|
|
|
#ifdef QCOM |
|
|
|
|
#include <cutils/properties.h> |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#include "common/version.h" |
|
|
|
|
#include "common/timing.h" |
|
|
|
|
#include "common/params.h" |
|
|
|
|
#include "common/swaglog.h" |
|
|
|
@ -107,11 +100,6 @@ LogCameraInfo cameras_logged[LOG_CAMERA_ID_MAX] = { |
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
constexpr int SEGMENT_LENGTH = 60; |
|
|
|
|
#if defined(QCOM) || defined(QCOM2) |
|
|
|
|
std::string LOG_ROOT = "/data/media/0/realdata"; |
|
|
|
|
#else |
|
|
|
|
std::string LOG_ROOT = util::getenv_default("HOME", "/.comma/media/0/realdata", "/data/media/0/realdata"); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
double randrange(double a, double b) __attribute__((unused)); |
|
|
|
|
double randrange(double a, double b) { |
|
|
|
@ -123,11 +111,6 @@ double randrange(double a, double b) { |
|
|
|
|
|
|
|
|
|
ExitHandler do_exit; |
|
|
|
|
|
|
|
|
|
static bool file_exists(const std::string& fn) { |
|
|
|
|
std::ifstream f(fn); |
|
|
|
|
return f.good(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class RotateState { |
|
|
|
|
public: |
|
|
|
|
SubSocket* fpkt_sock; |
|
|
|
@ -328,82 +311,6 @@ void encoder_thread(int cam_idx) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void append_property(const char* key, const char* value, void *cookie) { |
|
|
|
|
std::vector<std::pair<std::string, std::string> > *properties = |
|
|
|
|
(std::vector<std::pair<std::string, std::string> > *)cookie; |
|
|
|
|
|
|
|
|
|
properties->push_back(std::make_pair(std::string(key), std::string(value))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
kj::Array<capnp::word> gen_init_data() { |
|
|
|
|
MessageBuilder msg; |
|
|
|
|
auto init = msg.initEvent().initInitData(); |
|
|
|
|
|
|
|
|
|
if (file_exists("/EON")) { |
|
|
|
|
init.setDeviceType(cereal::InitData::DeviceType::NEO); |
|
|
|
|
} else if (file_exists("/TICI")) { |
|
|
|
|
init.setDeviceType(cereal::InitData::DeviceType::TICI); |
|
|
|
|
} else { |
|
|
|
|
init.setDeviceType(cereal::InitData::DeviceType::PC); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init.setVersion(capnp::Text::Reader(COMMA_VERSION)); |
|
|
|
|
|
|
|
|
|
std::ifstream cmdline_stream("/proc/cmdline"); |
|
|
|
|
std::vector<std::string> kernel_args; |
|
|
|
|
std::string buf; |
|
|
|
|
while (cmdline_stream >> buf) { |
|
|
|
|
kernel_args.push_back(buf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto lkernel_args = init.initKernelArgs(kernel_args.size()); |
|
|
|
|
for (int i=0; i<kernel_args.size(); i++) { |
|
|
|
|
lkernel_args.set(i, kernel_args[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init.setKernelVersion(util::read_file("/proc/version")); |
|
|
|
|
|
|
|
|
|
#ifdef QCOM |
|
|
|
|
{ |
|
|
|
|
std::vector<std::pair<std::string, std::string> > properties; |
|
|
|
|
property_list(append_property, (void*)&properties); |
|
|
|
|
|
|
|
|
|
auto lentries = init.initAndroidProperties().initEntries(properties.size()); |
|
|
|
|
for (int i=0; i<properties.size(); i++) { |
|
|
|
|
auto lentry = lentries[i]; |
|
|
|
|
lentry.setKey(properties[i].first); |
|
|
|
|
lentry.setValue(properties[i].second); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
const char* dongle_id = getenv("DONGLE_ID"); |
|
|
|
|
if (dongle_id) { |
|
|
|
|
init.setDongleId(std::string(dongle_id)); |
|
|
|
|
} |
|
|
|
|
init.setDirty(!getenv("CLEAN")); |
|
|
|
|
|
|
|
|
|
// log params
|
|
|
|
|
Params params = Params(); |
|
|
|
|
init.setGitCommit(params.get("GitCommit")); |
|
|
|
|
init.setGitBranch(params.get("GitBranch")); |
|
|
|
|
init.setGitRemote(params.get("GitRemote")); |
|
|
|
|
init.setPassive(params.read_db_bool("Passive")); |
|
|
|
|
{ |
|
|
|
|
std::map<std::string, std::string> params_map; |
|
|
|
|
params.read_db_all(¶ms_map); |
|
|
|
|
auto lparams = init.initParams().initEntries(params_map.size()); |
|
|
|
|
int i = 0; |
|
|
|
|
for (auto& kv : params_map) { |
|
|
|
|
auto lentry = lparams[i]; |
|
|
|
|
lentry.setKey(kv.first); |
|
|
|
|
lentry.setValue(kv.second); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return capnp::messageToFlatArray(msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int clear_locks_fn(const char* fpath, const struct stat *sb, int tyupeflag) { |
|
|
|
|
const char* dot = strrchr(fpath, '.'); |
|
|
|
|
if (dot && strcmp(dot, ".lock") == 0) { |
|
|
|
@ -416,50 +323,10 @@ static void clear_locks() { |
|
|
|
|
ftw(LOG_ROOT.c_str(), clear_locks_fn, 16); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void bootlog() { |
|
|
|
|
int err; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
auto words = gen_init_data(); |
|
|
|
|
auto bytes = words.asBytes(); |
|
|
|
|
logger_init(&s.logger, "bootlog", bytes.begin(), bytes.size(), false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = logger_next(&s.logger, LOG_ROOT.c_str(), s.segment_path, sizeof(s.segment_path), &s.rotate_segment); |
|
|
|
|
assert(err == 0); |
|
|
|
|
LOGW("bootlog to %s", s.segment_path); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
MessageBuilder msg; |
|
|
|
|
auto boot = msg.initEvent().initBoot(); |
|
|
|
|
|
|
|
|
|
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 lastPmsg = util::read_file("/sys/fs/pstore/pmsg-ramoops-0"); |
|
|
|
|
boot.setLastPmsg(capnp::Data::Reader((const kj::byte*)lastPmsg.data(), lastPmsg.size())); |
|
|
|
|
|
|
|
|
|
std::string launchLog = util::read_file("/tmp/launch_log"); |
|
|
|
|
boot.setLaunchLog(capnp::Text::Reader(launchLog.data(), launchLog.size())); |
|
|
|
|
|
|
|
|
|
auto bytes = msg.toBytes(); |
|
|
|
|
logger_log(&s.logger, bytes.begin(), bytes.size(), false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
logger_close(&s.logger); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
|
|
|
|
|
setpriority(PRIO_PROCESS, 0, -12); |
|
|
|
|
|
|
|
|
|
if (argc > 1 && strcmp(argv[1], "--bootlog") == 0) { |
|
|
|
|
bootlog(); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int segment_length = SEGMENT_LENGTH; |
|
|
|
|
if (getenv("LOGGERD_TEST")) { |
|
|
|
|
segment_length = atoi(getenv("LOGGERD_SEGMENT_LENGTH")); |
|
|
|
@ -495,11 +362,7 @@ int main(int argc, char** argv) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// init logger
|
|
|
|
|
{ |
|
|
|
|
auto words = gen_init_data(); |
|
|
|
|
auto bytes = words.asBytes(); |
|
|
|
|
logger_init(&s.logger, "rlog", bytes.begin(), bytes.size(), true); |
|
|
|
|
} |
|
|
|
|
logger_init(&s.logger, "rlog", true); |
|
|
|
|
|
|
|
|
|
// init encoders
|
|
|
|
|
pthread_mutex_init(&s.rotate_lock, NULL); |
|
|
|
|