From 44348ff234f32376078780995d6a9d8ea3ab9d0b 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: Thu, 27 Oct 2022 16:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=82=E5=B8=B8=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/server.c b/server.c index 3ac9b0c..368fa94 100644 --- a/server.c +++ b/server.c @@ -96,7 +96,6 @@ static void init_dict_pool(FILE *fp); static int insert_item(FILE *fp, const dict_t* dict, int keysize, int datasize); static inline uint32_t last_nonnull(const char* p, uint32_t max_size); static int listen_socket(int fd); -static void process_defer(); static int send_all(thread_timer_t *timer); static int send_data(int accept_fd, int index, server_ack_t cmd, const char *data, size_t length); static int s1_get(thread_timer_t *timer); @@ -584,6 +583,7 @@ static int s5_md5(thread_timer_t *timer) { static void handle_quit(int signo) { uint32_t index = (uint32_t)(pthread_getspecific(pthread_key_index)); printf("Handle sigquit@%u\n", index); + fflush(stdout); signal(SIGQUIT, handle_quit); longjmp(jmp2convend[index], signo); } @@ -591,23 +591,27 @@ static void handle_quit(int signo) { static void handle_segv(int signo) { uint32_t index = (uint32_t)(pthread_getspecific(pthread_key_index)); printf("Handle sigsegv@%u\n", index); + fflush(stdout); signal(SIGSEGV, handle_segv); longjmp(jmp2convend[index], signo); } static void handle_kill(int signo) { puts("Handle sigkill/sigterm"); - process_defer(); + fflush(stdout); + exit(signo); } static void handle_int(int signo) { puts("Keyboard interrupted"); - process_defer(); + fflush(stdout); + exit(signo); } static void handle_pipe(int signo) { uint32_t index = (uint32_t)(pthread_getspecific(pthread_key_index)); printf("Pipe error@%u, break loop...\n", index); + fflush(stdout); signal(SIGPIPE, handle_pipe); longjmp(jmp2convend[index], signo); } @@ -701,15 +705,6 @@ static void cleanup_thread(thread_timer_t* timer) { puts("Finish cleaning"); } -static void process_defer() { - for(int i = 0; i < THREADCNT; i++) { - if(timers[i].thread) pthread_kill(timers[i].thread, SIGUSR1); // pthread_exit - if(timers[i].timerthread) pthread_kill(timers[i].timerthread, SIGUSR1); // pthread_exit - } - fflush(stdout); - pthread_exit(NULL); -} - static void handle_accept(void *p) { #ifdef DEBUG printf("accept ptr: %p\n", p); @@ -846,7 +841,6 @@ static void accept_client(int fd) { signal(SIGSEGV, handle_segv); signal(SIGPIPE, handle_pipe); signal(SIGTERM, handle_kill); - signal(SIGUSR1, (void (*)(int))pthread_exit); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); init_crypto();