cancel_timeout?
Ted Lemon
Ted_Lemon at isc.org
Fri Sep 24 15:27:41 UTC 1999
> Since they can be called at any time, I want the dhclient to drop
> anything it's currently doing and let my functions execute and take it
> to the following state. Will this require me to cancel _everything_
> that is done before doing what I want?
You need to cancel all outstanding timeouts that are active for a
given state machine (usually, there's only one, though) so that you
won't accidentally make a bogus state transition when the timeout goes
off.
> for (ip = interfaces; ip; ip = ip -> next) {
> if (strcmp(ip -> name,"eth0") == 0) {
> sp = ip -> client;
> sp -> state = S_INIT;
> state_init (sp);
> return 1; }}
> return 0;
I would say that you probably need to be prepared to cancel some
timeouts here. Unfortunately, the code isn't really structured to
make this easy... :'(
> case S_REBOOTING:
> cancel_timeout (send_request, ip); /* added by me */
> case S_REQUESTING:
> cancel_timeout (send_request, ip); /* added by me */
> case S_RENEWING:
> cancel_timeout (send_request, ip);
> break;
Why'd you add the two extra cancel_timeout() calls? They do the same
thing. For S_REBOOTING, you'll cancel the timeout three times, and
you'll cancel it twice for S_REQUESTING. The statements as they were,
because of the way C switch statements work, would have canceled the
timeout exactly once if you were in any of the three states covered by
the three case statements. Remember that after a case statement, all
code is executed up to a break statement or the end of the switch
statement - a subsequent case statement does _not_ change the flow of
control following a preceding case statement.
> Is this switch ok, and should I use it in the discover_addr too?
It may be okay (modulo my comments above) - I'm not sure. I'm afraid
that I don't have the client in my head right now - I've been hacking
almost exclusively on the server recently. If you've come to the
conclusion that you've got it right, I'd say go with it, and see what
happens, but be aware that if you haven't got it quite right, you may
need to do some debugging.
_MelloN_
More information about the dhcp-hackers
mailing list