-const char errlog_rcs[] = "$Id: errlog.c,v 1.53 2007/08/05 13:53:14 fabiankeil Exp $";
+const char errlog_rcs[] = "$Id: errlog.c,v 1.54 2007/09/22 16:15:34 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
*
* Revisions :
* $Log: errlog.c,v $
+ * Revision 1.54 2007/09/22 16:15:34 fabiankeil
+ * - Let it compile with pcc.
+ * - Move our includes below system includes to prevent macro conflicts.
+ *
* Revision 1.53 2007/08/05 13:53:14 fabiankeil
* #1763173 from Stefan Huehner: declare some more functions
* static and use void instead of empty parameter lists.
TermLogWindow();
#else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
- fputs(error_message, stderr);
+ fputs(error_message, logfp);
#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
#if defined(unix)
- if(pidfile)
+ if (pidfile)
{
unlink(pidfile);
}
}
+/*********************************************************************
+ *
+ * Function : show_version
+ *
+ * Description : Logs the Privoxy version and the program name.
+ *
+ * Parameters :
+ * 1 : prog_name = The program name.
+ *
+ * Returns : Nothing.
+ *
+ *********************************************************************/
+static void show_version(const char *prog_name)
+{
+ log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
+ if (prog_name != NULL)
+ {
+ log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
+ }
+}
+
+
+/*********************************************************************
+ *
+ * Function : init_log_module
+ *
+ * Description : Initializes the logging module to log to stderr.
+ * Can only be called while stderr hasn't been closed
+ * yet and is only supposed to be called once.
+ *
+ * Parameters :
+ * 1 : prog_name = The program name.
+ *
+ * Returns : Nothing.
+ *
+ *********************************************************************/
+void init_log_module(const char *prog_name)
+{
+ lock_logfile();
+ logfp = stderr;
+ unlock_logfile();
+ set_debug_level(debug);
+ show_version(prog_name);
+}
+
+
+/*********************************************************************
+ *
+ * Function : set_debug_level
+ *
+ * Description : Sets the debug level to the provided value
+ * plus LOG_LEVEL_MINIMUM.
+ *
+ * XXX: we should only use the LOG_LEVEL_MINIMUM
+ * until the frist time the configuration file has
+ * been parsed.
+ *
+ * Parameters : 1: debug_level = The debug level to set.
+ *
+ * Returns : Nothing.
+ *
+ *********************************************************************/
+void set_debug_level(int debug_level)
+{
+ debug = debug_level | LOG_LEVEL_MINIMUM;
+}
+
+
+/*********************************************************************
+ *
+ * Function : disable_logging
+ *
+ * Description : Disables logging.
+ *
+ * Parameters : None.
+ *
+ * Returns : Nothing.
+ *
+ *********************************************************************/
+void disable_logging(void)
+{
+ lock_logfile();
+ if (logfp != NULL)
+ {
+ fclose(logfp);
+ }
+ logfp = NULL;
+ unlock_logfile();
+}
+
+
/*********************************************************************
*
* Function : init_error_log
*
- * Description : Initializes the logging module. Must call before
- * calling log_error.
+ * Description : Initializes the logging module to log to a file.
+ *
+ * XXX: should be renamed.
*
* Parameters :
* 1 : prog_name = The program name.
* Returns : N/A
*
*********************************************************************/
-void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
+void init_error_log(const char *prog_name, const char *logfname)
{
FILE *fp;
- lock_loginit();
+ assert(NULL != logfname);
- /* set the logging detail level */
- debug = debuglevel | LOG_LEVEL_MINIMUM;
+ lock_loginit();
+ lock_logfile();
if ((logfp != NULL) && (logfp != stderr))
{
- log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
- lock_logfile();
- fclose(logfp);
- } else {
- lock_logfile();
+ log_error(LOG_LEVEL_INFO, "(Re-)Open logfile \'%s\'", logfname ? logfname : "none");
}
- logfp = stderr;
- unlock_logfile();
/* set the designated log file */
- if( logfname )
+ fp = fopen(logfname, "a");
+ if (NULL == fp)
{
- if( NULL == (fp = fopen(logfname, "a")) )
- {
- log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
- }
-
- /* set logging to be completely unbuffered */
- setbuf(fp, NULL);
-
- lock_logfile();
- logfp = fp;
- unlock_logfile();
+ log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: \'%s\'", logfname);
}
- log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
- if (prog_name != NULL)
+ /* set logging to be completely unbuffered */
+ setbuf(fp, NULL);
+
+ if (logfp != NULL)
{
- log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
+ fclose(logfp);
}
+ logfp = fp;
+ unlock_logfile();
+
+ show_version(prog_name);
unlock_loginit();
} /* init_error_log */
+
#if defined(USE_NEW_LOG_ERROR)
/*
* Use an alternative log_error version and its helper functions.
}
#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
- /* verify if loglevel applies to current settings and bail out if negative */
- if ((loglevel & debug) == 0)
+ /*
+ * verify that the loglevel applies to current
+ * settings and that logging is enabled.
+ * Bail out otherwise.
+ */
+ if ((0 == (loglevel & debug)) || (logfp == NULL))
{
return;
}
snprintf(tempbuf, sizeof(tempbuf),
"%s Privoxy(%08lx) Fatal error: log_error() failed to allocate buffer memory.\n"
"\nExiting.", timestamp, thread_id);
- if( !logfp )
- {
- logfp = stderr;
- }
+ assert(NULL != logfp);
fputs(tempbuf, logfp);
unlock_logfile();
fatal_error(tempbuf); /* Exit */
loglevel = LOG_LEVEL_FATAL;
}
- /* deal with glibc stupidity - it won't let you initialize logfp */
- /* XXX: Still necessary? */
- if(NULL == logfp)
- {
- logfp = stderr;
- }
-
- fputs(outbuf_save, logfp);
+ assert(NULL != logfp);
if (loglevel == LOG_LEVEL_FATAL)
{
fatal_error(outbuf_save);
/* Never get here */
}
+ fputs(outbuf_save, logfp);
unlock_logfile();
#ifndef ERRLOG_H_INCLUDED
#define ERRLOG_H_INCLUDED
-#define ERRLOG_H_VERSION "$Id: errlog.h,v 1.17 2007/03/31 13:33:28 fabiankeil Exp $"
+#define ERRLOG_H_VERSION "$Id: errlog.h,v 1.18 2007/07/14 07:28:47 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.h,v $
*
* Revisions :
* $Log: errlog.h,v $
+ * Revision 1.18 2007/07/14 07:28:47 fabiankeil
+ * Add translation function for JB_ERR_FOO codes.
+ *
* Revision 1.17 2007/03/31 13:33:28 fabiankeil
* Add alternative log_error() with timestamps
* that contain milliseconds and without using
#define LOG_LEVEL_ERROR 0x2000
#define LOG_LEVEL_FATAL 0x4000 /* Exits after writing log */
-extern void init_error_log(const char *prog_name, const char *logfname, int debuglevel);
+extern void init_error_log(const char *prog_name, const char *logfname);
+extern void set_debug_level(int debuglevel);
+void disable_logging(void);
+void init_log_module(const char *prog_name);
extern void log_error(int loglevel, const char *fmt, ...);
extern const char *jb_err_to_string(int error);
-const char jcc_rcs[] = "$Id: jcc.c,v 1.151 2007/09/29 10:21:16 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.152 2007/10/04 18:03:34 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.152 2007/10/04 18:03:34 fabiankeil
+ * - Fix a crash when parsing invalid requests whose first header
+ * is rejected by get_header(). Regression (re?)introduced
+ * in r1.143 by yours truly.
+ * - Move ACTION_VANILLA_WAFER handling into parsers.c's
+ * client_cookie_adder() to make sure send-vanilla-wafer can be
+ * controlled through tags (and thus regression-tested).
+ *
* Revision 1.151 2007/09/29 10:21:16 fabiankeil
* - Move get_filter_function() from jcc.c to filters.c
* so the filter functions can be static.
#endif
;
+ init_log_module(Argv[0]);
+
/*
* Parse the command line arguments
*
close ( fd );
}
#endif /* 1 */
- /* FIXME: 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.
+ /*
+ * stderr (fd 2) will be closed later on, when the
+ * log file has been parsed.
*/
close( 0 );
*/
if (received_hup_signal)
{
- init_error_log(Argv[0], config->logfile, config->debug);
+ init_error_log(Argv[0], config->logfile);
received_hup_signal = 0;
}
#endif
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.65 2007/07/21 11:51:36 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.66 2007/08/05 14:02:09 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
*
* Revisions :
* $Log: loadcfg.c,v $
+ * Revision 1.66 2007/08/05 14:02:09 fabiankeil
+ * #1763173 from Stefan Huehner: declare unload_configfile() static.
+ *
* Revision 1.65 2007/07/21 11:51:36 fabiankeil
* As Hal noticed, checking dispatch_cgi() as the last cruncher
* looks like a bug if CGI requests are blocked unintentionally,
*
* Description : Load the config file and all parameters.
*
+ * XXX: more than thousand lines long
+ * and thus in serious need of refactoring.
+ *
* Parameters : None
*
* Returns : The configuration_spec, or NULL on error.
struct file_list *fs;
unsigned long linenum = 0;
int i;
+ char *logfile = NULL;
if ( !check_file_changed(current_configfile, configfile, &fs))
{
* In logdir by default
* *************************************************************************/
case hash_logfile :
- freez(config->logfile);
- config->logfile = no_daemon ? NULL : make_path(config->logdir, arg);
+ logfile = make_path(config->logdir, arg);
+ if (NULL == logfile)
+ {
+ log_error(LOG_LEVEL_FATAL, "Out of memore while creating logfile path");
+ }
continue;
/* *************************************************************************
fclose(configfp);
+ set_debug_level(config->debug);
+
+ freez(config->logfile);
+
+ if (!no_daemon)
+ {
+ if (NULL != logfile)
+ {
+ config->logfile = logfile;
+ log_error(LOG_LEVEL_INFO,
+ "Switching to daemon mode. Log messages will be written to: %s", config->logfile);
+ init_error_log(Argv[0], config->logfile);
+ }
+ else
+ {
+ log_error(LOG_LEVEL_INFO, "No logfile configured while in daemon mode. Logging disabled.");
+ disable_logging();
+ }
+ }
+
if (NULL == config->proxy_args)
{
log_error(LOG_LEVEL_FATAL, "Out of memory loading config - insufficient memory for config->proxy_args");
}
- init_error_log(Argv[0], config->logfile, config->debug);
-
if (config->actions_file[0])
{
add_loader(load_actions_file, config);