summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2009-11-12 10:18:27 +0000
committererdgeist <>2009-11-12 10:18:27 +0000
commitf4409df68abe9a27686a157ffa8da33603fc91ad (patch)
tree6c99371a0fe2e12230c9c22bd263367251877762
parentb1bf030f922685b2613c7826fac306b6c2a82552 (diff)
Allow logging of completed events to syslog
-rw-r--r--Makefile1
-rw-r--r--ot_stats.c17
-rw-r--r--trackerlogic.c2
3 files changed, 19 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 8e7fc87..acfe669 100644
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,7 @@ BINDIR?=$(PREFIX)/bin
35#FEATURES+=-DWANT_LOG_NUMWANT 35#FEATURES+=-DWANT_LOG_NUMWANT
36#FEATURES+=-DWANT_MODEST_FULLSCRAPES 36#FEATURES+=-DWANT_MODEST_FULLSCRAPES
37#FEATURES+=-DWANT_SPOT_WOODPECKER 37#FEATURES+=-DWANT_SPOT_WOODPECKER
38#FEATURES+=-DWANT_SYSLOGS
38FEATURES+=-DWANT_FULLSCRAPE 39FEATURES+=-DWANT_FULLSCRAPE
39 40
40#FEATURES+=-D_DEBUG_HTTPERROR 41#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 @@
14#include <pthread.h> 14#include <pthread.h>
15#include <unistd.h> 15#include <unistd.h>
16#include <inttypes.h> 16#include <inttypes.h>
17#ifdef WANT_SYSLOGS
18#include <syslog.h>
19#endif
17 20
18/* Libowfat */ 21/* Libowfat */
19#include "byte.h" 22#include "byte.h"
@@ -637,6 +640,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
637 if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++; 640 if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++;
638 break; 641 break;
639 case EVENT_COMPLETED: 642 case EVENT_COMPLETED:
643#ifdef WANT_SYSLOGS
644 if( event_data) {
645 char hex_out[42];
646 to_hex( hex_out, (uint8_t*)event_data );
647 syslog( LOG_INFO, "event=completed info_hash=%s", hex_out );
648 }
649#endif
640 ot_overall_completed++; 650 ot_overall_completed++;
641 break; 651 break;
642 case EVENT_SCRAPE: 652 case EVENT_SCRAPE:
@@ -715,10 +725,17 @@ static pthread_t thread_id;
715void stats_init( ) { 725void stats_init( ) {
716 ot_start_time = g_now_seconds; 726 ot_start_time = g_now_seconds;
717 pthread_create( &thread_id, NULL, stats_worker, NULL ); 727 pthread_create( &thread_id, NULL, stats_worker, NULL );
728#ifdef WANT_SYSLOGS
729 openlog( "opentracker", 0, LOG_USER );
730 setlogmask(LOG_UPTO(LOG_INFO));
731#endif
718} 732}
719 733
720void stats_deinit( ) { 734void stats_deinit( ) {
721 pthread_cancel( thread_id ); 735 pthread_cancel( thread_id );
736#ifdef WANT_SYSLOGS
737 closelog();
738#endif
722} 739}
723 740
724const char *g_version_stats_c = "$Source$: $Revision$\n"; 741const 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_
138 torrent->peer_list->peer_count++; 138 torrent->peer_list->peer_count++;
139 if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) { 139 if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) {
140 torrent->peer_list->down_count++; 140 torrent->peer_list->down_count++;
141 stats_issue_event( EVENT_COMPLETED, 0, 0 ); 141 stats_issue_event( EVENT_COMPLETED, 0, (uintptr_t)torrent->hash );
142 } 142 }
143 if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING ) 143 if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING )
144 torrent->peer_list->seed_count++; 144 torrent->peer_list->seed_count++;