From 24a729dca811f63444fb6ea8ebb63bd728a653a5 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Thu, 9 Apr 2020 05:05:19 +0800 Subject: [PATCH] improve loggerd error handling (#1332) * call BZ2_bzWriteClose after fail * set closed file handles to NULL * move fclose after BZ2_bzWriteClose old-commit-hash: 434a2b06584652ef82b393fcbc2986b598736030 --- selfdrive/loggerd/logger.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/selfdrive/loggerd/logger.cc b/selfdrive/loggerd/logger.cc index 0bb6c1b74f..e0d0a73652 100644 --- a/selfdrive/loggerd/logger.cc +++ b/selfdrive/loggerd/logger.cc @@ -132,8 +132,22 @@ static LoggerHandle* logger_open(LoggerState *s, const char* root_path) { return h; fail: LOGE("logger failed to open files"); - if (h->qlog_file) fclose(h->qlog_file); - if (h->log_file) fclose(h->log_file); + if (h->bz_file) { + BZ2_bzWriteClose(&bzerror, h->bz_file, 0, NULL, NULL); + h->bz_file = NULL; + } + if (h->bz_qlog) { + BZ2_bzWriteClose(&bzerror, h->bz_qlog, 0, NULL, NULL); + h->bz_qlog = NULL; + } + if (h->qlog_file) { + fclose(h->qlog_file); + h->qlog_file = NULL; + } + if (h->log_file) { + fclose(h->log_file); + h->log_file = NULL; + } return NULL; } @@ -228,8 +242,12 @@ void lh_close(LoggerHandle* h) { BZ2_bzWriteClose(&bzerror, h->bz_qlog, 0, NULL, NULL); h->bz_qlog = NULL; } - if (h->qlog_file) fclose(h->qlog_file); + if (h->qlog_file) { + fclose(h->qlog_file); + h->qlog_file = NULL; + } fclose(h->log_file); + h->log_file = NULL; unlink(h->lock_path); pthread_mutex_unlock(&h->lock); pthread_mutex_destroy(&h->lock);