From 8c955bcbc07c5a2082f42c31ca957b306c4713a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 15 Oct 2022 01:01:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=A1=E5=8F=B7=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server.c b/server.c index e15e412..86f311f 100644 --- a/server.c +++ b/server.c @@ -68,6 +68,7 @@ static void cleanup_thread(thread_timer_t* timer); static server_ack_t del(FILE *fp, const char* key, int len, char ret[4]); static void handle_accept(void *accept_fd_p); static void handle_int(int signo); +static void handle_kill(int signo); static void handle_pipe(int signo); static void handle_quit(int signo); static void handle_segv(int signo); @@ -560,7 +561,12 @@ static void handle_quit(int signo) { } static void handle_segv(int signo) { - puts("Handle kill/segv/term"); + puts("Handle segv"); + pthread_exit(NULL); +} + +static void handle_kill(int signo) { + puts("Handle kill/term"); for(int i = 0; i < THREADCNT; i++) { if(timers[i].thread) pthread_kill(timers[i].thread, SIGQUIT); if(timers[i].timerthread) pthread_kill(timers[i].timerthread, SIGQUIT); @@ -652,7 +658,6 @@ static void handle_accept(void *p) { if (pthread_create(&thread, &attr, (void *)&accept_timer, p)) { perror("Error creating timer thread"); cleanup_thread(timer_pointer_of(p)); - pthread_rwlock_unlock(&timer_pointer_of(p)->mb); return; } timer_pointer_of(p)->timerthread = thread; @@ -787,10 +792,10 @@ static void accept_client(int fd) { }*/ signal(SIGINT, handle_int); signal(SIGQUIT, handle_quit); - signal(SIGKILL, handle_segv); + signal(SIGKILL, handle_kill); signal(SIGSEGV, handle_segv); signal(SIGPIPE, handle_pipe); - signal(SIGTERM, handle_segv); + signal(SIGTERM, handle_kill); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); init_crypto();