完善日志系统,修复读取配置文件时的内存泄漏,初步添加熔断机制与指数退避机制
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
int in_log(logs *log,log_manager *self)
|
||||
{
|
||||
@ -81,15 +83,21 @@ int cleanup(log_manager *self)
|
||||
if(self->log ==NULL)
|
||||
return 1;
|
||||
logs *tobeclean,*loc;
|
||||
sem_wait(&self->log_sem);
|
||||
sem_wait(&self->log_sem);//获取信号量
|
||||
loc = self->log;
|
||||
self->log = NULL;
|
||||
self->count = 0;
|
||||
self->count = 0;//摘取log链
|
||||
sem_post(&self->log_sem);
|
||||
//释放信号量
|
||||
while(loc->next !=NULL)
|
||||
{
|
||||
tobeclean = loc;
|
||||
loc = loc->next;
|
||||
int fd = open("log.txt",O_CREAT | O_WRONLY | O_APPEND, 0777);
|
||||
if(fd == -1)
|
||||
perror("file:");
|
||||
write(fd,loc->log,strlen(loc->log));
|
||||
close(fd);
|
||||
free(tobeclean);
|
||||
}
|
||||
free(loc);
|
||||
|
||||
Reference in New Issue
Block a user