src/lib/trema.c in trema-0.2.5 vs src/lib/trema.c in trema-0.2.6

- old
+ new

@@ -33,10 +33,11 @@ #include <unistd.h> #include "trema.h" #include "daemon.h" #include "doubly_linked_list.h" #include "log.h" +#include "management_interface.h" #include "messenger.h" #include "openflow_application_interface.h" #include "packetin_filter_interface.h" #include "timer.h" #include "trema_private.h" @@ -198,11 +199,11 @@ #ifdef printf #undef printf #endif #define printf mock_printf -int mock_printf(const char *format, ...); +int mock_printf( const char *format, ...); typedef struct stat _stat; #ifdef stat #undef stat #endif @@ -241,11 +242,11 @@ #ifdef set_external_callback #undef set_external_callback #endif #define set_external_callback mock_set_external_callback -bool mock_set_external_callback( void ( *callback ) ( void ) ); +bool mock_set_external_callback( void ( *callback )( void ) ); #ifdef dump_stats #undef dump_stats #endif #define dump_stats mock_dump_stats @@ -255,10 +256,22 @@ #undef finalize_packetin_filter_interface #endif #define finalize_packetin_filter_interface mock_finalize_packetin_filter_interface bool mock_finalize_packetin_filter_interface(); +#ifdef init_management_interface +#undef init_management_interface +#endif +#define init_management_interface mock_init_management_interface +bool mock_init_management_interface(); + +#ifdef finalize_management_interface +#undef finalize_management_interface +#endif +#define finalize_management_interface mock_finalize_management_interface +bool mock_finalize_management_interface(); + #define static #endif // UNIT_TESTING @@ -282,14 +295,15 @@ static struct option long_options[] = { { "name", 1, NULL, 'n' }, { "daemonize", 0, NULL, 'd' }, { "logging_level", 1, NULL, 'l' }, { "syslog", 0, NULL, 'g' }, + { "logging_facility", 1, NULL, 'f' }, { "help", 0, NULL, 'h' }, { NULL, 0, NULL, 0 }, }; -static char short_options[] = "n:dl:gh"; +static char short_options[] = "n:dl:gf:h"; /** * Default usage function shown on <tt>-h</tt> or <tt>--help</tt>. * @@ -299,15 +313,16 @@ void usage() { printf( "Usage: %s [OPTION]...\n" "\n" - " -n, --name=SERVICE_NAME service name\n" - " -d, --daemonize run in the background\n" - " -l, --logging_level=LEVEL set logging level\n" - " -g, --syslog output log messages to syslog\n" - " -h, --help display this help and exit\n", + " -n, --name=SERVICE_NAME service name\n" + " -d, --daemonize run in the background\n" + " -l, --logging_level=LEVEL set logging level\n" + " -g, --syslog output log messages to syslog\n" + " -f, --logging_facility=FACILITY set syslog facility\n" + " -h, --help display this help and exit\n", executable_name ); } @@ -365,10 +380,11 @@ die_unless_initialized(); debug( "Terminating %s...", get_trema_name() ); maybe_finalize_openflow_application_interface(); + finalize_management_interface(); finalize_packetin_filter_interface(); finalize_messenger(); finalize_stat(); finalize_timer(); trema_started = false; @@ -441,10 +457,13 @@ set_logging_level( optarg ); break; case 'g': log_output_type = LOGGING_TYPE_SYSLOG; break; + case 'f': + set_syslog_facility( optarg ); + break; case 'h': usage(); xfree( trema_name ); xfree( executable_name ); exit( EXIT_SUCCESS ); @@ -605,10 +624,11 @@ set_usr1_handler(); set_usr2_handler(); init_messenger( get_trema_sock() ); init_stat(); init_timer(); + init_management_interface(); initialized = true; pthread_mutex_unlock( &mutex ); } @@ -629,11 +649,11 @@ start_trema_up() { pthread_mutex_lock( &mutex ); die_unless_initialized(); - debug( "Starting %s ... (TREMA_HOME = %s)", get_trema_name(), get_trema_home() ); + debug( "Starting %s ... ( TREMA_HOME = %s )", get_trema_name(), get_trema_home() ); maybe_daemonize(); write_pid( get_trema_pid(), get_trema_name() ); trema_started = true; @@ -730,9 +750,18 @@ if ( try > max_try ) { error( "Failed to terminate %d.", pid ); return false; } return true; +} + + +void +_free_trema_name() { + if ( trema_name != NULL ) { + xfree( trema_name ); + trema_name = NULL; + } } /* * Local variables: