Skip to content

Commit

Permalink
Allow pidfile in client mode too.
Browse files Browse the repository at this point in the history
Automated use of iperf needs a way to clean up client-mode
connections too, so let the pidfile work in either mode.

Signed-off-by: Ben Greear <greearb@candelatech.com>
  • Loading branch information
greearb committed Dec 19, 2018
1 parent a9e42bf commit 85303e6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/iperf3.1
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ send output to a log file.
force flushing output at every interval.
Used to avoid buffering when sending output to pipe.
.TP
.BR -I ", " --pidfile " \fIfile\fR"
write a file with the process ID, useful for automated process cleanup.
.TP
.BR -d ", " --debug " "
emit debugging output.
Primarily (perhaps exclusively) of use to developers.
Expand All @@ -173,9 +176,6 @@ run in server mode
.BR -D ", " --daemon " "
run the server in background as a daemon
.TP
.BR -I ", " --pidfile " \fIfile\fR"
write a file with the process ID, most useful when running as a daemon.
.TP
.BR -1 ", " --one-off
handle one client connection, then exit.
.TP
Expand Down
1 change: 0 additions & 1 deletion src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
break;
case 'I':
test->pidfile = strdup(optarg);
server_flag = 1;
break;
case OPT_LOGFILE:
test->logfile = strdup(optarg);
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n"
" -J, --json output in JSON format\n"
" --logfile f send output to a log file\n"
" --forceflush force flushing output at every interval\n"
" -I, --pidfile file write PID file\n"
" -d, --debug emit debugging output\n"
" -v, --version show version information and quit\n"
" -h, --help show this message and quit\n"
"Server specific:\n"
" -s, --server run in server mode\n"
" -D, --daemon run the server as a daemon\n"
" -I, --pidfile file write PID file\n"
" -1, --one-off handle one client connection then exit\n"
#if defined(HAVE_SSL)
" --rsa-private-key-path path to the RSA private key used to decrypt\n"
Expand Down
12 changes: 7 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ run(struct iperf_test *test)
/* Ignore SIGPIPE to simplify error handling */
signal(SIGPIPE, SIG_IGN);

if (iperf_create_pidfile(test) < 0) {
i_errno = IEPIDFILE;
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
}

switch (test->role) {
case 's':
if (test->daemon) {
Expand All @@ -143,10 +148,6 @@ run(struct iperf_test *test)
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
}
}
if (iperf_create_pidfile(test) < 0) {
i_errno = IEPIDFILE;
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
}
for (;;) {
int rc;
rc = iperf_run_server(test);
Expand All @@ -160,7 +161,6 @@ run(struct iperf_test *test)
if (iperf_get_test_one_off(test))
break;
}
iperf_delete_pidfile(test);
break;
case 'c':
if (iperf_run_client(test) < 0)
Expand All @@ -171,6 +171,8 @@ run(struct iperf_test *test)
break;
}

iperf_delete_pidfile(test);

iperf_catch_sigend(SIG_DFL);
signal(SIGPIPE, SIG_DFL);

Expand Down

0 comments on commit 85303e6

Please sign in to comment.