diff --git a/selfdrive/loggerd/SConscript b/selfdrive/loggerd/SConscript index b597406bac..1492d92f39 100644 --- a/selfdrive/loggerd/SConscript +++ b/selfdrive/loggerd/SConscript @@ -2,11 +2,11 @@ Import('env', 'arch', 'cereal', 'messaging', 'common', 'visionipc', 'gpucommon') logger_lib = env.Library('logger', ["logger.cc"]) -src = ['loggerd.cc'] libs = [logger_lib, 'zmq', 'capnp', 'kj', 'z', 'avformat', 'avcodec', 'swscale', 'avutil', 'yuv', 'bz2', 'OpenCL', common, cereal, messaging, visionipc] +src = ['loggerd.cc'] if arch in ["aarch64", "larch64"]: src += ['omx_encoder.cc'] libs += ['OmxCore', 'gsl', 'CB'] + gpucommon diff --git a/selfdrive/loggerd/logger.cc b/selfdrive/loggerd/logger.cc index 4ac496d2d3..a4e354263a 100644 --- a/selfdrive/loggerd/logger.cc +++ b/selfdrive/loggerd/logger.cc @@ -6,7 +6,6 @@ #include #include #include - #include #include @@ -18,14 +17,17 @@ #ifdef QCOM #include #endif -#include "messaging.hpp" #include "common/swaglog.h" #include "common/params.h" #include "common/util.h" #include "common/version.h" +#include "messaging.hpp" #include "logger.h" + +// ***** logging helpers ***** + void append_property(const char* key, const char* value, void *cookie) { std::vector > *properties = (std::vector > *)cookie; @@ -33,6 +35,24 @@ void append_property(const char* key, const char* value, void *cookie) { properties->push_back(std::make_pair(std::string(key), std::string(value))); } +static int mkpath(char* file_path) { + assert(file_path && *file_path); + char* p; + for (p=strchr(file_path+1, '/'); p; p=strchr(p+1, '/')) { + *p = '\0'; + if (mkdir(file_path, 0777)==-1) { + if (errno != EEXIST) { + *p = '/'; + return -1; + } + } + *p = '/'; + } + return 0; +} + +// ***** log metadata ***** + void log_init_data(LoggerState *s) { MessageBuilder msg; auto init = msg.initEvent().initInitData(); @@ -114,25 +134,11 @@ static void log_sentinel(LoggerState *s, cereal::Sentinel::SentinelType type) { logger_log(s, bytes.begin(), bytes.size(), true); } -static int mkpath(char* file_path) { - assert(file_path && *file_path); - char* p; - for (p=strchr(file_path+1, '/'); p; p=strchr(p+1, '/')) { - *p = '\0'; - if (mkdir(file_path, 0777)==-1) { - if (errno != EEXIST) { - *p = '/'; - return -1; - } - } - *p = '/'; - } - return 0; -} +// ***** logging functions ***** void logger_init(LoggerState *s, const char* log_name, bool has_qlog) { memset(s, 0, sizeof(*s)); - + umask(0); pthread_mutex_init(&s->lock, NULL); @@ -191,11 +197,11 @@ static LoggerHandle* logger_open(LoggerState *s, const char* root_path) { h->bz_qlog = BZ2_bzWriteOpen(&bzerror, h->qlog_file, 9, 0, 30); if (bzerror != BZ_OK) goto fail; } - + pthread_mutex_init(&h->lock, NULL); h->refcnt++; - log_init_data(s); return h; + fail: LOGE("logger failed to open files"); if (h->bz_file) { @@ -246,6 +252,8 @@ int logger_next(LoggerState *s, const char* root_path, pthread_mutex_unlock(&s->lock); + // write beggining of log metadata + log_init_data(s); log_sentinel(s, is_start_of_route ? cereal::Sentinel::SentinelType::START_OF_ROUTE : cereal::Sentinel::SentinelType::START_OF_SEGMENT); return 0; } diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index c8348e3e2a..f595b0f547 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -10,7 +10,6 @@ #include #include - #include #include #include @@ -18,6 +17,7 @@ #include #include + #include "common/timing.h" #include "common/params.h" #include "common/swaglog.h" @@ -101,14 +101,6 @@ namespace { constexpr int SEGMENT_LENGTH = 60; -double randrange(double a, double b) __attribute__((unused)); -double randrange(double a, double b) { - static std::mt19937 gen(millis_since_boot()); - - std::uniform_real_distribution<> dist(a, b); - return dist(gen); -} - ExitHandler do_exit; class RotateState { diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 80d7c388a9..fc058705a3 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -146,7 +146,6 @@ import cereal.messaging as messaging from common.params import Params from selfdrive.registration import register -from selfdrive.loggerd.config import ROOT from selfdrive.launcher import launcher @@ -421,12 +420,6 @@ def manager_init(): crash.bind_user(id=dongle_id) crash.bind_extra(version=version, dirty=dirty, is_eon=True) - os.umask(0) - try: - os.mkdir(ROOT, 0o777) - except OSError: - pass - # ensure shared libraries are readable by apks if EON: os.chmod(BASEDIR, 0o755)