diff options
author | axel <axel@liljencrantz.se> | 2005-11-28 09:24:09 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2005-11-28 09:24:09 +1000 |
commit | 6bf58e44f44d59fcb5d7c9aefa206fa96dbcaea2 (patch) | |
tree | cdd1f02f2a0d00c06fff0d04e7bab29fb1b79969 /fishd.c | |
parent | bda7948719555dd7745a416d79aa7e21a252fbdb (diff) |
Make sure fishd saves before exiting from signal
darcs-hash:20051127232409-ac50b-d316781e373c078fecf857a199594a00184361a9.gz
Diffstat (limited to 'fishd.c')
-rw-r--r-- | fishd.c | 49 |
1 files changed, 42 insertions, 7 deletions
@@ -71,6 +71,11 @@ static connection_t *conn; static int sock; /** + Set to one when fishd should save and exit +*/ +static int quit=0; + +/** Constructs the fish socket filename */ static char *get_socket_filename() @@ -111,6 +116,15 @@ static char *get_socket_filename() } /** + Signal handler for the term signal. +*/ +static void handle_term( int signal ) +{ + quit=1; +} + + +/** Acquire the lock for the socket Returns the name of the lock file if successful or NULL if unable to obtain lock. @@ -276,6 +290,14 @@ static void daemonize() act.sa_flags=0; act.sa_handler=SIG_IGN; sigaction( SIGHUP, &act, 0); + + /* + Make fishd save and exit on the TERM signal. + */ + sigfillset( & act.sa_mask ); + act.sa_flags=0; + act.sa_handler=&handle_term; + sigaction( SIGTERM, &act, 0); break; } @@ -389,8 +411,9 @@ static void init() */ int main( int argc, char ** argv ) { - int child_socket, t; + int child_socket; struct sockaddr_un remote; + socklen_t t; int max_fd; int update_count=0; @@ -419,13 +442,25 @@ int main( int argc, char ** argv ) FD_SET( c->fd, &write_fd ); } } - - res=select( max_fd, &read_fd, &write_fd, 0, 0 ); - - if( res==-1 ) + + while( 1 ) { - wperror( L"select" ); - exit(1); + res=select( max_fd, &read_fd, &write_fd, 0, 0 ); + + if( quit ) + { + save(); + exit(0); + } + + if( res != -1 ) + break; + + if( errno != EINTR ) + { + wperror( L"select" ); + exit(1); + } } if( FD_ISSET( sock, &read_fd ) ) |