fix loggerd after bootlog split (#19840)

* fix loggerd after bootlog split

* logger handles that

* unused

Co-authored-by: Comma Device <device@comma.ai>
pull/19842/head
Adeeb Shihadeh 4 years ago committed by GitHub
parent 13ea3ccf6d
commit 2e64049ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      selfdrive/loggerd/SConscript
  2. 48
      selfdrive/loggerd/logger.cc
  3. 10
      selfdrive/loggerd/loggerd.cc
  4. 7
      selfdrive/manager.py

@ -2,11 +2,11 @@ Import('env', 'arch', 'cereal', 'messaging', 'common', 'visionipc', 'gpucommon')
logger_lib = env.Library('logger', ["logger.cc"]) logger_lib = env.Library('logger', ["logger.cc"])
src = ['loggerd.cc']
libs = [logger_lib, 'zmq', 'capnp', 'kj', 'z', libs = [logger_lib, 'zmq', 'capnp', 'kj', 'z',
'avformat', 'avcodec', 'swscale', 'avutil', 'avformat', 'avcodec', 'swscale', 'avutil',
'yuv', 'bz2', 'OpenCL', common, cereal, messaging, visionipc] 'yuv', 'bz2', 'OpenCL', common, cereal, messaging, visionipc]
src = ['loggerd.cc']
if arch in ["aarch64", "larch64"]: if arch in ["aarch64", "larch64"]:
src += ['omx_encoder.cc'] src += ['omx_encoder.cc']
libs += ['OmxCore', 'gsl', 'CB'] + gpucommon libs += ['OmxCore', 'gsl', 'CB'] + gpucommon

@ -6,7 +6,6 @@
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -18,14 +17,17 @@
#ifdef QCOM #ifdef QCOM
#include <cutils/properties.h> #include <cutils/properties.h>
#endif #endif
#include "messaging.hpp"
#include "common/swaglog.h" #include "common/swaglog.h"
#include "common/params.h" #include "common/params.h"
#include "common/util.h" #include "common/util.h"
#include "common/version.h" #include "common/version.h"
#include "messaging.hpp"
#include "logger.h" #include "logger.h"
// ***** logging helpers *****
void append_property(const char* key, const char* value, void *cookie) { 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> > *properties =
(std::vector<std::pair<std::string, std::string> > *)cookie; (std::vector<std::pair<std::string, std::string> > *)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))); 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) { void log_init_data(LoggerState *s) {
MessageBuilder msg; MessageBuilder msg;
auto init = msg.initEvent().initInitData(); 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); logger_log(s, bytes.begin(), bytes.size(), true);
} }
static int mkpath(char* file_path) { // ***** logging functions *****
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;
}
void logger_init(LoggerState *s, const char* log_name, bool has_qlog) { void logger_init(LoggerState *s, const char* log_name, bool has_qlog) {
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
umask(0); umask(0);
pthread_mutex_init(&s->lock, NULL); 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); h->bz_qlog = BZ2_bzWriteOpen(&bzerror, h->qlog_file, 9, 0, 30);
if (bzerror != BZ_OK) goto fail; if (bzerror != BZ_OK) goto fail;
} }
pthread_mutex_init(&h->lock, NULL); pthread_mutex_init(&h->lock, NULL);
h->refcnt++; h->refcnt++;
log_init_data(s);
return h; return h;
fail: fail:
LOGE("logger failed to open files"); LOGE("logger failed to open files");
if (h->bz_file) { if (h->bz_file) {
@ -246,6 +252,8 @@ int logger_next(LoggerState *s, const char* root_path,
pthread_mutex_unlock(&s->lock); 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); log_sentinel(s, is_start_of_route ? cereal::Sentinel::SentinelType::START_OF_ROUTE : cereal::Sentinel::SentinelType::START_OF_SEGMENT);
return 0; return 0;
} }

@ -10,7 +10,6 @@
#include <sys/resource.h> #include <sys/resource.h>
#include <string> #include <string>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
@ -18,6 +17,7 @@
#include <random> #include <random>
#include <ftw.h> #include <ftw.h>
#include "common/timing.h" #include "common/timing.h"
#include "common/params.h" #include "common/params.h"
#include "common/swaglog.h" #include "common/swaglog.h"
@ -101,14 +101,6 @@ namespace {
constexpr int SEGMENT_LENGTH = 60; 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; ExitHandler do_exit;
class RotateState { class RotateState {

@ -146,7 +146,6 @@ import cereal.messaging as messaging
from common.params import Params from common.params import Params
from selfdrive.registration import register from selfdrive.registration import register
from selfdrive.loggerd.config import ROOT
from selfdrive.launcher import launcher from selfdrive.launcher import launcher
@ -421,12 +420,6 @@ def manager_init():
crash.bind_user(id=dongle_id) crash.bind_user(id=dongle_id)
crash.bind_extra(version=version, dirty=dirty, is_eon=True) 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 # ensure shared libraries are readable by apks
if EON: if EON:
os.chmod(BASEDIR, 0o755) os.chmod(BASEDIR, 0o755)

Loading…
Cancel
Save