From f4409df68abe9a27686a157ffa8da33603fc91ad Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Thu, 12 Nov 2009 10:18:27 +0000 Subject: [PATCH] Allow logging of completed events to syslog --- Makefile | 1 + ot_stats.c | 17 +++++++++++++++++ trackerlogic.c | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8e7fc87..acfe669 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ BINDIR?=$(PREFIX)/bin #FEATURES+=-DWANT_LOG_NUMWANT #FEATURES+=-DWANT_MODEST_FULLSCRAPES #FEATURES+=-DWANT_SPOT_WOODPECKER +#FEATURES+=-DWANT_SYSLOGS FEATURES+=-DWANT_FULLSCRAPE #FEATURES+=-D_DEBUG_HTTPERROR diff --git a/ot_stats.c b/ot_stats.c index 4f6b620..a976713 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -14,6 +14,9 @@ #include #include #include +#ifdef WANT_SYSLOGS +#include +#endif /* Libowfat */ #include "byte.h" @@ -637,6 +640,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++; break; case EVENT_COMPLETED: +#ifdef WANT_SYSLOGS + if( event_data) { + char hex_out[42]; + to_hex( hex_out, (uint8_t*)event_data ); + syslog( LOG_INFO, "event=completed info_hash=%s", hex_out ); + } +#endif ot_overall_completed++; break; case EVENT_SCRAPE: @@ -715,10 +725,17 @@ static pthread_t thread_id; void stats_init( ) { ot_start_time = g_now_seconds; pthread_create( &thread_id, NULL, stats_worker, NULL ); +#ifdef WANT_SYSLOGS + openlog( "opentracker", 0, LOG_USER ); + setlogmask(LOG_UPTO(LOG_INFO)); +#endif } void stats_deinit( ) { pthread_cancel( thread_id ); +#ifdef WANT_SYSLOGS + closelog(); +#endif } const char *g_version_stats_c = "$Source$: $Revision$\n"; diff --git a/trackerlogic.c b/trackerlogic.c index 6ca1ad2..f70dd94 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -138,7 +138,7 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_ torrent->peer_list->peer_count++; if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) { torrent->peer_list->down_count++; - stats_issue_event( EVENT_COMPLETED, 0, 0 ); + stats_issue_event( EVENT_COMPLETED, 0, (uintptr_t)torrent->hash ); } if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING ) torrent->peer_list->seed_count++;