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