--- embedaddon/iperf/src/main.c 2016/10/18 13:28:18 1.1 +++ embedaddon/iperf/src/main.c 2023/09/27 11:14:54 1.1.1.3 @@ -1,5 +1,5 @@ /* - * iperf, Copyright (c) 2014, 2015, The Regents of the University of + * iperf, Copyright (c) 2014-2022, The Regents of the University of * California, through Lawrence Berkeley National Laboratory (subject * to receipt of any required approvals from the U.S. Dept. of * Energy). All rights reserved. @@ -41,16 +41,13 @@ #include #include #include -#ifdef HAVE_STDINT_H -#include -#endif -#include #include "iperf.h" #include "iperf_api.h" -#include "units.h" +#include "iperf_util.h" #include "iperf_locale.h" #include "net.h" +#include "units.h" static int run(struct iperf_test *test); @@ -65,7 +62,7 @@ main(int argc, char **argv) // XXX: Setting the process affinity requires root on most systems. // Is this a feature we really need? #ifdef TEST_PROC_AFFINITY - /* didnt seem to work.... */ + /* didn't seem to work.... */ /* * increasing the priority of the process to minimise packet generation * delay @@ -77,7 +74,7 @@ main(int argc, char **argv) fprintf(stderr, "setting priority to valid level\n"); rc = setpriority(PRIO_PROCESS, 0, 0); } - + /* setting the affinity of the process */ cpu_set_t cpu_set; int affinity = -1; @@ -104,7 +101,7 @@ main(int argc, char **argv) if (iperf_parse_arguments(test, argc, argv) < 0) { iperf_err(test, "parameter error - %s", iperf_strerror(i_errno)); fprintf(stderr, "\n"); - usage_long(); + usage(); exit(1); } @@ -119,7 +116,7 @@ main(int argc, char **argv) static jmp_buf sigend_jmp_buf; -static void +static void __attribute__ ((noreturn)) sigend_handler(int sig) { longjmp(sigend_jmp_buf, 1); @@ -134,10 +131,14 @@ run(struct iperf_test *test) if (setjmp(sigend_jmp_buf)) iperf_got_sigend(test); + /* Ignore SIGPIPE to simplify error handling */ + signal(SIGPIPE, SIG_IGN); + switch (test->role) { case 's': if (test->daemon) { - int rc = daemon(0, 0); + int rc; + rc = daemon(0, 0); if (rc < 0) { i_errno = IEDAEMON; iperf_errexit(test, "error - %s", iperf_strerror(i_errno)); @@ -150,22 +151,38 @@ run(struct iperf_test *test) for (;;) { int rc; rc = iperf_run_server(test); + test->server_last_run_rc = rc; if (rc < 0) { iperf_err(test, "error - %s", iperf_strerror(i_errno)); + if (test->json_output) { + if (iperf_json_finish(test) < 0) + return -1; + } + iflush(test); + if (rc < -1) { iperf_errexit(test, "exiting"); - break; } } iperf_reset_test(test); - if (iperf_get_test_one_off(test)) - break; + if (iperf_get_test_one_off(test) && rc != 2) { + /* Authentication failure doesn't count for 1-off test */ + if (rc < 0 && i_errno == IEAUTHTEST) { + continue; + } + break; + } } iperf_delete_pidfile(test); break; case 'c': + if (iperf_create_pidfile(test) < 0) { + i_errno = IEPIDFILE; + iperf_errexit(test, "error - %s", iperf_strerror(i_errno)); + } if (iperf_run_client(test) < 0) iperf_errexit(test, "error - %s", iperf_strerror(i_errno)); + iperf_delete_pidfile(test); break; default: usage(); @@ -173,6 +190,7 @@ run(struct iperf_test *test) } iperf_catch_sigend(SIG_DFL); + signal(SIGPIPE, SIG_DFL); return 0; }