[Dhcp-agent-commits] dhcp-agent dhcp-client-states.c,1.28,1.29 dhcp-util.c,1.16,1.17 dhcp-util.h,1.3
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-06-19 00:40:16
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv14327 Modified Files: dhcp-client-states.c dhcp-util.c dhcp-util.h Log Message: updated dhcp-util.c for BSD SIGIO support on bpf device Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** dhcp-client-states.c 18 Jun 2002 04:33:40 -0000 1.28 --- dhcp-client-states.c 19 Jun 2002 00:40:12 -0000 1.29 *************** *** 31,54 **** #include <dhcp-globconf.h> - /* alarm handling routine and variable. */ - - /* wrap for volatine integers, or proper sig_atomic_t types. */ - - #ifdef HAVE_SIG_ATOMIC_T - - static sig_atomic_t have_alarm = 0; - - #else /* HAVE_SIG_ATOMIC_T */ - - static int have_alarm = 0; - - #endif - - static RETSIGTYPE handle_alarm(int i) - { - have_alarm = 1; - return (RETSIGTYPE) 0; - } - /* Along with the parameter request list we always build these options * upon creating new dhcp packets. */ --- 31,34 ---- *************** *** 302,305 **** --- 282,286 ---- int client_wait(dhcp_client_control_t *dc) { + struct timeval alarm_time; /* * setup signal based on renewal time *************** *** 310,324 **** * FIXME: (check RFC compliance) */ - - add_interrupt_handler(SIGALRM, handle_alarm); rawnet_down(dc->rawnet); ! alarm(dc->renewal_time); ! suspend_for_interrupts(); /* if we got a shutdown or HUP it will be caught later. */ ! if(have_alarm) { ! have_alarm = 0; ! } ! rawnet_up(dc->rawnet); --- 291,308 ---- * FIXME: (check RFC compliance) */ rawnet_down(dc->rawnet); ! while(1) { ! alarm_time.tv_sec = dc->renewal_time; ! alarm_time.tv_usec = 0; ! ! set_alarm(alarm_time); ! ! suspend_for_interrupts(); /* if we got a shutdown or HUP it will be caught later. */ ! if(had_alarm()) ! break; /* FIXME: decrement timer. */ ! } ! rawnet_up(dc->rawnet); Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-util.c 17 Jun 2002 13:23:08 -0000 1.16 --- dhcp-util.c 19 Jun 2002 00:40:12 -0000 1.17 *************** *** 225,229 **** fatal_error("could not set signal handler for: %d", sigtype); - return; } --- 225,228 ---- *************** *** 480,481 **** --- 479,560 ---- #endif /* HAVE_GETPROGNAME */ + + /* alarm handling routine and variable. */ + + /* wrap for volatine integers, or proper sig_atomic_t types. */ + + #ifdef HAVE_SIG_ATOMIC_T + + static sig_atomic_t have_alarm = 0; + + #else /* HAVE_SIG_ATOMIC_T */ + + static volatile int have_alarm = 0; + + #endif + + static RETSIGTYPE handle_alarm(int i) + { + have_alarm = 1; + return (RETSIGTYPE) 0; + } + + /* will trigger alarm for one time only. */ + void set_alarm(struct timeval alarm_time) + { + struct itimerval timer; + struct timeval disarm_timer = { 0, 0 }; + + timer.it_interval = alarm_time; + timer.it_value = disarm_timer; + + have_alarm = 0; + add_interrupt_handler(SIGALRM, handle_alarm); + + /* that's it. after this the timer is ticking. */ + setitimer(ITIMER_REAL, &timer, NULL); + + return; + } + + /* tells us whether we received an alarm or not.*/ + int had_alarm(void) + { + return have_alarm; + } + + /* sigio handling routine and variable. + * we only need to use this on *BSD + * with broken BPF which can't handle a select(). */ + + /* wrap for volatine integers, or proper sig_atomic_t types. */ + + #ifdef HAVE_SIG_ATOMIC_T + + static sig_atomic_t have_io = 0; + + #else /* HAVE_SIG_ATOMIC_T */ + + static volatile int have_io = 0; + + #endif + + static RETSIGTYPE handle_sigio(int i) + { + have_io = 1; + } + + void track_sigio(void) + { + add_interrupt_handler(SIGIO, handle_sigio); + return; + } + + int had_io(void) + { + if(have_io) { + have_io = 0; + return 1; + } else + return 0; + } Index: dhcp-util.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-util.h 17 Jun 2002 13:23:08 -0000 1.3 --- dhcp-util.h 19 Jun 2002 00:40:12 -0000 1.4 *************** *** 49,52 **** --- 49,54 ---- extern void block_interrupts(void); extern void add_interrupt_handler(int sigtype, void (*sighandler)(int)); + extern int had_alarm(void); + extern void set_alarm(struct timeval alarm_time); extern void info_message(char *fmt, ...); extern char *splice_string(const char *s1, const char *s2); *************** *** 60,63 **** --- 62,67 ---- extern struct timeval timeval_diff(struct timeval begin, struct timeval end); extern const char *getprogname(void); + extern void track_sigio(void); + extern int had_io(void); #endif /* DHCP_UTIL_H */ |