aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-05-22 15:48:46 +0000
committerNick Mathewson <nickm@torproject.org>2007-05-22 15:48:46 +0000
commite935d73b34094a88dbd997769be1c52b633fc3d3 (patch)
treeb4ce641936e6998987b887e94374b761bd9f6d2b
parent4ec5e139c8442b321ef9b58684da547ea0388261 (diff)
downloadtor-e935d73b34094a88dbd997769be1c52b633fc3d3.tar
tor-e935d73b34094a88dbd997769be1c52b633fc3d3.tar.gz
r12852@catbus: nickm | 2007-05-22 11:00:27 -0400
Use svn revisions consistently throughout all log messages. svn:r10291
-rw-r--r--src/common/log.c20
-rw-r--r--src/common/log.h1
-rw-r--r--src/or/config.c34
-rw-r--r--src/or/control.c7
-rw-r--r--src/or/main.c6
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/router.c12
7 files changed, 54 insertions, 27 deletions
diff --git a/src/common/log.c b/src/common/log.c
index 650e17b10..7e83d831a 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -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 */
diff --git a/src/common/log.h b/src/common/log.h
index af17e2e2c..f451599d0 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -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, ...)
diff --git a/src/or/config.c b/src/or/config.c
index 51610e777..69de3a51b 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -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);
diff --git a/src/or/control.c b/src/or/control.c
index 0fbcb5eab..5ee5714f0 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -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));
diff --git a/src/or/main.c b/src/or/main.c
index f0522f6fa..315e0f11a 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -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) {
diff --git a/src/or/or.h b/src/or/or.h
index f595dbd16..927cc94d9 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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);
diff --git a/src/or/router.c b/src/or/router.c
index 796a49d8f..826ccc0eb 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -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