summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/log.c14
-rw-r--r--src/main.c9
2 files changed, 19 insertions, 4 deletions
diff --git a/src/log.c b/src/log.c
index f5a0b44..c5368b8 100644
--- a/src/log.c
+++ b/src/log.c
@@ -70,7 +70,14 @@ static unsigned int logging_initialized = FALSE; /* boolean */
*/
int open_log_file (const char *log_file_name)
{
- log_file_fd = create_file_safely (log_file_name, FALSE);
+ if (log_file_name == NULL) {
+ if(config.godaemon == FALSE)
+ log_file_fd = fileno(stdout);
+ else
+ log_file_fd = -1;
+ } else {
+ log_file_fd = create_file_safely (log_file_name, FALSE);
+ }
return log_file_fd;
}
@@ -79,7 +86,7 @@ int open_log_file (const char *log_file_name)
*/
void close_log_file (void)
{
- if (log_file_fd < 0) {
+ if (log_file_fd < 0 || log_file_fd == fileno(stdout)) {
return;
}
@@ -108,6 +115,9 @@ void log_message (int level, const char *fmt, ...)
ssize_t ret;
+ if(!config.syslog && log_file_fd == -1)
+ return;
+
#ifdef NDEBUG
/*
* Figure out if we should write the message or not.
diff --git a/src/main.c b/src/main.c
index 50cacca..e52b4b2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -355,7 +355,7 @@ static void initialize_config_defaults (struct config_s *conf)
conf->errorpages = NULL;
conf->stathost = safestrdup (TINYPROXY_STATHOST);
conf->idletimeout = MAX_IDLE_TIME;
- conf->logf_name = safestrdup (LOCALSTATEDIR "/log/tinyproxy/tinyproxy.log");
+ conf->logf_name = NULL;
conf->pidpath = NULL;
}
@@ -415,8 +415,13 @@ main (int argc, char **argv)
anonymous_insert ("Content-Type");
}
- if (config.godaemon == TRUE)
+ if (config.godaemon == TRUE) {
+ if (!config.syslog && config.logf_name == NULL)
+ fprintf(stderr, "WARNING: logging deactivated "
+ "(can't log to stdout when daemonized)\n");
+
makedaemon ();
+ }
if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",