[dhcp-agent-commits] dhcp-agent/src dhcp-client-states.c,1.14,1.15 dhcp-client.c,1.11,1.12 dhcp-inte
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-12-19 17:20:39
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv17707 Modified Files: dhcp-client-states.c dhcp-client.c dhcp-interrupt.c dhcp-libutil.h dhcp-timer.c Log Message: fixed bug in alarm/hup handling Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client-states.c 19 Dec 2002 06:50:59 -0000 1.14 --- dhcp-client-states.c 19 Dec 2002 17:20:36 -0000 1.15 *************** *** 317,321 **** } ! time_t compensate_timeout_with_timer(dhcp_client_control_t *dc) { uint32_t next_timer; --- 317,321 ---- } ! static time_t compensate_timeout_with_timer(dhcp_client_control_t *dc) { uint32_t next_timer; *************** *** 590,593 **** --- 590,596 ---- int client_wait(dhcp_client_control_t *dc) { + uint32_t next_timer; + time_t time_before, time_after, time_interval; + INFO_MESSAGE("entering wait stage"); *************** *** 595,600 **** rawnet_down(dc->rawnet); ! /* Ask our internal timer to setup our next alarm: this is ! * for rebind, renewal, and expiry in that order. */ if(timer_set_next(dc->timer)) { --- 598,607 ---- rawnet_down(dc->rawnet); ! /* peek and store our next timer in case we get an interrupt ! * which is not a timer interrupt. */ ! ! next_timer = timer_peek_next_timer(dc->timer); ! ! time_before = time(NULL); if(timer_set_next(dc->timer)) { *************** *** 606,609 **** --- 613,646 ---- suspend_for_interrupts(); + /* at this point we may or may not have received a timer + * interrupt. if we have not then setup a timer to go off + * once we return by storing a new timer with the time + * difference. */ + + time_after = time(NULL); + + time_interval = time_after - time_before; /* number of seconds elapsed. */ + + if(peek_interrupt_type() != INTERRUPT_ALARM) { + + if(time_interval < 0) { + /* someone has been b0rking the system clock. */ + WARN_MESSAGE("the system clock is skewed or you've been messing with it. i'm going to just use the next timer and hope for the best."); + } else { + + + /* we did not receive a timer interrupt. + * put the difference as the next timer to go off. */ + + next_timer -= time_interval; /* this is safe since we're promoting the type + * and it can never be < 0 */ + + if(next_timer == 0) + next_timer = 1; /* give at least one second. */ + + timer_add_trigger(dc->timer, next_timer, timer_get_current_id(dc->timer)); + } + } + /* bring the raw network devices back up. we'll probably * need them: FIXME, revamp into one network module that uses Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client.c 19 Dec 2002 06:50:59 -0000 1.11 --- dhcp-client.c 19 Dec 2002 17:20:36 -0000 1.12 *************** *** 204,252 **** * Handle any interrupts here. */ ! check_for_interrupts(); ! switch (got_interrupt_type()) { ! case INTERRUPT_NONE: ! break; ! case INTERRUPT_TERM: ! state = STATE_DO_SHUTDOWN; ! break; ! case INTERRUPT_HUP: ! /* re-read configuration. */ ! INFO_MESSAGE("re-reading configuration"); ! if(client_conf_reread(dc->conf)) { ! WARN_MESSAGE("could not read configuration. using previous configuration."); ! } ! break; ! case INTERRUPT_ALARM: ! switch (timer_get_current_id(dc->timer)) { ! case TIMER_RENEW: ! state = STATE_RENEW; ! break; ! case TIMER_IP_LEASE: ! state = STATE_DISCOVER_OFFER; ! break; ! case TIMER_REBIND: ! state = STATE_REBIND; break; default: ! FATAL_MESSAGE("invalid timer type caught. this is a bug. report me."); } - break; - - default: - FATAL_MESSAGE("invalid interrupt type caught. this is a bug. report me."); } --- 204,253 ---- * Handle any interrupts here. */ ! while(check_for_interrupts()) { ! switch (got_interrupt_type()) { ! case INTERRUPT_NONE: ! break; ! case INTERRUPT_TERM: ! state = STATE_DO_SHUTDOWN; ! break; ! case INTERRUPT_HUP: ! /* re-read configuration. */ ! INFO_MESSAGE("re-reading configuration"); ! if(client_conf_reread(dc->conf)) { ! WARN_MESSAGE("could not read configuration. using previous configuration."); ! } ! break; ! case INTERRUPT_ALARM: ! switch (timer_get_current_id(dc->timer)) { ! case TIMER_RENEW: ! state = STATE_RENEW; ! break; ! case TIMER_IP_LEASE: ! state = STATE_DISCOVER_OFFER; ! break; ! case TIMER_REBIND: ! state = STATE_REBIND; ! break; ! ! default: ! FATAL_MESSAGE("invalid timer type caught. this is a bug. report me."); ! } break; default: ! FATAL_MESSAGE("invalid interrupt type caught. this is a bug. report me."); } } Index: dhcp-interrupt.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interrupt.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-interrupt.c 16 Nov 2002 00:23:43 -0000 1.2 --- dhcp-interrupt.c 19 Dec 2002 17:20:36 -0000 1.3 *************** *** 69,72 **** --- 69,86 ---- } + int peek_interrupt_type(void) + { + if(have_alarm) + return INTERRUPT_ALARM; + + if(have_hup) + return INTERRUPT_HUP; + + if(have_shutdown) + return INTERRUPT_TERM; + + return INTERRUPT_NONE; + } + /* check which variables ere setup and return. * clear before returning. */ *************** *** 160,164 **** sigprocmask(SIG_SETMASK, &o_mask, NULL); ! return 0; } --- 174,181 ---- sigprocmask(SIG_SETMASK, &o_mask, NULL); ! if(have_shutdown || have_alarm || have_hup) ! return 1; ! else ! return 0; } Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-libutil.h 19 Dec 2002 03:11:45 -0000 1.12 --- dhcp-libutil.h 19 Dec 2002 17:20:36 -0000 1.13 *************** *** 153,156 **** --- 153,157 ---- extern void add_interrupt_handler(int sigtype, void (*sighandler) (int)); extern void remove_interrupt(int sig); + extern int peek_interrupt_type(void); /* alarm handlers. */ Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-timer.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-timer.c 24 Nov 2002 01:12:12 -0000 1.6 --- dhcp-timer.c 19 Dec 2002 17:20:36 -0000 1.7 *************** *** 34,38 **** #include "dhcp-libutil.h" ! /* compare triggers by returning shortest time as highest. */ static int compare_triggers_shortest(void *trigger1_p, void *trigger2_p) { --- 34,38 ---- #include "dhcp-libutil.h" ! /* compare triggers by returning smallest id as highest. */ static int compare_triggers_shortest(void *trigger1_p, void *trigger2_p) { *************** *** 42,49 **** trigger2 = trigger2_p; ! if(trigger1->seconds > trigger2->seconds) return 1; ! if(trigger1->seconds < trigger2->seconds) return -1; --- 42,49 ---- trigger2 = trigger2_p; ! if(trigger1->id < trigger2->id) return 1; ! if(trigger1->id > trigger2->id) return -1; |