X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jcc.c;h=54f190efc84c2f9301ff8903be8c7f565eb41ca4;hp=bdb26a32c051fd835a293b08ab0ebfa018a5e651;hb=1a4c5d622b507f661a249e4fcbe8496db0ccbdf1;hpb=17ef7337d1a41e4733c1ec662c3b1191d0c76a8a diff --git a/jcc.c b/jcc.c index bdb26a32..54f190ef 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.81 2002/03/12 01:42:50 oes Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.90 2002/04/02 14:57:28 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -7,7 +7,7 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.81 2002/03/12 01:42:50 oes Exp $"; * the main connection-handling function. * * Copyright : Written by and Copyright (C) 2001 the SourceForge - * IJBSWA team. http://ijbswa.sourceforge.net + * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written * by and Copyright (C) 1997 Anonymous Coders and @@ -33,6 +33,37 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.81 2002/03/12 01:42:50 oes Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.90 2002/04/02 14:57:28 oes + * Made sending wafers independent of FEATURE_COOKIE_JAR + * + * Revision 1.89 2002/03/31 17:18:59 jongfoster + * Win32 only: Enabling STRICT to fix a VC++ compile warning. + * + * Revision 1.88 2002/03/27 14:32:43 david__schmidt + * More compiler warning message maintenance + * + * Revision 1.87 2002/03/26 22:29:54 swa + * we have a new homepage! + * + * Revision 1.86 2002/03/25 17:04:55 david__schmidt + * Workaround for closing the jarfile before load_config() comes around again + * + * Revision 1.85 2002/03/24 15:23:33 jongfoster + * Name changes + * + * Revision 1.84 2002/03/24 13:25:43 swa + * name change related issues + * + * Revision 1.83 2002/03/16 23:54:06 jongfoster + * Adding graceful termination feature, to help look for memory leaks. + * If you enable this (which, by design, has to be done by hand + * editing config.h) and then go to http://i.j.b/die, then the program + * will exit cleanly after the *next* request. It should free all the + * memory that was used. + * + * Revision 1.82 2002/03/13 00:27:05 jongfoster + * Killing warnings + * * Revision 1.81 2002/03/12 01:42:50 oes * Introduced modular filters * @@ -505,6 +536,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.81 2002/03/12 01:42:50 oes Exp $"; #ifdef _WIN32 # ifndef FEATURE_PTHREAD +# ifndef STRICT +# define STRICT +# endif # include # include # endif /* ndef FEATURE_PTHREAD */ @@ -583,6 +617,9 @@ int urls_read = 0; /* total nr of urls read inc rejected */ int urls_rejected = 0; /* total nr of urls rejected */ #endif /* def FEATURE_STATISTICS */ +#ifdef FEATURE_GRACEFUL_TERMINATION +int g_terminate = 0; +#endif static void listen_loop(void); static void chat(struct client_state *csp); @@ -933,19 +970,15 @@ static void chat(struct client_state *csp) enlist(csp->headers, http->cmd); -#ifdef FEATURE_COOKIE_JAR /* - * If we're logging cookies in a cookie jar, and the user has not - * supplied any wafers, and the user has not told us to suppress the - * vanilla wafer, then send the vanilla wafer. + * If the user has not supplied any wafers, and the user has not + * told us to suppress the vanilla wafer, then send the vanilla wafer. */ - if ((csp->config->jarfile != NULL) - && list_is_empty(csp->action->multi[ACTION_MULTI_WAFER]) + if (list_is_empty(csp->action->multi[ACTION_MULTI_WAFER]) && ((csp->action->flags & ACTION_VANILLA_WAFER) != 0)) { enlist(csp->action->multi[ACTION_MULTI_WAFER], VANILLA_WAFER); } -#endif /* def FEATURE_COOKIE_JAR */ #ifdef FEATURE_KILL_POPUPS @@ -1594,7 +1627,7 @@ static int32 server_thread(void *data) *********************************************************************/ void usage(const char *myname) { - printf("JunkBuster proxy version " VERSION " (" HOME_PAGE_URL ")\n" + printf("Privoxy version " VERSION " (" HOME_PAGE_URL ")\n" "Usage: %s [--help] [--version] [--no-daemon] [--pidfile pidfile] [--user user[.group]] [configfile]\n" "Aborting.\n", myname); @@ -1664,7 +1697,7 @@ int main(int argc, const char *argv[]) else if(strcmp(argv[argc_pos], "--version") == 0) { - printf("Junkbuster version " VERSION " (" HOME_PAGE_URL ")\n"); + printf("Privoxy version " VERSION " (" HOME_PAGE_URL ")\n"); exit(0); } @@ -1889,7 +1922,7 @@ int main(int argc, const char *argv[]) * on failure. * * Parameters : - * 1 : config = Junkbuster configuration. Specifies port + * 1 : config = Privoxy configuration. Specifies port * to bind to. * * Returns : Port that was opened. @@ -1928,7 +1961,7 @@ static jb_socket bind_port_helper(struct configuration_spec * config) { case -3 : log_error(LOG_LEVEL_FATAL, "can't bind to %s:%d: " - "There may be another junkbuster or some other " + "There may be another Privoxy or some other " "proxy running on port %d", (NULL != config->haddr) ? config->haddr : "INADDR_ANY", config->hport, config->hport); @@ -1974,7 +2007,11 @@ static void listen_loop(void) bfd = bind_port_helper(config); +#ifdef FEATURE_GRACEFUL_TERMINATION + while (!g_terminate) +#else for (;;) +#endif { #if !defined(FEATURE_PTHREAD) && !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) while (waitpid(-1, NULL, WNOHANG) > 0) @@ -1999,6 +2036,23 @@ static void listen_loop(void) } #endif +#ifdef __OS2__ +#ifdef FEATURE_COOKIE_JAR + /* + * Need a workaround here: we have to fclose() the jarfile, or we die because it's + * already open. I think unload_configfile() is not being run, which should do + * this work. Until that can get resolved, we'll use this workaround. + */ + if (csp) + if(csp->config) + if (csp->config->jar) + { + fclose(csp->config->jar); + csp->config->jar = NULL; + } +#endif /* FEATURE_COOKIE_JAR */ +#endif /* __OS2__ */ + if ( NULL == (csp = (struct client_state *) zalloc(sizeof(*csp))) ) { log_error(LOG_LEVEL_FATAL, "malloc(%d) for csp failed: %E", sizeof(*csp)); @@ -2110,7 +2164,7 @@ static void listen_loop(void) #if defined(__OS2__) && !defined(SELECTED_ONE_OPTION) #define SELECTED_ONE_OPTION child_id = _beginthread( - serve, + (void(* _Optlink)(void*))serve, NULL, 64 * 1024, csp); @@ -2140,7 +2194,7 @@ static void listen_loop(void) NP_Entry, (ULONG)server_thread, NP_Output, Output(), NP_CloseOutput, FALSE, - NP_Name, (ULONG)"junkbuster child", + NP_Name, (ULONG)"privoxy child", NP_StackSize, 200*1024, TAG_DONE))) { @@ -2188,7 +2242,7 @@ static void listen_loop(void) log_error(LOG_LEVEL_ERROR, "can't fork: %E"); - sprintf(buf , "JunkBuster: can't fork: errno = %d", errno); + sprintf(buf , "Privoxy: can't fork: errno = %d", errno); write_socket(csp->cfd, buf, strlen(buf)); close_socket(csp->cfd); @@ -2202,7 +2256,48 @@ static void listen_loop(void) serve(csp); } } - /* NOTREACHED */ + + /* NOTREACHED unless FEATURE_GRACEFUL_TERMINATION is defined */ + + /* Clean up. Aim: free all memory (no leaks) */ +#ifdef FEATURE_GRACEFUL_TERMINATION + + log_error(LOG_LEVEL_ERROR, "Graceful termination requested"); + + unload_current_config_file(); + unload_current_actions_file(); + unload_current_re_filterfile(); +#ifdef FEATURE_TRUST + unload_current_trust_file(); +#endif + + if (config->multi_threaded) + { + int i = 60; + do + { + sleep(1); + sweep(); + } while ((clients->next != NULL) && (--i > 0)); + + if (i <= 0) + { + log_error(LOG_LEVEL_ERROR, "Graceful termination failed - still some live clients after 1 minute wait."); + } + } + sweep(); + sweep(); + +#if defined(unix) + free(basedir); +#endif +#if defined(_WIN32) && !defined(_WIN_CONSOLE) + /* Cleanup - remove taskbar icon etc. */ + TermLogWindow(); +#endif + + exit(0); +#endif /* FEATURE_GRACEFUL_TERMINATION */ }