|  |  |  | @ -9,8 +9,6 @@ | 
			
		
	
		
			
				
					|  |  |  |  | #include <unistd.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <sys/stat.h> | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #include <pthread.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <bzlib.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <iostream> | 
			
		
	
		
			
				
					|  |  |  |  | #include <fstream> | 
			
		
	
		
			
				
					|  |  |  |  | #include <streambuf> | 
			
		
	
	
		
			
				
					|  |  |  | @ -20,7 +18,6 @@ | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #include "common/swaglog.h" | 
			
		
	
		
			
				
					|  |  |  |  | #include "common/params.h" | 
			
		
	
		
			
				
					|  |  |  |  | #include "common/util.h" | 
			
		
	
		
			
				
					|  |  |  |  | #include "common/version.h" | 
			
		
	
		
			
				
					|  |  |  |  | #include "messaging.hpp" | 
			
		
	
		
			
				
					|  |  |  |  | #include "logger.h" | 
			
		
	
	
		
			
				
					|  |  |  | @ -200,46 +197,14 @@ static LoggerHandle* logger_open(LoggerState *s, const char* root_path) { | 
			
		
	
		
			
				
					|  |  |  |  |   if (lock_file == NULL) return NULL; | 
			
		
	
		
			
				
					|  |  |  |  |   fclose(lock_file); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   h->log_file = fopen(h->log_path, "wb"); | 
			
		
	
		
			
				
					|  |  |  |  |   if (h->log_file == NULL) goto fail; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   if (s->has_qlog) { | 
			
		
	
		
			
				
					|  |  |  |  |     h->qlog_file = fopen(h->qlog_path, "wb"); | 
			
		
	
		
			
				
					|  |  |  |  |     if (h->qlog_file == NULL) goto fail; | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   int bzerror; | 
			
		
	
		
			
				
					|  |  |  |  |   h->bz_file = BZ2_bzWriteOpen(&bzerror, h->log_file, 9, 0, 30); | 
			
		
	
		
			
				
					|  |  |  |  |   if (bzerror != BZ_OK) goto fail; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   h->log = std::make_unique<BZFile>(h->log_path); | 
			
		
	
		
			
				
					|  |  |  |  |   if (s->has_qlog) { | 
			
		
	
		
			
				
					|  |  |  |  |     h->bz_qlog = BZ2_bzWriteOpen(&bzerror, h->qlog_file, 9, 0, 30); | 
			
		
	
		
			
				
					|  |  |  |  |     if (bzerror != BZ_OK) goto fail; | 
			
		
	
		
			
				
					|  |  |  |  |     h->q_log = std::make_unique<BZFile>(h->qlog_path); | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   pthread_mutex_init(&h->lock, NULL); | 
			
		
	
		
			
				
					|  |  |  |  |   h->refcnt++; | 
			
		
	
		
			
				
					|  |  |  |  |   return h; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fail: | 
			
		
	
		
			
				
					|  |  |  |  |   LOGE("logger failed to open files"); | 
			
		
	
		
			
				
					|  |  |  |  |   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; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | int logger_next(LoggerState *s, const char* root_path, | 
			
		
	
	
		
			
				
					|  |  |  | @ -310,11 +275,9 @@ void logger_close(LoggerState *s) { | 
			
		
	
		
			
				
					|  |  |  |  | void lh_log(LoggerHandle* h, uint8_t* data, size_t data_size, bool in_qlog) { | 
			
		
	
		
			
				
					|  |  |  |  |   pthread_mutex_lock(&h->lock); | 
			
		
	
		
			
				
					|  |  |  |  |   assert(h->refcnt > 0); | 
			
		
	
		
			
				
					|  |  |  |  |   int bzerror; | 
			
		
	
		
			
				
					|  |  |  |  |   BZ2_bzWrite(&bzerror, h->bz_file, data, data_size); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   if (in_qlog && h->bz_qlog != NULL) { | 
			
		
	
		
			
				
					|  |  |  |  |     BZ2_bzWrite(&bzerror, h->bz_qlog, data, data_size); | 
			
		
	
		
			
				
					|  |  |  |  |   h->log->write(data, data_size); | 
			
		
	
		
			
				
					|  |  |  |  |   if (in_qlog && h->q_log) { | 
			
		
	
		
			
				
					|  |  |  |  |     h->q_log->write(data, data_size); | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  |   pthread_mutex_unlock(&h->lock); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | @ -324,22 +287,8 @@ void lh_close(LoggerHandle* h) { | 
			
		
	
		
			
				
					|  |  |  |  |   assert(h->refcnt > 0); | 
			
		
	
		
			
				
					|  |  |  |  |   h->refcnt--; | 
			
		
	
		
			
				
					|  |  |  |  |   if (h->refcnt == 0) { | 
			
		
	
		
			
				
					|  |  |  |  |     if (h->bz_file){ | 
			
		
	
		
			
				
					|  |  |  |  |       int bzerror; | 
			
		
	
		
			
				
					|  |  |  |  |       BZ2_bzWriteClose(&bzerror, h->bz_file, 0, NULL, NULL); | 
			
		
	
		
			
				
					|  |  |  |  |       h->bz_file = NULL; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     if (h->bz_qlog){ | 
			
		
	
		
			
				
					|  |  |  |  |       int bzerror; | 
			
		
	
		
			
				
					|  |  |  |  |       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; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     fclose(h->log_file); | 
			
		
	
		
			
				
					|  |  |  |  |     h->log_file = NULL; | 
			
		
	
		
			
				
					|  |  |  |  |     h->log.reset(nullptr); | 
			
		
	
		
			
				
					|  |  |  |  |     h->q_log.reset(nullptr); | 
			
		
	
		
			
				
					|  |  |  |  |     unlink(h->lock_path); | 
			
		
	
		
			
				
					|  |  |  |  |     pthread_mutex_unlock(&h->lock); | 
			
		
	
		
			
				
					|  |  |  |  |     pthread_mutex_destroy(&h->lock); | 
			
		
	
	
		
			
				
					|  |  |  | 
 |