[or-cvs] Check that we can write to the logfile and log a warning to...
Peter Palfrader
weasel at seul.org
Wed Nov 19 02:09:45 UTC 2003
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv11285/src/or
Modified Files:
main.c
Log Message:
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.
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- main.c 18 Nov 2003 09:53:02 -0000 1.149
+++ main.c 19 Nov 2003 02:09:43 -0000 1.150
@@ -602,19 +602,19 @@
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;
@@ -625,6 +625,10 @@
daemonize();
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;
}
More information about the tor-commits
mailing list