mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-23 20:03:31 +01:00
Move the code that knows our tor version into a lowest-level lib
This commit is contained in:
parent
7bb76b24cf
commit
6e7ff8cba0
2
.gitignore
vendored
2
.gitignore
vendored
@ -210,6 +210,8 @@ uptime-*.json
|
||||
/src/lib/libtor-tls.a
|
||||
/src/lib/libtor-tls-testing.a
|
||||
/src/lib/libtor-trace.a
|
||||
/src/lib/libtor-version.a
|
||||
/src/lib/libtor-version-testing.a
|
||||
/src/lib/libtor-wallclock.a
|
||||
/src/lib/libtor-wallclock-testing.a
|
||||
|
||||
|
@ -62,6 +62,7 @@ TOR_UTIL_LIBS = \
|
||||
src/lib/libtor-malloc.a \
|
||||
src/lib/libtor-wallclock.a \
|
||||
src/lib/libtor-err.a \
|
||||
src/lib/libtor-version.a \
|
||||
src/lib/libtor-intmath.a \
|
||||
src/lib/libtor-ctime.a
|
||||
|
||||
@ -91,6 +92,7 @@ TOR_UTIL_TESTING_LIBS = \
|
||||
src/lib/libtor-malloc-testing.a \
|
||||
src/lib/libtor-wallclock-testing.a \
|
||||
src/lib/libtor-err-testing.a \
|
||||
src/lib/libtor-version-testing.a \
|
||||
src/lib/libtor-intmath.a \
|
||||
src/lib/libtor-ctime-testing.a
|
||||
endif
|
||||
|
@ -112,9 +112,9 @@
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
#include "lib/crypt_ops/crypto_util.h"
|
||||
#include "lib/encoding/confline.h"
|
||||
#include "lib/log/git_revision.h"
|
||||
#include "lib/net/resolve.h"
|
||||
#include "lib/sandbox/sandbox.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
#ifdef ENABLE_NSS
|
||||
#include "lib/crypt_ops/crypto_nss_mgt.h"
|
||||
@ -972,42 +972,6 @@ set_options(or_options_t *new_val, char **msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** The version of this Tor process, as parsed. */
|
||||
static char *the_tor_version = NULL;
|
||||
/** A shorter version of this Tor process's version, for export in our router
|
||||
* descriptor. (Does not include the git version, if any.) */
|
||||
static char *the_short_tor_version = NULL;
|
||||
|
||||
/** Return the current Tor version. */
|
||||
const char *
|
||||
get_version(void)
|
||||
{
|
||||
if (the_tor_version == NULL) {
|
||||
if (strlen(tor_git_revision)) {
|
||||
tor_asprintf(&the_tor_version, "%s (git-%s)", get_short_version(),
|
||||
tor_git_revision);
|
||||
} else {
|
||||
the_tor_version = tor_strdup(get_short_version());
|
||||
}
|
||||
}
|
||||
return the_tor_version;
|
||||
}
|
||||
|
||||
/** Return the current Tor version, without any git tag. */
|
||||
const char *
|
||||
get_short_version(void)
|
||||
{
|
||||
|
||||
if (the_short_tor_version == NULL) {
|
||||
#ifdef TOR_BUILD_TAG
|
||||
tor_asprintf(&the_short_tor_version, "%s (%s)", VERSION, TOR_BUILD_TAG);
|
||||
#else
|
||||
the_short_tor_version = tor_strdup(VERSION);
|
||||
#endif
|
||||
}
|
||||
return the_short_tor_version;
|
||||
}
|
||||
|
||||
/** Release additional memory allocated in options
|
||||
*/
|
||||
STATIC void
|
||||
@ -1067,9 +1031,6 @@ config_free_all(void)
|
||||
tor_free(torrc_defaults_fname);
|
||||
tor_free(global_dirfrontpagecontents);
|
||||
|
||||
tor_free(the_short_tor_version);
|
||||
tor_free(the_tor_version);
|
||||
|
||||
cleanup_protocol_warning_severity_level();
|
||||
|
||||
have_parsed_cmdline = 0;
|
||||
|
@ -41,8 +41,6 @@ const char *escaped_safe_str_client(const char *address);
|
||||
const char *escaped_safe_str(const char *address);
|
||||
void init_protocol_warning_severity_level(void);
|
||||
int get_protocol_warning_severity_level(void);
|
||||
const char *get_version(void);
|
||||
const char *get_short_version(void);
|
||||
|
||||
/** An error from options_trial_assign() or options_init_from_string(). */
|
||||
typedef enum setopt_err_t {
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "app/config/statefile.h"
|
||||
#include "lib/encoding/confline.h"
|
||||
#include "lib/net/resolve.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
#include "app/config/or_state_st.h"
|
||||
|
||||
|
@ -84,6 +84,7 @@
|
||||
#include "lib/encoding/confline.h"
|
||||
#include "lib/evloop/timers.h"
|
||||
#include "lib/crypt_ops/crypto_init.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
|
@ -92,6 +92,7 @@
|
||||
#include "lib/crypt_ops/crypto_util.h"
|
||||
#include "lib/encoding/confline.h"
|
||||
#include "lib/evloop/compat_libevent.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
#include "feature/dircache/cached_dir_st.h"
|
||||
#include "feature/control/control_connection_st.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "feature/dirauth/shared_random_state.h"
|
||||
#include "feature/dircommon/voting_schedule.h"
|
||||
#include "lib/encoding/confline.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
#include "app/config/or_state_st.h"
|
||||
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "lib/encoding/confline.h"
|
||||
#include "lib/osinfo/uname.h"
|
||||
#include "lib/tls/tortls.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
#include "feature/dirauth/authmode.h"
|
||||
|
||||
|
@ -33,6 +33,7 @@ include src/lib/thread/include.am
|
||||
include src/lib/time/include.am
|
||||
include src/lib/tls/include.am
|
||||
include src/lib/trace/include.am
|
||||
include src/lib/version/include.am
|
||||
include src/lib/wallclock/include.am
|
||||
include src/trunnel/include.am
|
||||
|
||||
|
@ -10,6 +10,5 @@ lib/log/*.h
|
||||
lib/malloc/*.h
|
||||
lib/string/*.h
|
||||
lib/testsupport/*.h
|
||||
lib/version/*.h
|
||||
lib/wallclock/*.h
|
||||
|
||||
micro-revision.i
|
@ -7,7 +7,6 @@ endif
|
||||
|
||||
src_lib_libtor_log_a_SOURCES = \
|
||||
src/lib/log/escape.c \
|
||||
src/lib/log/git_revision.c \
|
||||
src/lib/log/ratelim.c \
|
||||
src/lib/log/log.c \
|
||||
src/lib/log/util_bug.c
|
||||
@ -21,15 +20,8 @@ src_lib_libtor_log_testing_a_SOURCES = \
|
||||
src_lib_libtor_log_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
|
||||
src_lib_libtor_log_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
|
||||
|
||||
# Declare that these object files depend on micro-revision.i. Without this
|
||||
# rule, we could try to build them before micro-revision.i was created.
|
||||
src/lib/log/git_revision.$(OBJEXT) \
|
||||
src/lib/log/src_lib_libtor_log_testing_a-git_revision.$(OBJEXT): \
|
||||
micro-revision.i
|
||||
|
||||
noinst_HEADERS += \
|
||||
src/lib/log/escape.h \
|
||||
src/lib/log/git_revision.h \
|
||||
src/lib/log/ratelim.h \
|
||||
src/lib/log/log.h \
|
||||
src/lib/log/util_bug.h \
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#define LOG_PRIVATE
|
||||
#include "lib/log/log.h"
|
||||
#include "lib/log/git_revision.h"
|
||||
#include "lib/version/git_revision.h"
|
||||
#include "lib/log/ratelim.h"
|
||||
#include "lib/lock/compat_mutex.h"
|
||||
#include "lib/smartlist_core/smartlist_core.h"
|
||||
|
3
src/lib/version/.may_include
Normal file
3
src/lib/version/.may_include
Normal file
@ -0,0 +1,3 @@
|
||||
orconfig.h
|
||||
micro-revision.i
|
||||
lib/version/*.h
|
@ -4,7 +4,7 @@
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#include "orconfig.h"
|
||||
#include "lib/log/git_revision.h"
|
||||
#include "lib/version/git_revision.h"
|
||||
|
||||
/** String describing which Tor Git repository version the source was
|
||||
* built from. This string is generated by a bit of shell kludging in
|
25
src/lib/version/include.am
Normal file
25
src/lib/version/include.am
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
noinst_LIBRARIES += src/lib/libtor-version.a
|
||||
|
||||
if UNITTESTS_ENABLED
|
||||
noinst_LIBRARIES += src/lib/libtor-version-testing.a
|
||||
endif
|
||||
|
||||
src_lib_libtor_version_a_SOURCES = \
|
||||
src/lib/version/git_revision.c \
|
||||
src/lib/version/version.c
|
||||
|
||||
src_lib_libtor_version_testing_a_SOURCES = \
|
||||
$(src_lib_libtor_version_a_SOURCES)
|
||||
src_lib_libtor_version_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
|
||||
src_lib_libtor_version_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
|
||||
|
||||
# Declare that these object files depend on micro-revision.i. Without this
|
||||
# rule, we could try to build them before micro-revision.i was created.
|
||||
src/lib/version/git_revision.$(OBJEXT) \
|
||||
src/lib/version/src_lib_libtor_version_testing_a-git_revision.$(OBJEXT): \
|
||||
micro-revision.i
|
||||
|
||||
noinst_HEADERS += \
|
||||
src/lib/version/git_revision.h \
|
||||
src/lib/version/torversion.h
|
12
src/lib/version/torversion.h
Normal file
12
src/lib/version/torversion.h
Normal file
@ -0,0 +1,12 @@
|
||||
/* Copyright 2001-2004 Roger Dingledine.
|
||||
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
||||
* Copyright (c) 2007-2018, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#ifndef TOR_VERSION_H
|
||||
#define TOR_VERSION_H
|
||||
|
||||
const char *get_version(void);
|
||||
const char *get_short_version(void);
|
||||
|
||||
#endif /* !defined(TOR_VERSION_H) */
|
50
src/lib/version/version.c
Normal file
50
src/lib/version/version.c
Normal file
@ -0,0 +1,50 @@
|
||||
/* Copyright 2001-2004 Roger Dingledine.
|
||||
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
||||
* Copyright (c) 2007-2018, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#include "orconfig.h"
|
||||
#include "lib/version/torversion.h"
|
||||
#include "lib/version/git_revision.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/** A shorter version of this Tor process's version, for export in our router
|
||||
* descriptor. (Does not include the git version, if any.) */
|
||||
static const char the_short_tor_version[] =
|
||||
VERSION
|
||||
#ifdef TOR_BUILD_TAG
|
||||
" ("TOR_BUILD_TAG")"
|
||||
#endif
|
||||
"";
|
||||
|
||||
#define MAX_VERSION_LEN 128
|
||||
|
||||
/** The version of this Tor process, possibly including git version */
|
||||
static char the_tor_version[MAX_VERSION_LEN] = "";
|
||||
|
||||
/** Return the current Tor version. */
|
||||
const char *
|
||||
get_version(void)
|
||||
{
|
||||
if (the_tor_version[0] == 0) {
|
||||
if (strlen(tor_git_revision)) {
|
||||
snprintf(the_tor_version, sizeof(the_tor_version),
|
||||
"%s (git-%s)", the_short_tor_version, tor_git_revision);
|
||||
} else {
|
||||
snprintf(the_tor_version, sizeof(the_tor_version),
|
||||
"%s", the_short_tor_version);
|
||||
}
|
||||
the_tor_version[sizeof(the_tor_version)-1] = 0;
|
||||
}
|
||||
|
||||
return the_tor_version;
|
||||
}
|
||||
|
||||
/** Return the current Tor version, without any git tag. */
|
||||
const char *
|
||||
get_short_version(void)
|
||||
{
|
||||
return the_short_tor_version;
|
||||
}
|
@ -162,6 +162,7 @@ pub fn main() {
|
||||
cfg.component("tor-malloc");
|
||||
cfg.component("tor-wallclock");
|
||||
cfg.component("tor-err-testing");
|
||||
cfg.component("tor-version-testing");
|
||||
cfg.component("tor-intmath-testing");
|
||||
cfg.component("tor-ctime-testing");
|
||||
cfg.component("curve25519_donna");
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "lib/compress/compress.h"
|
||||
#include "lib/crypt_ops/crypto_ed25519.h"
|
||||
#include "lib/crypt_ops/crypto_init.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
static or_options_t *mock_options = NULL;
|
||||
static const or_options_t *
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "lib/compress/compress.h"
|
||||
#include "lib/evloop/compat_libevent.h"
|
||||
#include "lib/crypt_ops/crypto_init.h"
|
||||
#include "lib/version/torversion.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_FCNTL_H
|
||||
|
Loading…
Reference in New Issue
Block a user