Clear loggerd locks once on boot (#23060)
* add test for clear_locks * move to bootlog * simplify testpull/23050/head^2
parent
296c4076a2
commit
a2f32fd3e1
|
@ -56,6 +56,7 @@ static kj::Array<capnp::word> build_boot_log() {
|
|||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
clear_locks(LOG_ROOT);
|
||||
|
||||
const std::string path = LOG_ROOT + "/boot/" + logger_get_route_name() + ".bz2";
|
||||
LOGW("bootlog to %s", path.c_str());
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <ftw.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
|
@ -266,3 +267,15 @@ void lh_close(LoggerHandle* h) {
|
|||
}
|
||||
pthread_mutex_unlock(&h->lock);
|
||||
}
|
||||
|
||||
int clear_locks_fn(const char* fpath, const struct stat *sb, int tyupeflag) {
|
||||
const char* dot = strrchr(fpath, '.');
|
||||
if (dot && strcmp(dot, ".lock") == 0) {
|
||||
unlink(fpath);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clear_locks(const std::string log_root) {
|
||||
ftw(log_root.c_str(), clear_locks_fn, 16);
|
||||
}
|
||||
|
|
|
@ -96,3 +96,4 @@ void logger_log(LoggerState *s, uint8_t* data, size_t data_size, bool in_qlog);
|
|||
|
||||
void lh_log(LoggerHandle* h, uint8_t* data, size_t data_size, bool in_qlog);
|
||||
void lh_close(LoggerHandle* h);
|
||||
void clear_locks(const std::string log_root);
|
||||
|
|
|
@ -149,18 +149,6 @@ void encoder_thread(LoggerdState *s, const LogCameraInfo &cam_info) {
|
|||
}
|
||||
}
|
||||
|
||||
int clear_locks_fn(const char* fpath, const struct stat *sb, int tyupeflag) {
|
||||
const char* dot = strrchr(fpath, '.');
|
||||
if (dot && strcmp(dot, ".lock") == 0) {
|
||||
unlink(fpath);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clear_locks() {
|
||||
ftw(LOG_ROOT.c_str(), clear_locks_fn, 16);
|
||||
}
|
||||
|
||||
void logger_rotate(LoggerdState *s) {
|
||||
{
|
||||
std::unique_lock lk(s->rotate_lock);
|
||||
|
@ -190,8 +178,6 @@ void rotate_if_needed(LoggerdState *s) {
|
|||
}
|
||||
|
||||
void loggerd_thread() {
|
||||
clear_locks();
|
||||
|
||||
// setup messaging
|
||||
typedef struct QlogState {
|
||||
int counter, freq;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <ftw.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atomic>
|
||||
|
|
|
@ -91,3 +91,21 @@ TEST_CASE("trigger_rotate") {
|
|||
REQUIRE(frame_id == start_frame_id + encoder_seg * (SEGMENT_LENGTH * MAIN_FPS));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("clear_locks") {
|
||||
std::vector<std::string> dirs;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
std::string &path = dirs.emplace_back(LOG_ROOT + "/" + std::to_string(i));
|
||||
REQUIRE(util::create_directories(path, 0775));
|
||||
std::ofstream{path + "/.lock"};
|
||||
REQUIRE(util::file_exists(path + "/.lock"));
|
||||
}
|
||||
|
||||
clear_locks(LOG_ROOT);
|
||||
|
||||
for (const auto &dir : dirs) {
|
||||
std::string lock_file = dir + "/.lock";
|
||||
REQUIRE(util::file_exists(lock_file) == false);
|
||||
rmdir(dir.c_str());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue