Changeset 1924
- Timestamp:
- 09/01/08 12:06:36 (3 months ago)
- Files:
-
- cherokee/trunk/ChangeLog (modified) (1 diff)
- cherokee/trunk/cherokee/handler_cgi_base.c (modified) (3 diffs)
- cherokee/trunk/cherokee/main_worker.c (modified) (3 diffs)
- cherokee/trunk/cherokee/server-protected.h (modified) (1 diff)
- cherokee/trunk/cherokee/server.c (modified) (6 diffs)
- cherokee/trunk/cherokee/thread.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/ChangeLog
r1922 r1924 1 2008-09-01 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 3 * cherokee/main_worker.c, cherokee/handler_cgi_base.c, 4 cherokee/thread.c, cherokee/server-protected.h, cherokee/server.c: 5 Some signal management work. 6 1 7 2008-08-31 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 8 cherokee/trunk/cherokee/handler_cgi_base.c
r1910 r1924 533 533 534 534 /* SCRIPT_NAME: 535 * It is the request without the pathinfo if it exists 535 * RFC 3875: "URI path identifying the CGI script". 536 * 537 * For a CGI, it is the request without the PATHINFO, if any 538 * 539 * For a SCGI and FCGI, it is the request minus the pathinfo, 540 * which is request until the second slash character beginning 541 * at webdir length. 542 * 536 543 */ 537 544 cherokee_buffer_clean (&tmp); 538 545 539 546 if (! cgi_props->check_file) { 540 /* SCGI or FastCGI */541 542 if (conn->web_directory.len > 1) {543 cherokee_buffer_add_buffer (&tmp, &conn->web_directory);544 }545 547 /* SCGI or FastCGI 548 */ 549 cherokee_buffer_add (&tmp, 550 conn->request.buf, 551 conn->request.len - conn->pathinfo.len); 552 546 553 cgi->add_env_pair (cgi, "SCRIPT_NAME", 11, tmp.buf, tmp.len); 547 554 … … 588 595 cint_t local_len; 589 596 struct stat st; 597 cuint_t len = 0; 598 cuint_t slashes = 0; 590 599 cint_t pathinfo_len = 0; 591 600 cherokee_connection_t *conn = HANDLER_CONN(cgi); … … 615 624 616 625 /* No file checking: mainly for FastCGI and SCGI 626 * Examples: 627 * 628 * Webdir: /demo/subdirectory 629 * Request: http://localhost/demo/subdirectory/ 630 * SCRIPT_NAME': /demo/subdirectory/ 631 * PATH_INFO: <empty> 632 * 633 * Webdir: / 634 * Request http://localhost/another/large/one/foo 635 * SCRIPT_NAME: /another 636 * PATH_INFO: /large/one/foo 637 * 638 * Webdir: / 639 * Request: http://localhost/ 640 * SCRIPT_NAME: / 641 * PATH_INFO: <empty> 617 642 */ 618 643 if ((! props->check_file) && 619 (! cherokee_buffer_is_empty (&conn->web_directory)))644 (! cherokee_buffer_is_empty (&conn->web_directory))) 620 645 { 621 if (conn->request.len == 1) { 622 cherokee_buffer_add_str (&conn->pathinfo, "/"); 623 624 } else if (conn->web_directory.len == 1) { 625 cherokee_buffer_add_buffer (&conn->pathinfo, &conn->request); 626 627 } else { 628 cherokee_buffer_add (&conn->pathinfo, 629 conn->request.buf + conn->web_directory.len, 630 conn->request.len - conn->web_directory.len); 631 } 646 if (conn->web_directory.len > 1) { 647 len += conn->web_directory.len; 648 } 649 650 while (len < conn->request.len) { 651 if (conn->request.buf[len] == '/') { 652 if (slashes == 1) 653 break; 654 slashes = 1; 655 } 656 len ++; 657 } 658 659 cherokee_buffer_add (&conn->pathinfo, 660 conn->request.buf + len, 661 conn->request.len - len); 662 632 663 return ret_ok; 633 664 } cherokee/trunk/cherokee/main_worker.c
r1921 r1924 27 27 #include <signal.h> 28 28 #include <unistd.h> 29 #include <sys/types.h> 30 #include <sys/wait.h> 29 31 30 32 #include "init.h" … … 85 87 86 88 87 static void 88 panic_handler (int code) 89 { 90 UNUSED(code); 91 cherokee_server_handle_panic (srv); 92 } 93 94 static void 95 prepare_to_die (int code) 96 { 97 UNUSED(code); 98 cherokee_server_handle_TERM (srv); 99 } 100 101 static void 102 graceful_restart (int code) 103 { 104 /* Graceful restart sent by the 'guardian' 105 */ 106 UNUSED(code); 107 printf ("Handling HUP signal..\n"); 108 cherokee_server_handle_HUP (srv); 109 } 110 111 static void 112 reopen_log_files (int code) 113 { 114 UNUSED(code); 115 printf ("Reopeing log files..\n"); 116 cherokee_server_log_reopen (srv); 117 } 89 static void 90 signals_handler (int sig, siginfo_t *si, void *context) 91 { 92 int exitcode; 93 94 UNUSED(si); 95 UNUSED(context); 96 97 switch (sig) { 98 case SIGHUP: 99 printf ("Handling Graceful Restart..\n"); 100 cherokee_server_handle_HUP (srv); 101 break; 102 103 case SIGUSR2: 104 printf ("Reopening log files..\n"); 105 cherokee_server_log_reopen (srv); 106 break; 107 108 case SIGINT: 109 case SIGTERM: 110 printf ("Server is exiting..\n"); 111 cherokee_server_handle_TERM (srv); 112 break; 113 114 case SIGCHLD: 115 wait (&exitcode); 116 break; 117 118 case SIGSEGV: 119 #ifdef SIGBUS 120 case SIGBUS: 121 #endif 122 cherokee_server_handle_panic (srv); 123 break; 124 125 default: 126 PRINT_ERROR ("Unknown signal: %d\n", sig); 127 } 128 } 129 118 130 119 131 static ret_t … … 134 146 common_server_initialization (cherokee_server_t *srv) 135 147 { 136 ret_t ret; 137 138 #ifdef SIGPIPE 139 signal (SIGPIPE, SIG_IGN); 140 #endif 141 #ifdef SIGHUP 142 signal (SIGHUP, graceful_restart); 143 #endif 144 #ifdef SIGUSR2 145 signal (SIGUSR2, reopen_log_files); 146 #endif 147 #ifdef SIGSEGV 148 signal (SIGSEGV, panic_handler); 149 #endif 148 ret_t ret; 149 struct sigaction act; 150 151 /* Signals it handles 152 */ 153 memset(&act, 0, sizeof(act)); 154 155 /* SIGPIPE */ 156 act.sa_handler = SIG_IGN; 157 sigaction (SIGPIPE, &act, NULL); 158 159 /* Signal Handler */ 160 act.sa_sigaction = signals_handler; 161 sigaction (SIGHUP, &act, NULL); 162 sigaction (SIGUSR2, &act, NULL); 163 sigaction (SIGSEGV, &act, NULL); 164 sigaction (SIGTERM, &act, NULL); 165 sigaction (SIGINT, &act, NULL); 150 166 #ifdef SIGBUS 151 signal (SIGBUS, panic_handler); 152 #endif 153 #ifdef SIGTERM 154 signal (SIGTERM, prepare_to_die); 155 #endif 156 #ifdef SIGINT 157 signal (SIGINT, prepare_to_die); 167 sigaction (SIGBUS, &act, NULL); 158 168 #endif 159 169 cherokee/trunk/cherokee/server-protected.h
r1912 r1924 63 63 time_t start_time; 64 64 cherokee_buffer_t panic_action; 65 66 /* Restarts 67 */ 65 68 cherokee_boolean_t wanna_exit; 66 69 cherokee_boolean_t wanna_reinit; 67 70 68 71 /* Virtual servers 69 72 */ cherokee/trunk/cherokee/server.c
r1918 r1924 121 121 n->wanna_exit = false; 122 122 n->wanna_reinit = false; 123 123 124 124 /* Server config 125 125 */ … … 1074 1074 1075 1075 list_for_each (i, &srv->thread_list) { 1076 CHEROKEE_THREAD_JOIN (THREAD(i)->thread);1076 cherokee_thread_wait_end (THREAD(i)); 1077 1077 } 1078 1078 } … … 1102 1102 return ret_ok; 1103 1103 1104 /* Close all connections 1105 */ 1106 close_all_connections (srv); 1107 1108 /* Flush logs 1109 */ 1110 flush_logs (srv); 1111 1104 1112 /* Stop all the threads (may be slow) 1105 1113 */ 1106 1114 stop_threads (srv); 1107 1108 /* Close all connections1109 */1110 close_all_connections (srv);1111 1112 /* Flush logs1113 */1114 flush_logs (srv);1115 1115 1116 1116 return ret_ok; … … 1149 1149 cherokee_server_step (cherokee_server_t *srv) 1150 1150 { 1151 /* Wanna exit ? 1152 */ 1153 if (unlikely (srv->wanna_exit)) { 1154 return ret_eof; 1155 } 1156 1151 1157 /* Get the server time. 1152 1158 */ … … 1175 1181 #endif 1176 1182 1177 /* Wanna reinit ? 1178 */ 1179 if (unlikely (srv->wanna_reinit)) { 1180 cherokee_list_t *i; 1181 cherokee_boolean_t empty = true; 1183 /* Gracefull restart: 1184 * The main thread waits for the rest 1185 */ 1186 if (unlikely ((srv->wanna_reinit) && 1187 (srv->main_thread->conns_num == 0))) 1188 { 1189 cherokee_list_t *i; 1182 1190 1183 1191 list_for_each (i, &srv->thread_list) { 1184 if (THREAD(i)->conns_num != 0) { 1185 empty = false; 1186 break; 1187 } 1188 } 1189 1190 if (empty) 1191 empty = (srv->main_thread->conns_num == 0); 1192 1193 if (empty) 1194 return ret_eof; 1195 } 1196 1197 /* Wanna exit ? 1198 */ 1199 if (unlikely (srv->wanna_exit)) { 1192 cherokee_thread_wait_end (THREAD(i)); 1193 } 1200 1194 return ret_eof; 1201 1195 } … … 1713 1707 cherokee_server_handle_HUP (cherokee_server_t *srv) 1714 1708 { 1715 srv->wanna_reinit = true;1716 srv->keepalive = false;1717 srv->keepalive_max = 0;1709 srv->wanna_reinit = true; 1710 srv->keepalive = false; 1711 srv->keepalive_max = 0; 1718 1712 1719 1713 cherokee_socket_close (&srv->socket); cherokee/trunk/cherokee/thread.c
r1912 r1924 116 116 cherokee_thread_wait_end (cherokee_thread_t *thd) 117 117 { 118 #ifdef HAVE_PTHREAD119 118 /* Wait until the thread exits 120 119 */ 121 pthread_join (thd->thread, NULL); 122 #endif 120 CHEROKEE_THREAD_JOIN (thd->thread); 123 121 return ret_ok; 124 122 } … … 1467 1465 if (unlikely (thd->conns_num >= thd->conns_max)) 1468 1466 return 0; 1467 1468 if (unlikely ((THREAD_SRV(thd)->wanna_reinit) || 1469 (THREAD_SRV(thd)->wanna_exit))) 1470 return 0; 1469 1471 #if 0 1470 1472 if (unlikely (cherokee_fdpoll_is_full(thd->fdpoll))) { … … 1517 1519 } 1518 1520 #endif 1521 1522 /* Graceful restart 1523 */ 1524 if (srv->wanna_reinit) 1525 goto out; 1519 1526 1520 1527 /* If thread has pending connections, it should do a … … 1867 1874 } 1868 1875 #endif 1876 1877 /* Server wants to exit, and the thread has nothing to do 1878 */ 1879 if (unlikely (srv->wanna_exit)) { 1880 thd->exit = true; 1881 return ret_eof; 1882 } 1883 1884 if (unlikely (srv->wanna_reinit)) 1885 { 1886 if ((thd->active_list_num == 0) && 1887 (thd->polling_list_num == 0)) 1888 { 1889 thd->exit = true; 1890 return ret_eof; 1891 } 1892 1893 cherokee_fdpoll_watch (thd->fdpoll, fdwatch_msecs); 1894 goto out; 1895 } 1869 1896 1870 1897 /* If thread has pending connections, it should do a