优化退出流程,统一注册到on_exit(

This commit is contained in:
2025-09-29 16:07:11 +08:00
parent afe70e6d17
commit 8c52e4ba84
9 changed files with 163 additions and 41 deletions

View File

@ -239,6 +239,7 @@ int teml(Ctl *self,int fifo[2])
//创建线程用于定期清理日志
pthread_create(&self->logwathcher,NULL,self->logmanager->clear_log,self->logmanager);
command->statue = 0;
self->command = command;
do
{ //设置缓冲区,接收用户输入
write(STDOUT_FILENO,PROMPT,sizeof(PROMPT));
@ -252,11 +253,14 @@ int teml(Ctl *self,int fifo[2])
const char fexp[256] = {'\0'};
memcpy(&input,&fexp,MAX_BUF);
}while(command->statue == 0);
pthread_kill(self->logwathcher,SIGUSR1);
log_manager_stop(self->logmanager);
pthread_join(self->logwathcher,NULL);
//关闭log定期清理程序
close(fifo[0]);
close(fifo[1]);
free_history(self);
self->command = NULL;
free(command);
}

View File

@ -3,6 +3,7 @@
#include <pthread.h>
#include "tools/log/log.h"
#include "interpreter/interpreter.h"
#define MAX_BUF 256
#define HISTORY_BUF 256
@ -17,8 +18,11 @@ typedef struct Ctl
char *history[HISTORY_BUF];
pthread_t logwathcher;
log_manager *logmanager;
ctx *command;//解释器上下文
}Ctl;
Ctl *init_tem(log_manager *logmanager);
int free_history(Ctl *self);
#endif