[or-cvs] remove another possible sigpipe cause
Roger Dingledine
arma at seul.org
Sat Nov 20 06:52:15 UTC 2004
Update of /home2/or/cvsroot/tor/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/tor/src/common
Modified Files:
log.c
Log Message:
remove another possible sigpipe cause
Index: log.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/log.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- log.c 15 Nov 2004 23:30:26 -0000 1.69
+++ log.c 20 Nov 2004 06:52:13 -0000 1.70
@@ -76,8 +76,11 @@
}
/** If lf refers to an actual file that we have just opened, and the file
- * contains no data, log an "opening new logfile" message at the top. **/
-static void log_tor_version(logfile_t *lf, int reset)
+ * contains no data, log an "opening new logfile" message at the top.
+ *
+ * Return -1 if the log is broken and needs to be deleted, else return 0.
+ */
+static int log_tor_version(logfile_t *lf, int reset)
{
char buf[256];
size_t n;
@@ -85,10 +88,10 @@
if (!lf->needs_close)
/* If it doesn't get closed, it isn't really a file. */
- return;
+ return 0;
if (lf->is_temporary)
/* If it's temporary, it isn't really a file. */
- return;
+ return 0;
#ifdef HAVE_FTELLO
is_new = (ftello(lf->file) == 0);
#else
@@ -97,11 +100,13 @@
if (reset && !is_new)
/* We are resetting, but we aren't at the start of the file; no
* need to log again. */
- return;
+ return 0;
n = _log_prefix(buf, sizeof(buf), LOG_NOTICE);
tor_snprintf(buf+n, sizeof(buf)-n,
"Tor %s opening %slog file.\n", VERSION, is_new?"new ":"");
- fputs(buf, lf->file);
+ if (fputs(buf, lf->file) == EOF)
+ return -1; /* failed */
+ return 0;
}
/** Helper: Format a log message into a fixed-sized buffer. (This is
@@ -272,6 +277,7 @@
tor_free(victim);
}
+/** DOCDOC */
static void close_log(logfile_t *victim)
{
if (victim->needs_close && victim->file) {
@@ -285,14 +291,16 @@
}
}
+/** DOCDOC */
static int reset_log(logfile_t *lf)
{
if (lf->needs_close) {
- if(fclose(lf->file)==EOF ||
+ if (fclose(lf->file)==EOF ||
!(lf->file = fopen(lf->filename, "a"))) {
return -1;
} else {
- log_tor_version(lf, 1);
+ if (log_tor_version(lf, 1) < 0)
+ return -1;
}
}
return 0;
@@ -371,7 +379,11 @@
if (!f) return -1;
add_stream_log(loglevelMin, loglevelMax, filename, f);
logfiles->needs_close = 1;
- log_tor_version(logfiles, 0);
+ if (log_tor_version(logfiles, 0) < 0) {
+ logfile_t *victim = logfiles;
+ logfiles = victim->next;
+ delete_log(victim);
+ }
return 0;
}
More information about the tor-commits
mailing list