Commit e935d73b authored by Nick Mathewson's avatar Nick Mathewson 🏃
Browse files

r12852@catbus: nickm | 2007-05-22 11:00:27 -0400

 Use svn revisions consistently throughout all log messages.


svn:r10291
parent 4ec5e139
......@@ -88,6 +88,17 @@ int _log_global_min_severity = LOG_NOTICE;
static void delete_log(logfile_t *victim);
static void close_log(logfile_t *victim);
/** DOCDOC */
static char *appname = NULL;
/** DOCDOC */
void
log_set_application_name(const char *name)
{
tor_free(appname);
appname = name ? tor_strdup(name) : NULL;
}
/** Helper: Write the standard prefix for log lines to a
* <b>buf_len</b> character buffer in <b>buf</b>.
*/
......@@ -140,8 +151,13 @@ log_tor_version(logfile_t *lf, int reset)
* need to log again. */
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 ":"");
if (appname) {
tor_snprintf(buf+n, sizeof(buf)-n,
"%s opening %slog file.\n", appname, is_new?"new ":"");
} else {
tor_snprintf(buf+n, sizeof(buf)-n,
"Tor %s opening %slog file.\n", VERSION, is_new?"new ":"");
}
if (fputs(buf, lf->file) == EOF ||
fflush(lf->file) == EOF) /* error */
return -1; /* failed */
......
......@@ -113,6 +113,7 @@ void configure_libevent_logging(void);
void suppress_libevent_log_msg(const char *msg);
void change_callback_log_severity(int loglevelMin, int loglevelMax,
log_callback cb);
void log_set_application_name(const char *name);
/* Outputs a message to stdout */
void _log(int severity, uint32_t domain, const char *format, ...)
......
......@@ -697,6 +697,25 @@ set_options(or_options_t *new_val, char **msg)
return 0;
}
extern const char tor_svn_revision[]; /* from main.c */
/** Return the current Tor version, possibly */
const char *
get_version(void)
{
static char *version = NULL;
if (version == NULL) {
if (strlen(tor_svn_revision)) {
size_t len = strlen(VERSION)+strlen(tor_svn_revision)+8;
version = tor_malloc(len);
tor_snprintf(version, len, "%s (r%s)", VERSION, tor_svn_revision);
} else {
version = tor_strdup(VERSION);
}
}
return version;
}
/** Release all memory and resources held by global configuration structures.
*/
void
......@@ -3080,8 +3099,6 @@ check_nickname_list(const char *lst, const char *name, char **msg)
return r;
}
extern const char tor_svn_revision[]; /* from main.c */
/** Read a configuration file into <b>options</b>, finding the configuration
* file location based on the command line. After loading the options,
* validate them for consistency, then take actions based on them.
......@@ -3118,13 +3135,7 @@ options_init_from_torrc(int argc, char **argv)
}
if (argc > 1 && (!strcmp(argv[1],"--version"))) {
char vbuf[128];
if (strlen(tor_svn_revision)) {
tor_snprintf(vbuf, sizeof(vbuf), " (r%s)", tor_svn_revision);
} else {
vbuf[0] = 0;
}
printf("Tor version %s%s.\n",VERSION,vbuf);
printf("Tor version %s.\n",get_version());
if (argc > 2 && (!strcmp(argv[2],"--version"))) {
print_svn_version();
}
......@@ -4311,7 +4322,10 @@ or_state_save(time_t now)
global_state->LastWritten = time(NULL);
tor_free(global_state->TorVersion);
global_state->TorVersion = tor_strdup("Tor " VERSION);
len = strlen(get_version())+8;
global_state->TorVersion = tor_malloc(len);
tor_snprintf(global_state->TorVersion, len, "Tor %s", get_version());
state = config_dump(&state_format, global_state, 1, 0);
len = strlen(state)+256;
contents = tor_malloc(len);
......
......@@ -1184,7 +1184,7 @@ getinfo_helper_misc(control_connection_t *conn, const char *question,
{
(void) conn;
if (!strcmp(question, "version")) {
*answer = tor_strdup(VERSION);
*answer = tor_strdup(get_version());
} else if (!strcmp(question, "config-file")) {
*answer = tor_strdup(get_torrc_fname());
} else if (!strcmp(question, "info/names")) {
......@@ -2301,8 +2301,9 @@ connection_control_process_inbuf(control_connection_t *conn)
char buf[128];
set_uint16(buf+2, htons(0x0000)); /* type == error */
set_uint16(buf+4, htons(0x0001)); /* code == internal error */
strlcpy(buf+6, "The v0 control protocol no longer supported in "VERSION"; "
"use Tor 0.1.2.x or upgrade your controller", sizeof(buf)-6);
strlcpy(buf+6, "The v0 control protocol is not supported by Tor 0.2.0.x "
"and later; use Tor 0.1.2.x or upgrade your controller",
sizeof(buf)-6);
body_len = 2+strlen(buf+6)+2; /* code, msg, nul. */
set_uint16(buf+0, htons(body_len));
connection_write_to_buf(buf, 4+body_len, TO_CONN(conn));
......
......@@ -1684,11 +1684,15 @@ handle_signals(int is_parent)
static int
tor_init(int argc, char *argv[])
{
char buf[256];
time_of_process_start = time(NULL);
if (!closeable_connection_lst)
closeable_connection_lst = smartlist_create();
if (!active_linked_connection_lst)
active_linked_connection_lst = smartlist_create();
/* Have the log set up with our application name. */
tor_snprintf(buf, sizeof(buf), "Tor %s", get_version());
log_set_application_name(buf);
/* Initialize the history structures. */
rep_hist_init();
/* Initialize the service cache. */
......@@ -1700,7 +1704,7 @@ tor_init(int argc, char *argv[])
add_temp_log();
log(LOG_NOTICE, LD_GENERAL, "Tor v%s. This is experimental software. "
"Do not rely on it for strong anonymity. (Running on %s)",VERSION,
"Do not rely on it for strong anonymity. (Running on %s)",get_version(),
get_uname());
if (network_init()<0) {
......
......@@ -2223,6 +2223,7 @@ int set_options(or_options_t *new_val, char **msg);
void config_free_all(void);
const char *safe_str(const char *address);
const char *escaped_safe_str(const char *address);
const char *get_version(void);
int config_get_lines(char *string, config_line_t **result);
void config_free_lines(config_line_t *front);
......
......@@ -1249,17 +1249,7 @@ extern const char tor_svn_revision[]; /* from main.c */
void
get_platform_str(char *platform, size_t len)
{
char svn_version_buf[128];
if (!strcmpend(VERSION, "-dev") && strlen(tor_svn_revision)) {
tor_snprintf(svn_version_buf, sizeof(svn_version_buf), " (r%s)",
tor_svn_revision);
} else {
svn_version_buf[0] = 0;
}
tor_snprintf(platform, len, "Tor %s%s on %s",
VERSION, svn_version_buf, get_uname());
return;
tor_snprintf(platform, len, "Tor %s on %s", get_version(), get_uname());
}
/* XXX need to audit this thing and count fenceposts. maybe
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment