diff options
-rw-r--r-- | opentracker.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/opentracker.c b/opentracker.c index 2108a98..7c67f26 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -70,10 +70,6 @@ static void signal_handler( int s ) { | |||
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | exit( 0 ); | 72 | exit( 0 ); |
73 | } else if( s == SIGALRM ) { | ||
74 | /* Maintain our copy of the clock. time() on BSDs is very expensive. */ | ||
75 | g_now_seconds = time(NULL); | ||
76 | alarm(5); | ||
77 | } | 73 | } |
78 | } | 74 | } |
79 | 75 | ||
@@ -83,7 +79,6 @@ static void defaul_signal_handlers( void ) { | |||
83 | sigaddset (&signal_mask, SIGPIPE); | 79 | sigaddset (&signal_mask, SIGPIPE); |
84 | sigaddset (&signal_mask, SIGHUP); | 80 | sigaddset (&signal_mask, SIGHUP); |
85 | sigaddset (&signal_mask, SIGINT); | 81 | sigaddset (&signal_mask, SIGINT); |
86 | sigaddset (&signal_mask, SIGALRM); | ||
87 | pthread_sigmask (SIG_BLOCK, &signal_mask, NULL); | 82 | pthread_sigmask (SIG_BLOCK, &signal_mask, NULL); |
88 | } | 83 | } |
89 | 84 | ||
@@ -95,11 +90,10 @@ static void install_signal_handlers( void ) { | |||
95 | sa.sa_handler = signal_handler; | 90 | sa.sa_handler = signal_handler; |
96 | sigemptyset(&sa.sa_mask); | 91 | sigemptyset(&sa.sa_mask); |
97 | sa.sa_flags = SA_RESTART; | 92 | sa.sa_flags = SA_RESTART; |
98 | if ((sigaction(SIGINT, &sa, NULL) == -1) || (sigaction(SIGALRM, &sa, NULL) == -1) ) | 93 | if ((sigaction(SIGINT, &sa, NULL) == -1)) |
99 | panic( "install_signal_handlers" ); | 94 | panic( "install_signal_handlers" ); |
100 | 95 | ||
101 | sigaddset (&signal_mask, SIGINT); | 96 | sigaddset (&signal_mask, SIGINT); |
102 | sigaddset (&signal_mask, SIGALRM); | ||
103 | pthread_sigmask (SIG_UNBLOCK, &signal_mask, NULL); | 97 | pthread_sigmask (SIG_UNBLOCK, &signal_mask, NULL); |
104 | } | 98 | } |
105 | 99 | ||
@@ -608,12 +602,22 @@ int drop_privileges ( const char * const serveruser, const char * const serverdi | |||
608 | return 0; | 602 | return 0; |
609 | } | 603 | } |
610 | 604 | ||
605 | /* Maintain our copy of the clock. time() on BSDs is very expensive. */ | ||
606 | static void *time_caching_worker(void*args) { | ||
607 | (void)args; | ||
608 | while (1) { | ||
609 | g_now_seconds = time(NULL); | ||
610 | sleep(5); | ||
611 | } | ||
612 | } | ||
613 | |||
611 | int main( int argc, char **argv ) { | 614 | int main( int argc, char **argv ) { |
612 | ot_ip6 serverip; | 615 | ot_ip6 serverip; |
613 | ot_net tmpnet; | 616 | ot_net tmpnet; |
614 | int bound = 0, scanon = 1; | 617 | int bound = 0, scanon = 1; |
615 | uint16_t tmpport; | 618 | uint16_t tmpport; |
616 | char * statefile = 0; | 619 | char * statefile = 0; |
620 | pthread_t thread_id; /* time cacher */ | ||
617 | 621 | ||
618 | memset( serverip, 0, sizeof(ot_ip6) ); | 622 | memset( serverip, 0, sizeof(ot_ip6) ); |
619 | #ifdef WANT_V4_ONLY | 623 | #ifdef WANT_V4_ONLY |
@@ -690,6 +694,7 @@ int main( int argc, char **argv ) { | |||
690 | panic( "drop_privileges failed, exiting. Last error"); | 694 | panic( "drop_privileges failed, exiting. Last error"); |
691 | 695 | ||
692 | g_now_seconds = time( NULL ); | 696 | g_now_seconds = time( NULL ); |
697 | pthread_create( &thread_id, NULL, time_caching_worker, NULL); | ||
693 | 698 | ||
694 | /* Create our self pipe which allows us to interrupt mainloops | 699 | /* Create our self pipe which allows us to interrupt mainloops |
695 | io_wait in case some data is available to send out */ | 700 | io_wait in case some data is available to send out */ |
@@ -714,9 +719,6 @@ int main( int argc, char **argv ) { | |||
714 | if( !g_udp_workers ) | 719 | if( !g_udp_workers ) |
715 | udp_init( -1, 0 ); | 720 | udp_init( -1, 0 ); |
716 | 721 | ||
717 | /* Kick off our initial clock setting alarm */ | ||
718 | alarm(5); | ||
719 | |||
720 | server_mainloop( 0 ); | 722 | server_mainloop( 0 ); |
721 | 723 | ||
722 | return 0; | 724 | return 0; |