diff options
author | erdgeist <> | 2009-11-12 10:18:27 +0000 |
---|---|---|
committer | erdgeist <> | 2009-11-12 10:18:27 +0000 |
commit | f4409df68abe9a27686a157ffa8da33603fc91ad (patch) | |
tree | 6c99371a0fe2e12230c9c22bd263367251877762 | |
parent | b1bf030f922685b2613c7826fac306b6c2a82552 (diff) |
Allow logging of completed events to syslog
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | ot_stats.c | 17 | ||||
-rw-r--r-- | trackerlogic.c | 2 |
3 files changed, 19 insertions, 1 deletions
@@ -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 | ||
38 | FEATURES+=-DWANT_FULLSCRAPE | 39 | FEATURES+=-DWANT_FULLSCRAPE |
39 | 40 | ||
40 | #FEATURES+=-D_DEBUG_HTTPERROR | 41 | #FEATURES+=-D_DEBUG_HTTPERROR |
@@ -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; | |||
715 | void stats_init( ) { | 725 | void 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 | ||
720 | void stats_deinit( ) { | 734 | void stats_deinit( ) { |
721 | pthread_cancel( thread_id ); | 735 | pthread_cancel( thread_id ); |
736 | #ifdef WANT_SYSLOGS | ||
737 | closelog(); | ||
738 | #endif | ||
722 | } | 739 | } |
723 | 740 | ||
724 | const char *g_version_stats_c = "$Source$: $Revision$\n"; | 741 | 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_ | |||
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++; |