From 7ccce99bf5bbd2aae2d22b9d8bf42c2cc0a89926 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: Mon, 7 Jun 2021 14:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8Dbroken=20pipe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.c b/server.c index 6e3345f..f1841cc 100644 --- a/server.c +++ b/server.c @@ -32,6 +32,7 @@ void error_die(const char *); void execute_cgi(int, const char *, const char *, const char *); off_t get_file_size(const char *); int get_line(int, char *, int); +void handle_quit(int); void headers(int, const char *); void not_found(int); void serve_file(int, const char *); @@ -333,6 +334,14 @@ int get_line(int sock, char *buf, int size) { return (i); } +/**********************************************************************/ +/* Handle thread quit signal +/**********************************************************************/ +void handle_quit(int signo) { + perror("handle"); + pthread_exit(NULL); +} + /**********************************************************************/ /* Return the informational HTTP headers about a file. */ /* Parameters: the socket to print the headers on @@ -504,6 +513,8 @@ void unimplemented(int client) { while (1) {\ client_sock = accept(server_sock, (struct sockaddr *)&client_name, &client_name_len);\ if (client_sock == -1) break;\ + signal(SIGQUIT, handle_quit);\ + signal(SIGPIPE, handle_quit);\ if (pthread_create(&newthread, NULL, accept_request, client_sock) != 0) perror("pthread_create");\ }\ close(client_sock);\