Commit 056ce721 by xiongziliang

完整主进程

parent bc0a39bc
...@@ -275,23 +275,16 @@ static void sig_crash(int sig) { ...@@ -275,23 +275,16 @@ static void sig_crash(int sig) {
void System::startDaemon() { void System::startDaemon() {
signal(SIGTTOU,SIG_IGN); static pid_t pid;
signal(SIGTTIN,SIG_IGN);
signal(SIGHUP,SIG_IGN);
signal(SIGINT, [](int) {
InfoL << "SIGINT:exit";
signal(SIGINT,SIG_IGN);
throw ExitException();
});
do{ do{
auto pid = fork(); pid = fork();
if(pid == -1){ if(pid == -1){
WarnL << "fork失败:" << get_uv_errmsg(); WarnL << "fork失败:" << get_uv_errmsg();
//休眠1秒再试 //休眠1秒再试
sleep(1); sleep(1);
continue; continue;
} }
if(pid == 0){ if(pid == 0){
//子进程 //子进程
return; return;
...@@ -299,8 +292,13 @@ void System::startDaemon() { ...@@ -299,8 +292,13 @@ void System::startDaemon() {
//父进程,监视子进程是否退出 //父进程,监视子进程是否退出
DebugL << "启动子进程:" << pid; DebugL << "启动子进程:" << pid;
signal(SIGINT, [](int) {
WarnL << "收到主动退出信号,关闭父进程与子进程";
kill(pid,SIGINT);
exit(0);
});
do{ do{
try {
int status = 0; int status = 0;
if(waitpid(pid, &status, 0) >= 0) { if(waitpid(pid, &status, 0) >= 0) {
WarnL << "子进程退出"; WarnL << "子进程退出";
...@@ -309,13 +307,6 @@ void System::startDaemon() { ...@@ -309,13 +307,6 @@ void System::startDaemon() {
break; break;
} }
DebugL << "waitpid被中断:" << get_uv_errmsg(); DebugL << "waitpid被中断:" << get_uv_errmsg();
}catch (ExitException &ex){
WarnL << "收到主动退出信号,关闭父进程与子进程";
//通知子进程主动退出
kill(pid,SIGINT);
//父进程主动退出
exit(0);
}
}while (true); }while (true);
}while (true); }while (true);
} }
......
...@@ -160,6 +160,9 @@ extern void unInstallWebHook(); ...@@ -160,6 +160,9 @@ extern void unInstallWebHook();
static void inline listen_shell_input(){ static void inline listen_shell_input(){
cout << "> 欢迎进入命令模式,你可以输入\"help\"命令获取帮助" << endl; cout << "> 欢迎进入命令模式,你可以输入\"help\"命令获取帮助" << endl;
cout << "> " << std::flush; cout << "> " << std::flush;
signal(SIGTTOU,SIG_IGN);
signal(SIGTTIN,SIG_IGN);
SockUtil::setNoBlocked(STDIN_FILENO); SockUtil::setNoBlocked(STDIN_FILENO);
auto oninput = [](int event) { auto oninput = [](int event) {
if (event & Event_Read) { if (event & Event_Read) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论