diff --git a/src/iperf_api.c b/src/iperf_api.c index 014a56055..4e8ed1fa7 100755 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -390,6 +390,12 @@ iperf_set_test_blksize(struct iperf_test *ipt, int blksize) ipt->settings->blksize = blksize; } +void +iperf_set_test_logfile(struct iperf_test *ipt, char *logfile) +{ + ipt->logfile = strdup(logfile); +} + void iperf_set_test_rate(struct iperf_test *ipt, uint64_t rate) { @@ -1217,15 +1223,6 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) } } - /* Set logging to a file if specified, otherwise use the default (stdout) */ - if (test->logfile) { - test->outfile = fopen(test->logfile, "a+"); - if (test->outfile == NULL) { - i_errno = IELOGFILE; - return -1; - } - } - /* Check flag / role compatibility. */ if (test->role == 'c' && server_flag) { i_errno = IESERVERONLY; @@ -1350,6 +1347,20 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) return 0; } +/* + * Open the file specified by test->logfile and set test->outfile to its' FD. + */ +int iperf_open_logfile(struct iperf_test *test) +{ + test->outfile = fopen(test->logfile, "a+"); + if (test->outfile == NULL) { + i_errno = IELOGFILE; + return -1; + } + + return 0; +} + int iperf_set_send_state(struct iperf_test *test, signed char state) { diff --git a/src/iperf_api.h b/src/iperf_api.h index 7daf97495..7483faa86 100755 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -138,6 +138,7 @@ void iperf_set_test_reporter_interval( struct iperf_test* ipt, double reporter_i void iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval ); void iperf_set_test_state( struct iperf_test* ipt, signed char state ); void iperf_set_test_blksize( struct iperf_test* ipt, int blksize ); +void iperf_set_test_logfile( struct iperf_test* ipt, char *logfile ); void iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate ); void iperf_set_test_pacing_timer( struct iperf_test* ipt, int pacing_timer ); void iperf_set_test_bytes( struct iperf_test* ipt, uint64_t bytes ); @@ -267,6 +268,7 @@ int iperf_exchange_results(struct iperf_test *); int iperf_init_test(struct iperf_test *); int iperf_create_send_timers(struct iperf_test *); int iperf_parse_arguments(struct iperf_test *, int, char **); +int iperf_open_logfile(struct iperf_test *); void iperf_reset_test(struct iperf_test *); void iperf_reset_stats(struct iperf_test * test); diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index 46c283b43..20ea6fda5 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -454,6 +454,10 @@ iperf_run_client(struct iperf_test * test) struct timeval* timeout = NULL; struct iperf_stream *sp; + if (test->logfile) + if (iperf_open_logfile(test) < 0) + return -1; + if (test->affinity != -1) if (iperf_setaffinity(test, test->affinity) != 0) return -1; diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 079da8968..56cab4bb1 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -398,6 +398,10 @@ iperf_run_server(struct iperf_test *test) struct timeval* timeout; int flag; + if (test->logfile) + if (iperf_open_logfile(test) < 0) + return -1; + if (test->affinity != -1) if (iperf_setaffinity(test, test->affinity) != 0) return -2;