-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.85 2002/03/24 15:23:33 jongfoster Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
* the main connection-handling function.
*
* Copyright : Written by and Copyright (C) 2001 the SourceForge
- * IJBSWA team. http://ijbswa.sourceforge.net
+ * Privoxy team. http://ijbswa.sourceforge.net
*
* Based on the Internet Junkbuster originally written
* by and Copyright (C) 1997 Anonymous Coders and
*
* Revisions :
* $Log: jcc.c,v $
+ * 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
*
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);
*********************************************************************/
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);
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);
}
* on failure.
*
* Parameters :
- * 1 : config = Junkbuster configuration. Specifies port
+ * 1 : config = Privoxy configuration. Specifies port
* to bind to.
*
* Returns : Port that was opened.
{
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);
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)
}
#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));
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)))
{
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 */
}