aboutsummaryrefslogtreecommitdiff
path: root/src/iperf_error.c
diff options
context:
space:
mode:
authorBruce A. Mah <bmah@es.net>2014-03-14 14:23:38 -0700
committerBruce A. Mah <bmah@es.net>2014-03-14 14:23:38 -0700
commitaeb6938d5ab2e3c2c72a5831fbf87ce7cfb21f1d (patch)
treec17c8871d2ae89a60e78cb059bd7a839ee39475f /src/iperf_error.c
parent3f5f7f759186c7fa21a5d00738e88b2f40a3dbee (diff)
downloadiperf3-aeb6938d5ab2e3c2c72a5831fbf87ce7cfb21f1d.tar.gz
Support --logfile argument to make all output go to a file.
This works for both client and server side (in the case of the server, either for daemon or non-daemon mode). Consistifies a few places that were using printf instead of iprintf. Fixes Issue 119.
Diffstat (limited to 'src/iperf_error.c')
-rw-r--r--src/iperf_error.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/iperf_error.c b/src/iperf_error.c
index d4cb444..51b0f8b 100644
--- a/src/iperf_error.c
+++ b/src/iperf_error.c
@@ -28,11 +28,16 @@ iperf_err(struct iperf_test *test, const char *format, ...)
if (test != NULL && test->json_output && test->json_top != NULL)
cJSON_AddStringToObject(test->json_top, "error", str);
else
- fprintf(stderr, "iperf3: %s\n", str);
+ if (test && test->outfile) {
+ fprintf(test->outfile, "iperf3: %s\n", str);
+ }
+ else {
+ fprintf(stderr, "iperf3: %s\n", str);
+ }
va_end(argp);
}
-/* Do a printf to stderr, then exit. */
+/* Do a printf to stderr or log file as appropriate, then exit. */
void
iperf_errexit(struct iperf_test *test, const char *format, ...)
{
@@ -45,7 +50,12 @@ iperf_errexit(struct iperf_test *test, const char *format, ...)
cJSON_AddStringToObject(test->json_top, "error", str);
iperf_json_finish(test);
} else
- fprintf(stderr, "iperf3: %s\n", str);
+ if (test && test->outfile) {
+ fprintf(test->outfile, "iperf3: %s\n", str);
+ }
+ else {
+ fprintf(stderr, "iperf3: %s\n", str);
+ }
va_end(argp);
iperf_delete_pidfile(test);
exit(1);
@@ -116,6 +126,10 @@ iperf_strerror(int i_errno)
case IEENDCONDITIONS:
snprintf(errstr, len, "only one test end condition (-t, -n, -k) may be specified");
break;
+ case IELOGFILE:
+ snprintf(errstr, len, "unable to open log file");
+ perr = 1;
+ break;
case IENEWTEST:
snprintf(errstr, len, "unable to create a new test");
perr = 1;