diff options
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/opentracker.c b/opentracker.c index c36ceaa..f715424 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -65,6 +65,32 @@ static void signal_handler( int s ) { | |||
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | static void defaul_signal_handlers( void ) { | ||
69 | sigset_t signal_mask; | ||
70 | sigemptyset(&signal_mask); | ||
71 | sigaddset (&signal_mask, SIGPIPE); | ||
72 | sigaddset (&signal_mask, SIGHUP); | ||
73 | sigaddset (&signal_mask, SIGINT); | ||
74 | sigaddset (&signal_mask, SIGALRM); | ||
75 | pthread_sigmask (SIG_BLOCK, &signal_mask, NULL); | ||
76 | } | ||
77 | |||
78 | static void install_signal_handlers( void ) { | ||
79 | struct sigaction sa; | ||
80 | sigset_t signal_mask; | ||
81 | sigemptyset(&signal_mask); | ||
82 | |||
83 | sa.sa_handler = signal_handler; | ||
84 | sigemptyset(&sa.sa_mask); | ||
85 | sa.sa_flags = SA_RESTART; | ||
86 | if ((sigaction(SIGINT, &sa, NULL) == -1) || (sigaction(SIGALRM, &sa, NULL) == -1) ) | ||
87 | panic( "install_signal_handlers" ); | ||
88 | |||
89 | sigaddset (&signal_mask, SIGINT); | ||
90 | sigaddset (&signal_mask, SIGALRM); | ||
91 | pthread_sigmask (SIG_UNBLOCK, &signal_mask, NULL); | ||
92 | } | ||
93 | |||
68 | static void usage( char *name ) { | 94 | static void usage( char *name ) { |
69 | fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-r redirect] [-d dir] [-A ip] [-f config] [-s livesyncport]" | 95 | fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-r redirect] [-d dir] [-A ip] [-f config] [-s livesyncport]" |
70 | #ifdef WANT_ACCESSLIST_BLACK | 96 | #ifdef WANT_ACCESSLIST_BLACK |
@@ -254,12 +280,14 @@ static int64_t ot_try_bind( ot_ip6 ip, uint16_t port, PROTO_FLAG proto ) { | |||
254 | #endif | 280 | #endif |
255 | 281 | ||
256 | #ifdef _DEBUG | 282 | #ifdef _DEBUG |
283 | { | ||
257 | char *protos[] = {"TCP","UDP","UDP mcast"}; | 284 | char *protos[] = {"TCP","UDP","UDP mcast"}; |
258 | char _debug[512]; | 285 | char _debug[512]; |
259 | int off = snprintf( _debug, sizeof(_debug), "Binding socket type %s to address [", protos[proto] ); | 286 | int off = snprintf( _debug, sizeof(_debug), "Binding socket type %s to address [", protos[proto] ); |
260 | off += fmt_ip6c( _debug+off, ip); | 287 | off += fmt_ip6c( _debug+off, ip); |
261 | snprintf( _debug + off, sizeof(_debug)-off, "]:%d...", port); | 288 | snprintf( _debug + off, sizeof(_debug)-off, "]:%d...", port); |
262 | fputs( _debug, stderr ); | 289 | fputs( _debug, stderr ); |
290 | } | ||
263 | #endif | 291 | #endif |
264 | 292 | ||
265 | if( socket_bind6_reuse( sock, ip, port, 0 ) == -1 ) | 293 | if( socket_bind6_reuse( sock, ip, port, 0 ) == -1 ) |
@@ -483,7 +511,7 @@ int main( int argc, char **argv ) { | |||
483 | noipv6=1; | 511 | noipv6=1; |
484 | #endif | 512 | #endif |
485 | 513 | ||
486 | while( scanon ) { | 514 | while( scanon ) { |
487 | switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:l:v" | 515 | switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:l:v" |
488 | #ifdef WANT_ACCESSLIST_BLACK | 516 | #ifdef WANT_ACCESSLIST_BLACK |
489 | "b:" | 517 | "b:" |
@@ -540,10 +568,6 @@ while( scanon ) { | |||
540 | if( drop_privileges( g_serverdir ? g_serverdir : "." ) == -1 ) | 568 | if( drop_privileges( g_serverdir ? g_serverdir : "." ) == -1 ) |
541 | panic( "drop_privileges failed, exiting. Last error"); | 569 | panic( "drop_privileges failed, exiting. Last error"); |
542 | 570 | ||
543 | signal( SIGPIPE, SIG_IGN ); | ||
544 | signal( SIGINT, signal_handler ); | ||
545 | signal( SIGALRM, signal_handler ); | ||
546 | |||
547 | g_now_seconds = time( NULL ); | 571 | g_now_seconds = time( NULL ); |
548 | 572 | ||
549 | /* Create our self pipe which allows us to interrupt mainloops | 573 | /* Create our self pipe which allows us to interrupt mainloops |
@@ -555,8 +579,10 @@ while( scanon ) { | |||
555 | io_setcookie( g_self_pipe[0], (void*)FLAG_SELFPIPE ); | 579 | io_setcookie( g_self_pipe[0], (void*)FLAG_SELFPIPE ); |
556 | io_wantread( g_self_pipe[0] ); | 580 | io_wantread( g_self_pipe[0] ); |
557 | 581 | ||
582 | defaul_signal_handlers( ); | ||
558 | /* Init all sub systems. This call may fail with an exit() */ | 583 | /* Init all sub systems. This call may fail with an exit() */ |
559 | trackerlogic_init( ); | 584 | trackerlogic_init( ); |
585 | install_signal_handlers( ); | ||
560 | 586 | ||
561 | /* Kick off our initial clock setting alarm */ | 587 | /* Kick off our initial clock setting alarm */ |
562 | alarm(5); | 588 | alarm(5); |