From aafd6488afb58b427c92973d50caddc291f07263 Mon Sep 17 00:00:00 2001 From: Josh Elsasser Date: Fri, 17 Aug 2007 03:57:26 +0000 Subject: [PATCH] Shut down ipc server on fatal signal, not just torrent client. --- daemon/daemon.c | 2 +- daemon/server.c | 26 ++++++++++++++++---------- daemon/server.h | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/daemon/daemon.c b/daemon/daemon.c index 633688921..22ec2ae68 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -344,7 +344,7 @@ gotsig( int sig, short what UNUSED, void * arg UNUSED ) { exiting = 1; errmsg( "received fatal signal %i, attempting to exit cleanly", sig ); - torrent_exit( 0 ); + server_quit(); } else { diff --git a/daemon/server.c b/daemon/server.c index f323aa102..d11bec178 100644 --- a/daemon/server.c +++ b/daemon/server.c @@ -185,6 +185,21 @@ server_listen( int fd ) return 0; } +void +server_quit( void ) +{ + struct client * ii, * next; + + torrent_exit( 0 ); + gl_exiting = 1; + + for( ii = RB_MIN( allclients, &gl_clients ); NULL != ii; ii = next ) + { + next = RB_NEXT( allclients, &gl_clients, ii ); + byebye( ii->ev, EVBUFFER_EOF, NULL ); + } +} + void newclient( int fd, short event UNUSED, void * arg ) { @@ -560,16 +575,7 @@ void quitmsg( enum ipc_msg id UNUSED, benc_val_t * val UNUSED, int64_t tag UNUSED, void * arg UNUSED ) { - struct client * ii, * next; - - torrent_exit( 0 ); - gl_exiting = 1; - - for( ii = RB_MIN( allclients, &gl_clients ); NULL != ii; ii = next ) - { - next = RB_NEXT( allclients, &gl_clients, ii ); - byebye( ii->ev, EVBUFFER_EOF, NULL ); - } + server_quit(); } void diff --git a/daemon/server.h b/daemon/server.h index 0921e50cf..1cfa47532 100644 --- a/daemon/server.h +++ b/daemon/server.h @@ -30,5 +30,6 @@ struct event_base; int server_init( struct event_base * ); void server_debug( int ); int server_listen( int ); +void server_quit( void ); #endif /* TR_DAEMON_SERVER_H */