diff options
author | Peter Palfrader <peter@palfrader.org> | 2003-11-19 02:09:43 +0000 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2003-11-19 02:09:43 +0000 |
commit | 9a676b04ddcebfdaab34f187a1a745f811e429d8 (patch) | |
tree | c9e91603c744ba1e88eda38b8d996a24ed17ac0a /src | |
parent | 3d145769de5805e4150e9683a855586fe9c59c9a (diff) | |
download | tor-9a676b04ddcebfdaab34f187a1a745f811e429d8.tar.gz tor-9a676b04ddcebfdaab34f187a1a745f811e429d8.zip |
Check that we can write to the logfile and log a warning to stderr if we can't
Move writing of pidfile after daemonizing, and also after setting the [ug]id:
This means that the tor user needs write priviliges to the pidfile location.
It needs it for unlinking the pidfile anyway.
svn:r846
Diffstat (limited to 'src')
-rw-r--r-- | src/common/log.c | 4 | ||||
-rw-r--r-- | src/or/main.c | 20 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/common/log.c b/src/common/log.c index 3a60d0576d..397d27aaf1 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -150,6 +150,10 @@ void add_stream_log(int loglevel, const char *name, FILE *stream) logfiles = lf; } +/* + * If opening the logfile fails, -1 is returned and + * errno is set appropriately (by fopen) + */ int add_file_log(int loglevel, const char *filename) { FILE *f; diff --git a/src/or/main.c b/src/or/main.c index ebab9eaa23..b362b0baf5 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -602,19 +602,19 @@ static int init_from_config(int argc, char **argv) { close_logs(); /* we'll close, then open with correct loglevel if necessary */ if(!options.LogFile && !options.RunAsDaemon) add_stream_log(options.loglevel, "<stdout>", stdout); - if(options.DebugLogFile) - add_file_log(LOG_DEBUG, options.DebugLogFile); if(options.LogFile) - add_file_log(options.loglevel, options.LogFile); + if (add_file_log(options.loglevel, options.LogFile) != 0) { + /* opening the log file failed! Use stderr and log a warning */ + add_stream_log(options.loglevel, "<stderr>", stderr); + log_fn(LOG_WARN, "Cannot write to LogFile '%s': %s.", options.LogFile, strerror(errno)); + } + if(options.DebugLogFile) + if (add_file_log(LOG_DEBUG, options.DebugLogFile) != 0) + log_fn(LOG_WARN, "Cannot write to DebugLogFile '%s': %s.", options.LogFile, strerror(errno)); global_read_bucket = options.TotalBandwidth; /* start it at 1 second of traffic */ stats_prev_global_read_bucket = global_read_bucket; - /* write our pid to the pid file */ - write_pidfile(options.PidFile); - /* XXX Is overwriting the pidfile ok? I think it is. -RD */ - - /* now that we've written the pid file, we can switch the user and group. */ if(options.User || options.Group) { if(switch_id(options.User, options.Group) != 0) { return -1; @@ -626,6 +626,10 @@ static int init_from_config(int argc, char **argv) { have_daemonized = 1; } + /* write our pid to the pid file, if we do not have write permissions we will log a warning */ + write_pidfile(options.PidFile); + /* XXX Is overwriting the pidfile ok? I think it is. -RD */ + return 0; } |