From 1f9494979268b62ed4b4588fb7d9e790c0e12100 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 22:32:52 +0100 Subject: replace all calls to sprintf with a format helper that advances a cursor. Also convert the meta-formatter (i.e. results printer) to this scheme --- ot_stats.c | 304 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 150 insertions(+), 154 deletions(-) (limited to 'ot_stats.c') diff --git a/ot_stats.c b/ot_stats.c index 53bd749..45dc8db 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -22,6 +22,7 @@ #include "ot_iovec.h" #include "ot_ip.h" #include "ot_mutex.h" +#include "ot_fmt.h" #include "ot_stats.h" #include "trackerlogic.h" @@ -184,12 +185,11 @@ static size_t stats_get_highscore_networks(stats_network_node *node, int depth, return score; } -static size_t stats_return_busy_networks(char *reply, stats_network_node *tree, size_t amount, int limit) { +static void stats_return_busy_networks(char **reply, const char *reply_end, stats_network_node *tree, size_t amount, int limit) { ot_ip6 networks[amount]; ot_ip6 node_value; size_t scores[amount]; size_t i; - char *r = reply; memset(scores, 0, sizeof(scores)); memset(networks, 0, sizeof(networks)); @@ -197,24 +197,21 @@ static size_t stats_return_busy_networks(char *reply, stats_network_node *tree, stats_get_highscore_networks(tree, 0, node_value, scores, networks, amount, limit); - r += sprintf(r, "Networks, limit /%d:\n", limit + STATS_NETWORK_NODE_BITWIDTH); + fmt_append(reply, reply_end, "Networks, limit /%d:\n", limit + STATS_NETWORK_NODE_BITWIDTH); for (i = amount; i > 0; --i) { if (scores[i - 1]) { - r += sprintf(r, "%08zd: ", scores[i - 1]); - // #ifdef WANT_V6 - r += ip_format(r, networks[i - 1]); - *r++ = '\n'; + char ip_readable[64]; + + ip_readable[ip_format(ip_readable, networks[i - 1])] = 0; + fmt_append(reply, reply_end, "%08zd: %s\n", scores[i - 1], ip_readable); } } - *r++ = '\n'; - - return r - reply; + fmt_append(reply, reply_end, "\n"); } -static size_t stats_slash24s_txt(char *reply, size_t amount) { +static void stats_slash24s_txt(char **reply, const char *reply_end, size_t amount) { stats_network_node *slash24s_network_counters_root = NULL; - char *r = reply; - size_t i, bucket, peer_size = OT_PEER_SIZE4; + size_t i, bucket, peer_size = OT_PEER_SIZE4; for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { ot_vector *torrents_list = mutex_bucket_lock(bucket); @@ -241,35 +238,28 @@ static size_t stats_slash24s_txt(char *reply, size_t amount) { } mutex_bucket_unlock(bucket, 0); if (!g_opentracker_running) - goto bailout_error; + goto done; } /* The tree is built. Now analyze */ - r += stats_return_busy_networks(r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_MAXDEPTH); - r += stats_return_busy_networks(r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_LIMIT); - goto success; + stats_return_busy_networks(reply, reply_end, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_MAXDEPTH); + stats_return_busy_networks(reply, reply_end, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_LIMIT); + goto done; bailout_unlock: mutex_bucket_unlock(bucket, 0); -bailout_error: - r = reply; -success: +done: stats_shift_down_network_count(&slash24s_network_counters_root, 0, sizeof(int) * 8 - 1); - - return r - reply; } #ifdef WANT_SPOT_WOODPECKER static stats_network_node *stats_woodpeckers_tree; static pthread_mutex_t g_woodpeckers_mutex = PTHREAD_MUTEX_INITIALIZER; -static size_t stats_return_woodpeckers(char *reply, int amount) { - char *r = reply; - +static void stats_return_woodpeckers(char **reply, const char *reply_end, int amount) { pthread_mutex_lock(&g_woodpeckers_mutex); - r += stats_return_busy_networks(r, stats_woodpeckers_tree, amount, STATS_NETWORK_NODE_MAXDEPTH); + stats_return_busy_networks(reply, reply_end, stats_woodpeckers_tree, amount, STATS_NETWORK_NODE_MAXDEPTH); pthread_mutex_unlock(&g_woodpeckers_mutex); - return r - reply; } #endif @@ -309,10 +299,10 @@ static inline void stats_insert_into_highscore(size_t val, ot_record* list, size /* Fetches stats from tracker */ -size_t stats_top_txt(char *reply, size_t amount) { +void stats_top_txt(char **reply, const char *reply_end, size_t amount) { size_t j, idx, bucket; ot_record top100s[100], top100c[100], top100l[100]; - char *r = reply, hex_out[42]; + char hex_out[42]; if (amount > 100) amount = 100; @@ -323,7 +313,7 @@ size_t stats_top_txt(char *reply, size_t amount) { /* Iterate over complete torrent list */ for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { - ot_vector *torrents_list = mutex_bucket_lock(bucket); + ot_vector *torrents_list = mutex_bucket_lock(bucket); for (j = 0; j < torrents_list->size; ++j) { ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j; size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; @@ -336,114 +326,110 @@ size_t stats_top_txt(char *reply, size_t amount) { } mutex_bucket_unlock(bucket, 0); if (!g_opentracker_running) - return 0; + return; } - r += sprintf(r, "Top %zd torrents by peers:\n", amount); + fmt_append(reply, reply_end, "Top %zd torrents by peers:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100c[idx].val) - r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, hex_from_hash(hex_out, top100c[idx].hash)); - r += sprintf(r, "Top %zd torrents by seeds:\n", amount); + fmt_append(reply, reply_end, "\t%zd\t%s\n", top100c[idx].val, hex_from_hash(hex_out, top100c[idx].hash)); + fmt_append(reply, reply_end, "Top %zd torrents by seeds:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100s[idx].val) - r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, hex_from_hash(hex_out, top100s[idx].hash)); - r += sprintf(r, "Top %zd torrents by leechers:\n", amount); + fmt_append(reply, reply_end, "\t%zd\t%s\n", top100s[idx].val, hex_from_hash(hex_out, top100s[idx].hash)); + fmt_append(reply, reply_end, "Top %zd torrents by leechers:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100l[idx].val) - r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, hex_from_hash(hex_out, top100l[idx].hash)); - - return r - reply; + fmt_append(reply, reply_end, "\t%zd\t%s\n", top100l[idx].val, hex_from_hash(hex_out, top100l[idx].hash)); } static unsigned long events_per_time(unsigned long long events, time_t t) { return events / ((unsigned int)t ? (unsigned int)t : 1); } -static size_t stats_connections_mrtg(char *reply) { +static void stats_connections_mrtg(char **reply, const char *reply_end) { ot_time t = time(NULL) - ot_start_time; - return sprintf(reply, "%llu\n%llu\n%i seconds (%i hours)\nopentracker connections, %lu conns/s :: %lu success/s.", - ot_overall_tcp_connections + ot_overall_udp_connections, - ot_overall_tcp_successfulannounces + ot_overall_udp_successfulannounces + ot_overall_udp_connects, (int)t, (int)(t / 3600), - events_per_time(ot_overall_tcp_connections + ot_overall_udp_connections, t), - events_per_time(ot_overall_tcp_successfulannounces + ot_overall_udp_successfulannounces + ot_overall_udp_connects, t)); + fmt_append(reply, reply_end, "%llu\n%llu\n%i seconds (%i hours)\nopentracker connections, %lu conns/s :: %lu success/s.", + ot_overall_tcp_connections + ot_overall_udp_connections, + ot_overall_tcp_successfulannounces + ot_overall_udp_successfulannounces + ot_overall_udp_connects, (int)t, (int)(t / 3600), + events_per_time(ot_overall_tcp_connections + ot_overall_udp_connections, t), + events_per_time(ot_overall_tcp_successfulannounces + ot_overall_udp_successfulannounces + ot_overall_udp_connects, t)); } -static size_t stats_udpconnections_mrtg(char *reply) { +static void stats_udpconnections_mrtg(char **reply, const char *reply_end) { ot_time t = time(NULL) - ot_start_time; - return sprintf(reply, "%llu\n%llu\n%i seconds (%i hours)\nopentracker udp4 stats, %lu conns/s :: %lu success/s.", ot_overall_udp_connections, - ot_overall_udp_successfulannounces + ot_overall_udp_connects, (int)t, (int)(t / 3600), events_per_time(ot_overall_udp_connections, t), - events_per_time(ot_overall_udp_successfulannounces + ot_overall_udp_connects, t)); + fmt_append(reply, reply_end, "%llu\n%llu\n%i seconds (%i hours)\nopentracker udp4 stats, %lu conns/s :: %lu success/s.", ot_overall_udp_connections, + ot_overall_udp_successfulannounces + ot_overall_udp_connects, (int)t, (int)(t / 3600), events_per_time(ot_overall_udp_connections, t), + events_per_time(ot_overall_udp_successfulannounces + ot_overall_udp_connects, t)); } -static size_t stats_tcpconnections_mrtg(char *reply) { +static void stats_tcpconnections_mrtg(char **reply, const char *reply_end) { time_t t = time(NULL) - ot_start_time; - return sprintf(reply, "%llu\n%llu\n%i seconds (%i hours)\nopentracker tcp4 stats, %lu conns/s :: %lu success/s.", ot_overall_tcp_connections, - ot_overall_tcp_successfulannounces, (int)t, (int)(t / 3600), events_per_time(ot_overall_tcp_connections, t), - events_per_time(ot_overall_tcp_successfulannounces, t)); + fmt_append(reply, reply_end, "%llu\n%llu\n%i seconds (%i hours)\nopentracker tcp4 stats, %lu conns/s :: %lu success/s.", ot_overall_tcp_connections, + ot_overall_tcp_successfulannounces, (int)t, (int)(t / 3600), events_per_time(ot_overall_tcp_connections, t), + events_per_time(ot_overall_tcp_successfulannounces, t)); } -static size_t stats_scrape_mrtg(char *reply) { +static void stats_scrape_mrtg(char **reply, const char *reply_end) { time_t t = time(NULL) - ot_start_time; - return sprintf(reply, "%llu\n%llu\n%i seconds (%i hours)\nopentracker scrape stats, %lu scrape/s (tcp and udp)", ot_overall_tcp_successfulscrapes, - ot_overall_udp_successfulscrapes, (int)t, (int)(t / 3600), - events_per_time((ot_overall_tcp_successfulscrapes + ot_overall_udp_successfulscrapes), t)); + fmt_append(reply, reply_end, "%llu\n%llu\n%i seconds (%i hours)\nopentracker scrape stats, %lu scrape/s (tcp and udp)", + ot_overall_tcp_successfulscrapes, ot_overall_udp_successfulscrapes, (int)t, (int)(t / 3600), + events_per_time((ot_overall_tcp_successfulscrapes + ot_overall_udp_successfulscrapes), t)); } -static size_t stats_fullscrapes_mrtg(char *reply) { +static void stats_fullscrapes_mrtg(char **reply, const char *reply_end) { ot_time t = time(NULL) - ot_start_time; - return sprintf(reply, "%llu\n%llu\n%i seconds (%i hours)\nopentracker full scrape stats, %lu conns/s :: %lu bytes/s.", ot_full_scrape_count * 1000, - ot_full_scrape_size, (int)t, (int)(t / 3600), events_per_time(ot_full_scrape_count, t), events_per_time(ot_full_scrape_size, t)); + fmt_append(reply, reply_end, "%llu\n%llu\n%i seconds (%i hours)\nopentracker full scrape stats, %lu conns/s :: %lu bytes/s.", + ot_full_scrape_count * 1000, ot_full_scrape_size, (int)t, (int)(t / 3600), events_per_time(ot_full_scrape_count, t), + events_per_time(ot_full_scrape_size, t)); } -static size_t stats_peers_mrtg(char *reply) { +static void stats_peers_mrtg(char **reply, const char *reply_end) { torrent_stats stats = {0, 0, 0}; iterate_all_torrents(torrent_statter, (uintptr_t)&stats); - return sprintf(reply, "%llu\n%llu\nopentracker serving %llu torrents\nopentracker", stats.peer_count, stats.seed_count, stats.torrent_count); + fmt_append(reply, reply_end, "%llu\n%llu\nopentracker serving %llu torrents\nopentracker", stats.peer_count, stats.seed_count, + stats.torrent_count); } -static size_t stats_torrents_mrtg(char *reply) { +static void stats_torrents_mrtg(char **reply, const char *reply_end) { size_t torrent_count = mutex_get_torrent_count(); - return sprintf(reply, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", torrent_count, (size_t)0, torrent_count); + fmt_append(reply, reply_end, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", torrent_count, (size_t)0, torrent_count); } -static size_t stats_httperrors_txt(char *reply) { - return sprintf(reply, "302 RED %llu\n400 ... %llu\n400 PAR %llu\n400 COM %llu\n403 IP %llu\n404 INV %llu\n500 SRV %llu\n", ot_failed_request_counts[0], - ot_failed_request_counts[1], ot_failed_request_counts[2], ot_failed_request_counts[3], ot_failed_request_counts[4], - ot_failed_request_counts[5], ot_failed_request_counts[6]); +static void stats_httperrors_txt(char **reply, const char *reply_end) { + fmt_append(reply, reply_end, "302 RED %llu\n400 ... %llu\n400 PAR %llu\n400 COM %llu\n403 IP %llu\n404 INV %llu\n500 SRV %llu\n", + ot_failed_request_counts[0], ot_failed_request_counts[1], ot_failed_request_counts[2], ot_failed_request_counts[3], + ot_failed_request_counts[4], ot_failed_request_counts[5], ot_failed_request_counts[6]); } -static size_t stats_return_renew_bucket(char *reply) { - char *r = reply; - int i; +static void stats_return_renew_bucket(char **reply, const char *reply_end) { + int i; for (i = 0; i < OT_PEER_TIMEOUT; ++i) - r += sprintf(r, "%02i %llu\n", i, ot_renewed[i]); - return r - reply; + fmt_append(reply, reply_end, "%02i %llu\n", i, ot_renewed[i]); } -static size_t stats_return_sync_mrtg(char *reply) { +static void stats_return_sync_mrtg(char **reply, const char *reply_end) { ot_time t = time(NULL) - ot_start_time; - return sprintf(reply, "%llu\n%llu\n%i seconds (%i hours)\nopentracker connections, %lu conns/s :: %lu success/s.", ot_overall_sync_count, 0LL, (int)t, - (int)(t / 3600), events_per_time(ot_overall_tcp_connections + ot_overall_udp_connections, t), - events_per_time(ot_overall_tcp_successfulannounces + ot_overall_udp_successfulannounces + ot_overall_udp_connects, t)); + fmt_append(reply, reply_end, "%llu\n%llu\n%i seconds (%i hours)\nopentracker connections, %lu conns/s :: %lu success/s.", ot_overall_sync_count, 0LL, + (int)t, (int)(t / 3600), events_per_time(ot_overall_tcp_connections + ot_overall_udp_connections, t), + events_per_time(ot_overall_tcp_successfulannounces + ot_overall_udp_successfulannounces + ot_overall_udp_connects, t)); } -static size_t stats_return_completed_mrtg(char *reply) { +static void stats_return_completed_mrtg(char **reply, const char *reply_end) { ot_time t = time(NULL) - ot_start_time; - return sprintf(reply, "%llu\n%llu\n%i seconds (%i hours)\nopentracker, %lu completed/h.", ot_overall_completed, 0LL, (int)t, (int)(t / 3600), - events_per_time(ot_overall_completed, t / 3600)); + fmt_append(reply, reply_end, "%llu\n%llu\n%i seconds (%i hours)\nopentracker, %lu completed/h.", ot_overall_completed, 0LL, (int)t, (int)(t / 3600), + events_per_time(ot_overall_completed, t / 3600)); } #ifdef WANT_LOG_NUMWANT extern unsigned long long numwants[201]; -static size_t stats_return_numwants(char *reply) { - char *r = reply; - int i; +static void stats_return_numwants(char **reply, const char *reply_end) { + int i; for (i = 0; i <= 200; ++i) - r += sprintf(r, "%03d => %lld\n", i, numwants[i]); - return r - reply; + fmt_append(reply, reply_end, "%03d => %lld\n", i, numwants[i]); } #endif @@ -461,17 +447,14 @@ static void stats_return_fulllog(size_t *iovec_entries, struct iovec **iovector, return; re = r + 32 * OT_STATS_TMPSIZE; } - r += sprintf(r, "%08ld: ", loglist->time); - r += ip_format(r, loglist->ip); - *r++ = '\n'; - memcpy(r, loglist->data, loglist->size); - r += loglist->size; - *r++ = '\n'; - *r++ = '*'; - *r++ = '\n'; - *r++ = '\n'; - - llnext = loglist->next; + char ip_readable[64]; + + ip_readable[ip_format(ip_readable, loglist->ip)] = 0; + fmt_append(&r, re, "%08ld: %s\n", loglist->time, ip_readable); + fmt_bytes(&r, re, loglist->data, loglist->size); + fmt_append(&r, re, "\n*\n\n"); + + llnext = loglist->next; free(loglist->data); free(loglist); loglist = llnext; @@ -480,124 +463,137 @@ static void stats_return_fulllog(size_t *iovec_entries, struct iovec **iovector, } #endif -static size_t stats_return_everything(char *reply) { +static void stats_return_everything(char **reply, const char *reply_end) { torrent_stats stats = {0, 0, 0}; int i; - char *r = reply; iterate_all_torrents(torrent_statter, (uintptr_t)&stats); - r += sprintf(r, "\n"); - r += sprintf(r, "\n"); - r += sprintf(r, " %" PRIu32 "\n", g_tracker_id); - r += sprintf(r, " \n"); - r += stats_return_tracker_version(r); - r += sprintf(r, " \n"); - r += sprintf(r, " %llu\n", (unsigned long long)(time(NULL) - ot_start_time)); - r += sprintf(r, " \n"); - r += sprintf(r, " %zd\n", mutex_get_torrent_count()); - r += sprintf(r, " %llu\n", stats.torrent_count); - r += sprintf(r, " \n"); - r += sprintf(r, " \n %llu\n \n", stats.peer_count); - r += sprintf(r, " \n %llu\n \n", stats.seed_count); - r += sprintf(r, " \n %llu\n \n", ot_overall_completed); - r += sprintf(r, " \n"); - r += sprintf(r, " \n %llu\n %llu\n %llu\n \n", - ot_overall_tcp_connections, ot_overall_tcp_successfulannounces, ot_overall_tcp_successfulscrapes); - r += sprintf(r, " \n %llu\n %llu\n %llu\n %llu\n %llu\n \n", - ot_overall_udp_connections, ot_overall_udp_connects, ot_overall_udp_successfulannounces, ot_overall_udp_successfulscrapes, - ot_overall_udp_connectionidmissmatches); - r += sprintf(r, " \n %llu\n \n", ot_overall_sync_count); - r += sprintf(r, " \n"); - r += sprintf(r, " \n"); - r += sprintf(r, " \n"); + fmt_append(reply, reply_end, "\n"); + fmt_append(reply, reply_end, "\n"); + fmt_append(reply, reply_end, " %" PRIu32 "\n", g_tracker_id); + fmt_append(reply, reply_end, " \n"); + stats_return_tracker_version(reply, reply_end); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " %llu\n", (unsigned long long)(time(NULL) - ot_start_time)); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " %zd\n", mutex_get_torrent_count()); + fmt_append(reply, reply_end, " %llu\n", stats.torrent_count); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " \n %llu\n \n", stats.peer_count); + fmt_append(reply, reply_end, " \n %llu\n \n", stats.seed_count); + fmt_append(reply, reply_end, " \n %llu\n \n", ot_overall_completed); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " \n %llu\n %llu\n %llu\n \n", + ot_overall_tcp_connections, ot_overall_tcp_successfulannounces, ot_overall_tcp_successfulscrapes); + fmt_append(reply, reply_end, " \n %llu\n %llu\n %llu\n %llu\n %llu\n \n", + ot_overall_udp_connections, ot_overall_udp_connects, ot_overall_udp_successfulannounces, ot_overall_udp_successfulscrapes, + ot_overall_udp_connectionidmissmatches); + fmt_append(reply, reply_end, " \n %llu\n \n", ot_overall_sync_count); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " \n"); for (i = 0; i < OT_PEER_TIMEOUT; ++i) - r += sprintf(r, " %llu\n", i, ot_renewed[i]); - r += sprintf(r, " \n"); - r += sprintf(r, " \n"); + fmt_append(reply, reply_end, " %llu\n", i, ot_renewed[i]); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " \n"); for (i = 0; i < CODE_HTTPERROR_COUNT; ++i) - r += sprintf(r, " %llu\n", ot_failed_request_names[i], ot_failed_request_counts[i]); - r += sprintf(r, " \n"); - r += sprintf(r, " \n %llu\n \n", ot_overall_stall_count); - r += sprintf(r, " \n"); - r += sprintf(r, ""); - return r - reply; + fmt_append(reply, reply_end, " %llu\n", ot_failed_request_names[i], ot_failed_request_counts[i]); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, " \n %llu\n \n", ot_overall_stall_count); + fmt_append(reply, reply_end, " \n"); + fmt_append(reply, reply_end, ""); } -size_t stats_return_tracker_version(char *reply) { +void stats_return_tracker_version(char **reply, const char *reply_end) { #define QUOTE(name) #name #define SQUOTE(name) QUOTE(name) - return sprintf(reply, "https://erdgeist.org/gitweb/opentracker/commit/?id=" SQUOTE(GIT_VERSION) "\n"); + fmt_append(reply, reply_end, "https://erdgeist.org/gitweb/opentracker/commit/?id=" SQUOTE(GIT_VERSION) "\n"); } -size_t return_stats_for_tracker(char *reply, int mode, int format) { +void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int format) { (void)format; switch (mode & TASK_TASK_MASK) { case TASK_STATS_CONNS: - return stats_connections_mrtg(reply); + stats_connections_mrtg(reply, reply_end); + break; case TASK_STATS_SCRAPE: - return stats_scrape_mrtg(reply); + stats_scrape_mrtg(reply, reply_end); + break; case TASK_STATS_UDP: - return stats_udpconnections_mrtg(reply); + stats_udpconnections_mrtg(reply, reply_end); + break; case TASK_STATS_TCP: - return stats_tcpconnections_mrtg(reply); + stats_tcpconnections_mrtg(reply, reply_end); + break; case TASK_STATS_FULLSCRAPE: - return stats_fullscrapes_mrtg(reply); + stats_fullscrapes_mrtg(reply, reply_end); + break; case TASK_STATS_COMPLETED: - return stats_return_completed_mrtg(reply); + stats_return_completed_mrtg(reply, reply_end); + break; case TASK_STATS_HTTPERRORS: - return stats_httperrors_txt(reply); + stats_httperrors_txt(reply, reply_end); + break; case TASK_STATS_VERSION: - return stats_return_tracker_version(reply); + stats_return_tracker_version(reply, reply_end); + break; case TASK_STATS_RENEW: - return stats_return_renew_bucket(reply); + stats_return_renew_bucket(reply, reply_end); + break; case TASK_STATS_SYNCS: - return stats_return_sync_mrtg(reply); + stats_return_sync_mrtg(reply, reply_end); + break; #ifdef WANT_LOG_NUMWANT case TASK_STATS_NUMWANTS: - return stats_return_numwants(reply); + stats_return_numwants(reply, reply_end); + break; #endif default: - return 0; + break; } } static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_tasktype mode) { - char *r; + char *r; + const char *r_end; *iovec_entries = 0; *iovector = NULL; if (!(r = iovec_new_chunk(iovec_entries, iovector, OT_STATS_TMPSIZE))) return; + r_end = r + OT_STATS_TMPSIZE; switch (mode & TASK_TASK_MASK) { case TASK_STATS_TORRENTS: - r += stats_torrents_mrtg(r); + stats_torrents_mrtg(&r, r_end); break; case TASK_STATS_PEERS: - r += stats_peers_mrtg(r); + stats_peers_mrtg(&r, r_end); break; case TASK_STATS_SLASH24S: - r += stats_slash24s_txt(r, 128); + stats_slash24s_txt(&r, r_end, 128); break; case TASK_STATS_TOP10: - r += stats_top_txt(r, 10); + stats_top_txt(&r, r_end, 10); break; case TASK_STATS_TOP100: r = iovec_next_chunk(iovec_entries, iovector, r, 4 * OT_STATS_TMPSIZE); if (!r) return; - r += stats_top_txt(r, 100); + r_end = r + 4 * OT_STATS_TMPSIZE; + stats_top_txt(&r, r_end, 100); break; case TASK_STATS_EVERYTHING: r = iovec_next_chunk(iovec_entries, iovector, r, OT_STATS_TMPSIZE + 64 * OT_PEER_TIMEOUT); if (!r) return; - r += stats_return_everything(r); + r_end = r + OT_STATS_TMPSIZE + 64 * OT_PEER_TIMEOUT; + stats_return_everything(&r, r_end); break; #ifdef WANT_SPOT_WOODPECKER case TASK_STATS_WOODPECKERS: - r += stats_return_woodpeckers(r, 128); + stats_return_woodpeckers(&r, r_end, 128); break; #endif #ifdef WANT_FULLLOG_NETWORKS -- cgit v1.3