From: eitan Date: Wed, 12 Oct 2005 06:25:26 +0000 (+0000) Subject: Add -e flag to main in order to enable starting a new log file, X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=eb3a1de3337f096f2d7ce49a9e12dd131ed2d417;p=~shefty%2Frdma-win.git Add -e flag to main in order to enable starting a new log file, instead of accumulating it. git-svn-id: svn://openib.tc.cornell.edu/gen1@111 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- diff --git a/trunk/ulp/opensm/user/ibtrapgen/ibtrapgen.c b/trunk/ulp/opensm/user/ibtrapgen/ibtrapgen.c index c6bd3a24..f5663a54 100644 --- a/trunk/ulp/opensm/user/ibtrapgen/ibtrapgen.c +++ b/trunk/ulp/opensm/user/ibtrapgen/ibtrapgen.c @@ -113,7 +113,7 @@ ibtrapgen_init( IN ibtrapgen_t * const p_ibtrapgen, p_ibtrapgen->p_log = (osm_log_t *)cl_malloc(sizeof(osm_log_t)); osm_log_construct( p_ibtrapgen->p_log ); status = osm_log_init( p_ibtrapgen->p_log, p_opt->force_log_flush, - 0x0001, p_opt->log_file ); + 0x0001, p_opt->log_file, TRUE ); if( status != IB_SUCCESS ) return ( status ); diff --git a/trunk/ulp/opensm/user/include/opensm/osm_log.h b/trunk/ulp/opensm/user/include/opensm/osm_log.h index c84355f8..3337794a 100644 --- a/trunk/ulp/opensm/user/include/opensm/osm_log.h +++ b/trunk/ulp/opensm/user/include/opensm/osm_log.h @@ -230,7 +230,8 @@ osm_log_init( IN osm_log_t* const p_log, IN const boolean_t flush, IN const uint8_t log_flags, - IN const char *log_file) + IN const char *log_file, + IN const boolean_t accum_log_file ) { p_log->level = log_flags; p_log->flush = flush; @@ -241,10 +242,18 @@ osm_log_init( } else { + if (accum_log_file) p_log->out_port = fopen(log_file,"a+"); + else + p_log->out_port = fopen(log_file,"w+"); + if (!p_log->out_port) { + if (accum_log_file) printf("Cannot open %s for appending. Permission denied\n", log_file); + else + printf("Cannot open %s for writing. Permission denied\n", log_file); + return(IB_UNKNOWN_ERROR); } } diff --git a/trunk/ulp/opensm/user/include/opensm/osm_subnet.h b/trunk/ulp/opensm/user/include/opensm/osm_subnet.h index 4e0793d8..2ec5a2ab 100644 --- a/trunk/ulp/opensm/user/include/opensm/osm_subnet.h +++ b/trunk/ulp/opensm/user/include/opensm/osm_subnet.h @@ -217,6 +217,7 @@ typedef struct _osm_subn_opt uint8_t log_flags; char * dump_files_dir; char * log_file; + boolean_t accum_log_file; cl_map_t port_pro_ignore_guids; boolean_t port_profile_switch_nodes; uint32_t max_port_profile; @@ -316,6 +317,10 @@ typedef struct _osm_subn_opt * log_file * Name of the log file (or NULL) for stdout. * +* accum_log_file +* If TRUE (default) - the log file will be accumulated. +* If FALSE - the log file will be erased before starting current opensm run. +* * port_pro_ignore_guids * A map of guids to be ignored by port profiling. * diff --git a/trunk/ulp/opensm/user/opensm/cl_event_wheel.c b/trunk/ulp/opensm/user/opensm/cl_event_wheel.c index e23d51c2..97cceb2b 100644 --- a/trunk/ulp/opensm/user/opensm/cl_event_wheel.c +++ b/trunk/ulp/opensm/user/opensm/cl_event_wheel.c @@ -604,7 +604,7 @@ main () cl_event_wheel_construct( &event_wheel ); /* init */ - osm_log_init( &log, TRUE, 0xff, NULL); + osm_log_init( &log, TRUE, 0xff, NULL, FALSE); cl_event_wheel_init( &event_wheel, &log ); /* Start Playing */ diff --git a/trunk/ulp/opensm/user/opensm/main.c b/trunk/ulp/opensm/user/opensm/main.c index a5b46512..8059ec50 100644 --- a/trunk/ulp/opensm/user/opensm/main.c +++ b/trunk/ulp/opensm/user/opensm/main.c @@ -160,6 +160,11 @@ show_usage(void) " This option defines the log to be the given file.\n" " By default the log goes to /var/log/osm.log.\n" " For the log to go to standard output use -f stdout.\n\n"); + printf( "-e\n" + "--erase_log_file\n" + " This option will cause deletion of the log file \n" + " (if it previously exists). By default, the log file \n" + " is accumulative.\n\n"); printf( "-v\n" "--verbose\n" " This option increases the log verbosity level.\n" @@ -449,7 +454,7 @@ main( boolean_t cache_options = FALSE; char *ignore_guids_file_name = NULL; uint32_t val; - const char * const short_option = "i:f:d:g:l:s:t:vVhorc"; + const char * const short_option = "i:f:ed:g:l:s:t:vVhorc"; /* In the array below, the 2nd parameter specified the number @@ -469,6 +474,7 @@ main( { "verbose", 0, NULL, 'v'}, { "D", 1, NULL, 'D'}, { "log_file", 1, NULL, 'f'}, + { "erase_log_file",0, NULL, 'e'}, { "maxsmps", 1, NULL, 'n'}, { "V", 0, NULL, 'V'}, { "help", 0, NULL, 'h'}, @@ -618,6 +624,11 @@ main( opt.log_file = optarg; break; + case 'e': + opt.accum_log_file = FALSE; + printf(" Erasing existing(old) log file\n"); + break; + case 'v': log_flags = (log_flags <<1 )|1; printf(" Verbose option -v (log flags = 0x%X)\n", log_flags ); diff --git a/trunk/ulp/opensm/user/opensm/osm_opensm.c b/trunk/ulp/opensm/user/opensm/osm_opensm.c index 2e800d18..925d227e 100644 --- a/trunk/ulp/opensm/user/opensm/osm_opensm.c +++ b/trunk/ulp/opensm/user/opensm/osm_opensm.c @@ -202,7 +202,7 @@ osm_opensm_init( osm_opensm_construct( p_osm ); status = osm_log_init( &p_osm->log, p_opt->force_log_flush, - p_opt->log_flags, p_opt->log_file ); + p_opt->log_flags, p_opt->log_file, p_opt->accum_log_file ); if( status != IB_SUCCESS ) return ( status ); diff --git a/trunk/ulp/opensm/user/opensm/osm_subnet.c b/trunk/ulp/opensm/user/opensm/osm_subnet.c index 9ab35f79..beec964a 100644 --- a/trunk/ulp/opensm/user/opensm/osm_subnet.c +++ b/trunk/ulp/opensm/user/opensm/osm_subnet.c @@ -424,6 +424,7 @@ osm_subn_set_default_opt( p_opt->dump_files_dir = OSM_DEFAULT_TMP_DIR; p_opt->log_file = OSM_DEFAULT_LOG_FILE; + p_opt->accum_log_file = TRUE; p_opt->port_profile_switch_nodes = FALSE; p_opt->max_port_profile = 0xffffffff; p_opt->pfn_ui_pre_lid_assign = NULL; @@ -751,6 +752,10 @@ osm_subn_parse_conf_file( __osm_subn_opts_unpack_charp( "log_file" , p_key, p_val, &p_opts->log_file); + __osm_subn_opts_unpack_boolean( + "accum_log_file", + p_key, p_val, &p_opts->accum_log_file); + __osm_subn_opts_unpack_charp( "dump_files_dir" , p_key, p_val, &p_opts->dump_files_dir); @@ -917,6 +922,7 @@ osm_subn_write_conf_file( "force_log_flush %s\n\n" "# Log file to be used\n" "log_file %s\n\n" + "accum_log_file %s\n\n" "# The directory to hold the file OpenSM dumps\n" "dump_files_dir %s\n\n" "# If TRUE if OpenSM should disable multicast support\n" @@ -926,6 +932,7 @@ osm_subn_write_conf_file( p_opts->log_flags, p_opts->force_log_flush ? "TRUE" : "FALSE", p_opts->log_file, + p_opts->accum_log_file, p_opts->dump_files_dir, p_opts->no_multicast_option ? "TRUE" : "FALSE", p_opts->disable_multicast ? "TRUE" : "FALSE" diff --git a/trunk/ulp/opensm/user/osmtest/osmtest.c b/trunk/ulp/opensm/user/osmtest/osmtest.c index b88cf79b..ef8ee085 100644 --- a/trunk/ulp/opensm/user/osmtest/osmtest.c +++ b/trunk/ulp/opensm/user/osmtest/osmtest.c @@ -518,7 +518,7 @@ osmtest_init( IN osmtest_t * const p_osmt, osmtest_construct( p_osmt ); status = osm_log_init( &p_osmt->log, p_opt->force_log_flush, - 0x0001, p_opt->log_file ); + 0x0001, p_opt->log_file, TRUE ); if( status != IB_SUCCESS ) return ( status ); /* but we do not want any extra staff here */