From a0569d2d3cdca5d6ed78e0df77b08ccbbec52570 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 02:22:56 +0100 Subject: Report the version, event machanism and feature flags with -v --- man1/opentracker.1 | 4 +++ ot_config.c | 2 ++ ot_stats.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ot_stats.h | 1 + 4 files changed, 94 insertions(+) diff --git a/man1/opentracker.1 b/man1/opentracker.1 index 0103ebe..489a54c 100644 --- a/man1/opentracker.1 +++ b/man1/opentracker.1 @@ -15,6 +15,7 @@ .Op Fl d Ar chdir .Op Fl u Ar user .Op Fl w| Fl b accesslist +.Op Fl v .Sh DESCRIPTION .Nm is a bittorrent tracker that implements announce and scrape actions over the @@ -85,6 +86,9 @@ has been compiled with the or .Br WANT_ACCESSLIST_WHITE options, this option sets the location of the accesslist. +.It Fl v +Report the version, the event mechanism in use and the feature flags this +binary was built with. .El .Sh EXAMPLES Start diff --git a/ot_config.c b/ot_config.c index 272acf1..5da6642 100644 --- a/ot_config.c +++ b/ot_config.c @@ -432,6 +432,7 @@ static void help(char *name) { HELPLINE("-d dir", "specify directory to try to chroot to (default: \".\")"); HELPLINE("-u user", "specify user under whose privileges opentracker should run (default: \"nobody\")"); HELPLINE("-A ip[/bits]", "bless an ip address or net as admin address (e.g. to allow syncs from this address)"); + HELPLINE("-v", "report version, event mechanism and the feature flags opentracker was built with"); #ifdef WANT_ACCESSLIST_BLACK HELPLINE("-b file", "specify blacklist file."); #elif defined(WANT_ACCESSLIST_WHITE) @@ -566,6 +567,7 @@ void config_parse(int argc, char **argv) { char *cursor = buffer; stats_return_tracker_version(&cursor, buffer + sizeof(buffer) - 1); + stats_return_tracker_features(&cursor, buffer + sizeof(buffer) - 1); *cursor = 0; fputs(buffer, stderr); exit(0); diff --git a/ot_stats.c b/ot_stats.c index a9f12cc..5edbe0a 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -19,6 +19,7 @@ /* Opentracker */ #include "ot_accesslist.h" +#include "ot_event.h" #include "ot_hex.h" #include "ot_iovec.h" #include "ot_ip.h" @@ -546,6 +547,92 @@ static void stats_return_everything(char **reply, const char *reply_end) { fmt_append(reply, reply_end, ""); } +/* The names as the Makefile spells them, so that what a binary reports maps + straight back onto the FEATURES lines it was built from */ +static const char *const build_features[] = { +#ifdef WANT_V4_ONLY + "WANT_V4_ONLY", +#endif +#ifdef WANT_ACCESSLIST_BLACK + "WANT_ACCESSLIST_BLACK", +#endif +#ifdef WANT_ACCESSLIST_WHITE + "WANT_ACCESSLIST_WHITE", +#endif +#ifdef WANT_DYNAMIC_ACCESSLIST + "WANT_DYNAMIC_ACCESSLIST", +#endif +#ifdef WANT_SYNC_LIVE + "WANT_SYNC_LIVE", +#endif +#ifdef WANT_IP_FROM_QUERY_STRING + "WANT_IP_FROM_QUERY_STRING", +#endif +#ifdef WANT_IP_FROM_PROXY + "WANT_IP_FROM_PROXY", +#endif +#ifdef WANT_COMPRESSION_GZIP + "WANT_COMPRESSION_GZIP", +#endif +#ifdef WANT_COMPRESSION_GZIP_ALWAYS + "WANT_COMPRESSION_GZIP_ALWAYS", +#endif +#ifdef WANT_COMPRESSION_ZSTD + "WANT_COMPRESSION_ZSTD", +#endif +#ifdef WANT_COMPRESSION_ZSTD_ALWAYS + "WANT_COMPRESSION_ZSTD_ALWAYS", +#endif +#ifdef WANT_FULLSCRAPE + "WANT_FULLSCRAPE", +#endif +#ifdef WANT_MODEST_FULLSCRAPES + "WANT_MODEST_FULLSCRAPES", +#endif +#ifdef WANT_KEEPALIVE + "WANT_KEEPALIVE", +#endif +#ifdef WANT_RESTRICT_STATS + "WANT_RESTRICT_STATS", +#endif +#ifdef WANT_LOG_NUMWANT + "WANT_LOG_NUMWANT", +#endif +#ifdef WANT_SPOT_WOODPECKER + "WANT_SPOT_WOODPECKER", +#endif +#ifdef WANT_SYSLOGS + "WANT_SYSLOGS", +#endif +#ifdef WANT_DEV_RANDOM + "WANT_DEV_RANDOM", +#endif +#ifdef WANT_INSECURE_RANDOM_FALLBACK + "WANT_INSECURE_RANDOM_FALLBACK", +#endif +#ifdef _DEBUG + "_DEBUG", +#endif +#ifdef _DEBUG_HTTPERROR + "_DEBUG_HTTPERROR", +#endif +#ifdef _DEBUG_RANDOMTORRENTS + "_DEBUG_RANDOMTORRENTS", +#endif + NULL}; + +void stats_return_tracker_features(char **reply, const char *reply_end) { + size_t i; + + fmt_append(reply, reply_end, "events: %s\n", event_mechanism()); + fmt_append(reply, reply_end, "features:"); + for (i = 0; build_features[i]; ++i) + fmt_append(reply, reply_end, " %s", build_features[i]); + if (!build_features[0]) + fmt_append(reply, reply_end, " none"); + fmt_append(reply, reply_end, "\n"); +} + void stats_return_tracker_version(char **reply, const char *reply_end) { fmt_append(reply, reply_end, "opentracker %s", OT_VERSION); /* Empty when the build had no git to ask, which is what a release tarball diff --git a/ot_stats.h b/ot_stats.h index f484765..f9a9d87 100644 --- a/ot_stats.h +++ b/ot_stats.h @@ -35,6 +35,7 @@ void stats_deliver(int64_t sock, int tasktype); void stats_cleanup(void); void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int format); void stats_return_tracker_version(char **reply, const char *reply_end); +void stats_return_tracker_features(char **reply, const char *reply_end); void stats_init(void); void stats_deinit(void); -- cgit v1.3