[Dhcp-agent-commits] CVS: dhcp-agent dhcp-agent.h,1.17,1.18 dhcp-client-conf.c,1.2,1.3 dhcp-client.c
Status: Alpha
Brought to you by:
actmodern
From: Thamer Al-H. <act...@us...> - 2002-02-07 18:41:51
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv6477 Modified Files: dhcp-agent.h dhcp-client-conf.c dhcp-client.c dhcp-util.c dhcpclient.1 Log Message: added verbosity level option; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-agent.h 5 Feb 2002 02:00:59 -0000 1.17 --- dhcp-agent.h 7 Feb 2002 18:41:47 -0000 1.18 *************** *** 37,48 **** #endif - # include <sys/time.h> # include <sys/types.h> # include <sys/socket.h> # include <sys/stat.h> - # include <unistd.h> - # include <fcntl.h> - # include <syslog.h> - # include <signal.h> # include <netinet/in.h> --- 37,44 ---- #endif # include <sys/types.h> + # include <sys/time.h> # include <sys/socket.h> # include <sys/stat.h> # include <netinet/in.h> *************** *** 54,63 **** # include <fcntl.h> # include <ctype.h> - # include <time.h> # include <unistd.h> ! # include <dnet.h> - # include <dnet/ip.h> - # include <dnet/udp.h> # include <pcap.h> --- 50,58 ---- # include <fcntl.h> # include <ctype.h> # include <unistd.h> ! # include <syslog.h> ! # include <signal.h> ! # include <time.h> # include <dnet.h> # include <pcap.h> *************** *** 153,156 **** --- 148,160 ---- #endif + /* Verbosity levels. */ + + #define QUIET_VERBOSITY_LEVEL 0 + #define ERROR_VERBOSITY_LEVEL 1 + #define NORMAL_VERBOSITY_LEVEL 2 + #define WARNING_VERBOSITY_LEVEL 3 + #define DEBUG_VERBOSITY_LEVEL 4 + #define MAX_VERBOSITY_LEVEL DEBUG_VERBOSITY_LEVEL + /* * * * * * * * * * * * Data structures. * *************** *** 501,504 **** --- 505,514 ---- extern void error_message(char *fmt, ...); extern void fatal_error(char *fmt, ...); + extern void warn_message(char *fmt, ...); + extern void debug_message(char *fmt, ...); + + extern int get_verbosity_level(void); + extern int set_verbosity_level(int verbosity_level_to_set); + extern void *xmalloc(size_t size); extern void *xcalloc(size_t size); *************** *** 789,793 **** extern void delete_pid_file(char *name); extern int get_pid_file(char *name, pid_t *pid); - /* System configuration routines. */ --- 799,802 ---- Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-conf.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-conf.c 6 Feb 2002 23:50:15 -0000 1.2 --- dhcp-client-conf.c 7 Feb 2002 18:41:47 -0000 1.3 *************** *** 53,57 **** client_conf_reset_options(cc); cc->interface = dc->interface; - cc->conf_file = NULL; return cc; --- 53,56 ---- *************** *** 60,67 **** void client_conf_destroy(client_conf_t *cc) { ! if(cc->conf_file != NULL) ! xfree(cc->conf_file); ! ! xfree(cc); } --- 59,63 ---- void client_conf_destroy(client_conf_t *cc) { ! xfree(cc); } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client.c 3 Feb 2002 16:56:00 -0000 1.11 --- dhcp-client.c 7 Feb 2002 18:41:47 -0000 1.12 *************** *** 96,100 **** case STATE_FATAL_ERROR: ! error_message("I've encountered a fatal error. I'm giving up."); do_shutdown(dc); --- 96,100 ---- case STATE_FATAL_ERROR: ! info_message("I've encountered a fatal error. I'm giving up."); do_shutdown(dc); *************** *** 223,227 **** static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "cdavim:kwh:")) != -1) { switch(c) { --- 223,227 ---- static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "cdavim:kwh:l:")) != -1) { switch(c) { *************** *** 262,265 **** --- 262,274 ---- exit(0); + case 'l': + + if(set_verbosity_level(atoi(optarg))) { + error_message("illegal verbosity level: %s", optarg); + exit(1); + } + + break; + case 'h': /* fall through. */ default: *************** *** 290,294 **** fatal_error("cannot enter work directory", work_dir); } ! /* Now see if another client is running on the same interface. */ --- 299,303 ---- fatal_error("cannot enter work directory", work_dir); } ! /* Now see if another client is running on the same interface. */ *************** *** 297,304 **** exit(1); } ! /* setup umask: this is also done in go_background but the client * doesn't go into the background immediately. so do it now. */ ! umask(0); --- 306,313 ---- exit(1); } ! /* setup umask: this is also done in go_background but the client * doesn't go into the background immediately. so do it now. */ ! umask(0); Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-util.c 5 Feb 2002 02:00:59 -0000 1.4 --- dhcp-util.c 7 Feb 2002 18:41:47 -0000 1.5 *************** *** 28,31 **** --- 28,48 ---- static char msgbuff[MSG_BUFFER_SIZE]; + static int verbosity_level = NORMAL_VERBOSITY_LEVEL; + + /* set the verbosity level. */ + int set_verbosity_level(int verbosity_level_to_set) + { + if(verbosity_level_to_set < 0 || verbosity_level_to_set > MAX_VERBOSITY_LEVEL) + return 1; + + verbosity_level = verbosity_level_to_set; + return 0; + } + + /* get the current verbosity level. */ + int get_verbosity_level(void) + { + return verbosity_level; + } /* send error message. */ *************** *** 34,37 **** --- 51,57 ---- va_list ap; + if(verbosity_level <= QUIET_VERBOSITY_LEVEL) + return; + va_start(ap, fmt); *************** *** 39,43 **** if(interactive == 1) { ! fprintf(stderr, "%s", msgbuff); fprintf(stderr,"\n"); } else --- 59,63 ---- if(interactive == 1) { ! fprintf(stderr, "error: %s", msgbuff); fprintf(stderr,"\n"); } else *************** *** 51,54 **** --- 71,77 ---- { va_list ap; + + if(verbosity_level <= QUIET_VERBOSITY_LEVEL) + return; va_start(ap, fmt); *************** *** 57,61 **** if(interactive == 1) { ! fprintf(stderr, "%s", msgbuff); fprintf(stderr,"\n"); } else --- 80,84 ---- if(interactive == 1) { ! fprintf(stderr, "fatal error: %s", msgbuff); fprintf(stderr,"\n"); } else *************** *** 66,74 **** } ! /* send info message (warnings included) */ void info_message(char *fmt, ...) { va_list ap; va_start(ap, fmt); --- 89,100 ---- } ! /* send info message */ void info_message(char *fmt, ...) { va_list ap; + if(verbosity_level <= ERROR_VERBOSITY_LEVEL) + return; + va_start(ap, fmt); *************** *** 83,87 **** --- 109,155 ---- va_end(ap); } + + /* send warning messages: includes diagnostics. */ + void warn_message(char *fmt, ...) + { + va_list ap; + + if(verbosity_level <= WARNING_VERBOSITY_LEVEL) + return; + + va_start(ap, fmt); + + vsnprintf(msgbuff, sizeof(msgbuff), fmt, ap); + + if(interactive == 1) { + fprintf(stdout, "warning: %s", msgbuff); + fprintf(stdout,"\n"); + } else + info_log(msgbuff); + + va_end(ap); + } + + /* send debug message. */ + void debug_message(char *fmt, ...) + { + va_list ap; + + if(verbosity_level <= DEBUG_VERBOSITY_LEVEL) + return; + + va_start(ap, fmt); + + vsnprintf(msgbuff, sizeof(msgbuff), fmt, ap); + if(interactive == 1) { + fprintf(stdout, "debug: %s", msgbuff); + fprintf(stdout,"\n"); + } else + info_log(msgbuff); + + va_end(ap); + } + /* * Malloc and free wrapper functions in case Index: dhcpclient.1 =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcpclient.1,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcpclient.1 3 Feb 2002 16:56:00 -0000 1.6 --- dhcpclient.1 7 Feb 2002 18:41:47 -0000 1.7 *************** *** 11,14 **** --- 11,15 ---- .Op Ar -i interface name .Op Ar -m fake mac source address + .Op Ar -l verbosity_level .Sh DESCRIPTION .I *************** *** 45,48 **** --- 46,58 ---- Use a fake mac source address. Useful only for diagnostics where want to see if a specific lease based on a mac address is accessible. + .It Op Ar -l verbosity level + Verbosity level can be set to the following integers: + .Bl -tag + .It 0 No output + .It 1 Only error messages are outputed. + .It 2 Normal output; errors and info messages. + .It 3 Warning level. Output warnings along with error and info messages. + .It 4 Debug level. Lots of diagnostic output. All messages. + .El .El .Sh BUGS |