Skip to content

Commit 004a183

Browse files
matt9jcoolshou
authored andcommitted
Return client_api error codes, even with json output enabled
Previously on error, the client API would return 0 (success) in the cleanup and fail error handling path when outputting json to avoid double-closing the JSON output. With iperf_json_finish now idempotent, the client api can faithfully return an error when it fails, and the calling context will not double-close the output if it has already been closed. This addresses esnet#1405 .
1 parent 1e390ae commit 004a183

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Diff for: src/iperf_client_api.c

-4
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,6 @@ iperf_run_client(struct iperf_test * test)
708708
if (test->json_output) {
709709
cJSON_AddStringToObject(test->json_top, "error", iperf_strerror(i_errno));
710710
iperf_json_finish(test);
711-
iflush(test);
712-
// Return 0 and not -1 since all terminating function were done here.
713-
// Also prevents error message logging outside the already closed JSON output.
714-
return 0;
715711
}
716712
iflush(test);
717713
return -1;

Diff for: src/iperf_error.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ iperf_errexit(struct iperf_test *test, const char *format, ...)
9696

9797
va_start(argp, format);
9898
vsnprintf(str, sizeof(str), format, argp);
99-
if (test != NULL && test->json_output && test->json_top != NULL) {
100-
cJSON_AddStringToObject(test->json_top, "error", str);
99+
if (test != NULL && test->json_output) {
100+
if (test->json_top != NULL) {
101+
cJSON_AddStringToObject(test->json_top, "error", str);
102+
}
101103
iperf_json_finish(test);
102104
} else
103105
if (test && test->outfile && test->outfile != stdout) {

0 commit comments

Comments
 (0)