mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 06:33:44 +01:00
Always log version when starting tor.
svn:r1990
This commit is contained in:
parent
899bd4f471
commit
653aaeef08
@ -70,10 +70,11 @@ static INLINE size_t _log_prefix(char *buf, size_t buf_len, int severity)
|
|||||||
|
|
||||||
/** If lf refers to an actual file that we have just opened, and the file
|
/** 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. **/
|
* contains no data, log an "opening new logfile" message at the top. **/
|
||||||
static void log_tor_version(logfile_t *lf)
|
static void log_tor_version(logfile_t *lf, int reset)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
size_t n;
|
size_t n;
|
||||||
|
int is_new;
|
||||||
|
|
||||||
if (!lf->needs_close)
|
if (!lf->needs_close)
|
||||||
/* If it doesn't get closed, it isn't really a file. */
|
/* If it doesn't get closed, it isn't really a file. */
|
||||||
@ -81,11 +82,14 @@ static void log_tor_version(logfile_t *lf)
|
|||||||
if (lf->is_temporary)
|
if (lf->is_temporary)
|
||||||
/* If it's temporary, it isn't really a file. */
|
/* If it's temporary, it isn't really a file. */
|
||||||
return;
|
return;
|
||||||
if (ftell(lf->file) != 0)
|
is_new = (ftell(lf->file) == 0);
|
||||||
/* We aren't at the start of the file; no need to log. */
|
if (reset && !is_new)
|
||||||
|
/* We are resetting, but we aren't at the start of the file; no
|
||||||
|
* need to log again. */
|
||||||
return;
|
return;
|
||||||
n = _log_prefix(buf, 250, LOG_NOTICE);
|
n = _log_prefix(buf, 250, LOG_NOTICE);
|
||||||
n += snprintf(buf+n, 250-n, "Tor %s creating new log file\n", VERSION);
|
n += snprintf(buf+n, 250-n, "Tor %s opening %slog file\n", VERSION,
|
||||||
|
is_new?"new ":"");
|
||||||
if (n>250)
|
if (n>250)
|
||||||
n = 250;
|
n = 250;
|
||||||
buf[n+1]='\0';
|
buf[n+1]='\0';
|
||||||
@ -190,7 +194,7 @@ void reset_logs()
|
|||||||
if (lf->needs_close) {
|
if (lf->needs_close) {
|
||||||
fclose(lf->file);
|
fclose(lf->file);
|
||||||
lf->file = fopen(lf->filename, "a");
|
lf->file = fopen(lf->filename, "a");
|
||||||
log_tor_version(lf);
|
log_tor_version(lf, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,7 +260,7 @@ int add_file_log(int loglevelMin, int loglevelMax, const char *filename)
|
|||||||
if (!f) return -1;
|
if (!f) return -1;
|
||||||
add_stream_log(loglevelMin, loglevelMax, filename, f);
|
add_stream_log(loglevelMin, loglevelMax, filename, f);
|
||||||
logfiles->needs_close = 1;
|
logfiles->needs_close = 1;
|
||||||
log_tor_version(logfiles);
|
log_tor_version(logfiles, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user