diff --git a/server/dhcpd.c b/server/dhcpd.c index a42d759..31d6acc 100644 --- a/server/dhcpd.c +++ b/server/dhcpd.c @@ -921,12 +921,9 @@ main(int argc, char **argv) { omapi_set_int_value ((omapi_object_t *)dhcp_control_object, (omapi_object_t *)0, "state", server_running); -#if defined(ENABLE_GENTLE_SHUTDOWN) - /* no signal handlers until we deal with the side effects */ - /* install signal handlers */ signal(SIGINT, dhcp_signal_handler); /* control-c */ - signal(SIGTERM, dhcp_signal_handler); /* kill */ -#endif + signal(SIGTERM, dhcp_signal_handler); /* term, fast shutdown */ + signal(SIGUSR2, dhcp_signal_handler); /* perform recovery */ /* Log that we are about to start working */ log_info("Server starting service."); @@ -1402,6 +1399,9 @@ int dhcpd_interface_setup_hook (struct interface_info *ip, struct iaddr *ia) static TIME shutdown_time; static int omapi_connection_count; enum dhcp_shutdown_state shutdown_state; +#if defined (FAILOVER_PROTOCOL) +static isc_boolean_t shutdown_do_recovery_on_startup; +#endif isc_result_t dhcp_io_shutdown (omapi_object_t *obj, void *foo) { @@ -1481,38 +1481,31 @@ static isc_result_t dhcp_io_shutdown_countdown (void *vlp) } #if defined (FAILOVER_PROTOCOL) - /* Set all failover peers into the shutdown state. */ - if (shutdown_state == shutdown_dhcp) { - for (state = failover_states; state; state = state -> next) { - if (state -> me.state == normal) { - dhcp_failover_set_state (state, shut_down); - failover_connection_count++; - } - if (state -> me.state == shut_down && - state -> partner.state != partner_down) - failover_connection_count++; + if (shutdown_do_recovery_on_startup == ISC_TRUE) { + /* Set all failover peers into the shutdown state. */ + if (shutdown_state == shutdown_dhcp) { + for (state = failover_states; state; state = state -> next) { + if (state -> me.state == normal) { + dhcp_failover_set_state (state, shut_down); + failover_connection_count++; + } + if (state -> me.state == shut_down && + state -> partner.state != partner_down) + failover_connection_count++; + } } - } - - if (shutdown_state == shutdown_done) { - for (state = failover_states; state; state = state -> next) { - if (state -> me.state == shut_down) { - if (state -> link_to_peer) - dhcp_failover_link_dereference (&state -> link_to_peer, - MDL); - dhcp_failover_set_state (state, recover); - } + if (shutdown_state == shutdown_done) { + for (state = failover_states; state; state = state -> next) { + if (state -> me.state == shut_down) { + if (state -> link_to_peer) + dhcp_failover_link_dereference (&state -> link_to_peer, + MDL); + dhcp_failover_set_state (state, recover); + } + } } -#if defined (DEBUG_MEMORY_LEAKAGE) && \ - defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) - free_everything (); - omapi_print_dmalloc_usage_by_caller (); + } #endif - if (no_pid_file == ISC_FALSE) - (void) unlink(path_dhcpd_pid); - exit (0); - } -#else if (shutdown_state == shutdown_done) { #if defined (DEBUG_MEMORY_LEAKAGE) && \ defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) @@ -1523,7 +1516,6 @@ static isc_result_t dhcp_io_shutdown_countdown (void *vlp) (void) unlink(path_dhcpd_pid); exit (0); } -#endif if (shutdown_state == shutdown_dhcp && #if defined(FAILOVER_PROTOCOL) !failover_connection_count && @@ -1552,14 +1544,25 @@ isc_result_t dhcp_set_control_state (control_object_state_t oldstate, return ISC_R_SUCCESS; shutdown_time = cur_time; shutdown_state = shutdown_listeners; +#if defined (FAILOVER_PROTOCOL) + shutdown_do_recovery_on_startup = ISC_FALSE; +#endif /* Called by user. */ if (shutdown_signal == 0) { shutdown_signal = SIGUSR1; +#if defined (FAILOVER_PROTOCOL) + shutdown_do_recovery_on_startup = ISC_TRUE; +#endif dhcp_io_shutdown_countdown (0); return ISC_R_SUCCESS; } /* Called on signal. */ log_info("Received signal %d, initiating shutdown.", shutdown_signal); +#if defined (FAILOVER_PROTOCOL) + if (shutdown_signal == SIGUSR2) { + shutdown_do_recovery_on_startup = ISC_TRUE; + } +#endif shutdown_signal = SIGUSR1; /*