X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jcc.c;h=cee160122429d362256c6c5ba7518ee82e4a04ab;hp=8db61952340ee20194013bc98742b6f6a9a46184;hb=f40a0abd128bc78c9ac705a8384e71818ae306b5;hpb=6942a9a1a7b7f51b13970a2f84df758b214dead5 diff --git a/jcc.c b/jcc.c index 8db61952..cee16012 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.55 2001/11/13 20:14:53 jongfoster Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.60 2001/12/30 14:07:32 steudten Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,27 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.55 2001/11/13 20:14:53 jongfoster Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.60 2001/12/30 14:07:32 steudten + * - Add signal handling (unix) + * - Add SIGHUP handler (unix) + * - Add creation of pidfile (unix) + * - Add action 'top' in rc file (RH) + * - Add entry 'SIGNALS' to manpage + * - Add exit message to logfile (unix) + * + * Revision 1.59 2001/12/13 14:07:18 oes + * Fixed Bug: 503 error page now sent OK + * + * Revision 1.58 2001/11/30 23:37:24 jongfoster + * Renaming the Win32 config file to config.txt - this is almost the + * same as the corresponding UNIX name "config" + * + * Revision 1.57 2001/11/16 00:47:43 jongfoster + * Changing the tty-disconnection code to use setsid(). + * + * Revision 1.56 2001/11/13 20:20:54 jongfoster + * Tabs->spaces, fixing a bug with missing {} around an if() + * * Revision 1.55 2001/11/13 20:14:53 jongfoster * Patch for FreeBSD setpgrp() as suggested by Alexander Lazic * @@ -444,6 +465,7 @@ int ldebug = 0; #include "actions.h" #include "cgi.h" #include "loadcfg.h" +#include "urlmatch.h" const char jcc_h_rcs[] = JCC_H_VERSION; const char project_h_rcs[] = PROJECT_H_VERSION; @@ -451,6 +473,8 @@ const char project_h_rcs[] = PROJECT_H_VERSION; struct client_state clients[1]; struct file_list files[1]; +short int MustReload = 0; + #ifdef FEATURE_STATISTICS int urls_read = 0; /* total nr of urls read inc rejected */ int urls_rejected = 0; /* total nr of urls rejected */ @@ -492,6 +516,44 @@ static const char VANILLA_WAFER[] = "(copyright_or_otherwise)_applying_to_any_cookie._"; +#if !defined(_WIN32) && !defined(__OS2__) +/********************************************************************* + * + * Function : SIG_handler + * + * Description : Signal handler for different signals. + * see man kill, signal .. + * + * Parameters : + * 1 : signal - the signal cause this function to call + * + * Returns : - + * + *********************************************************************/ +static void SIG_handler( int signal ) +{ + switch( signal ) + { + case SIGHUP: + MustReload = 1; + break; + case SIGTERM: + log_error(LOG_LEVEL_INFO, "exiting by signal %d .. bye", signal); + +#if defined(unix) + deletePidFile(); +#endif /* unix */ + + exit( signal ); + break; + + default: + /* want to exit jb so use FATAL */ + log_error(LOG_LEVEL_FATAL, "SIG_handler: receive signal %d without handler.", signal); + } + return; +} +#endif /********************************************************************* * * Function : chat @@ -861,6 +923,7 @@ static void chat(struct client_state *csp) csp->ip_addr_str, http->cmd); } + /* Write the answer to the client */ if(rsp) { @@ -901,7 +964,7 @@ static void chat(struct client_state *csp) if(rsp) { - if ((write_socket(csp->cfd, rsp->head, n) != n) + if ((write_socket(csp->cfd, rsp->head, rsp->head_length) != rsp->head_length) || (write_socket(csp->cfd, rsp->body, rsp->content_length) != rsp->content_length)) { log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host); @@ -1386,7 +1449,7 @@ int main(int argc, const char *argv[]) #elif !defined(_WIN32) "config" #else - "junkbstr.txt" + "config.txt" #endif ; @@ -1461,8 +1524,44 @@ int main(int argc, const char *argv[]) #if !defined(_WIN32) && !defined(__OS2__) - signal(SIGPIPE, SIG_IGN); - signal(SIGCHLD, SIG_IGN); +{ + int sig; + struct sigaction action; + + for ( sig = 1; sig < 16; sig++ ) + { + switch( sig ) + { + case 9: + case SIGPIPE: + case SIGCHLD: + case SIGHUP: + continue; + } + if ( signal(sig, SIG_handler) == SIG_ERR ) + log_error(LOG_LEVEL_FATAL, "Can't set signal-handler for signal %d: %E", sig); + } + /* SIG_IGN */ + if ( signal(SIGPIPE, SIG_IGN) == SIG_ERR ) + log_error(LOG_LEVEL_FATAL, "Can't set SIG_IGN to SIGPIPE: %E"); + if ( signal(SIGCHLD, SIG_IGN) == SIG_ERR ) + log_error(LOG_LEVEL_FATAL, "Can't set SIG_IGN to SIGCHLD: %E"); + /* log file reload */ + if (!sigaction(SIGHUP,NULL,&action)) + { + action.sa_handler = &SIG_handler; + action.sa_flags = SA_RESTART; + + if ( sigaction(SIGHUP,&action,NULL)) + log_error(LOG_LEVEL_FATAL, "Can't set signal-handler for signal SIGHUP: %E"); + } + else + { + perror("sigaction"); + log_error(LOG_LEVEL_FATAL, "Can't get sigaction data for signal SIGHUP"); + } + +} #else /* ifdef _WIN32 */ # ifdef _WIN_CONSOLE @@ -1481,7 +1580,9 @@ int main(int argc, const char *argv[]) #if defined(unix) { pid_t pid = 0; +#if 0 int fd; +#endif /* * we make us a real daemon @@ -1512,11 +1613,15 @@ int main(int argc, const char *argv[]) exit( 0 ); } /* child */ +#if 1 + /* Should be more portable, but not as well tested */ + setsid(); +#else /* !1 */ #ifdef __FreeBSD__ setpgrp(0,0); -#else +#else /* ndef __FreeBSD__ */ setpgrp(); -#endif +#endif /* ndef __FreeBSD__ */ fd = open("/dev/tty", O_RDONLY); if ( fd ) { @@ -1524,6 +1629,7 @@ int main(int argc, const char *argv[]) ioctl( fd, TIOCNOTTY,0 ); close ( fd ); } +#endif /* !1 */ /* should close stderr (fd 2) here too, but the test for existence ** and load config file is done in listen_loop() and puts ** some messages on stderr there. @@ -1540,6 +1646,7 @@ int main(int argc, const char *argv[]) #endif /* _DEBUG */ chdir("/"); + writePidFile(); } #endif /* defined unix */