-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exit with 0 on SIGTERM/SIGHUP/SIGINT #1829
base: master
Are you sure you want to change the base?
Exit with 0 on SIGTERM/SIGHUP/SIGINT #1829
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm that this fixes the issue -- when I run sudo systemctl stop iperf3
it stops cleanly now:
Feb 06 23:18:56 srv1 systemd[1]: Started iperf3 daemon.
Feb 06 23:19:05 srv1 iperf3[2413983]: iperf3: interrupt - the server has terminated by signal Terminated(15)
Feb 06 23:19:05 srv1 iperf3[2413983]: -----------------------------------------------------------
Feb 06 23:19:05 srv1 iperf3[2413983]: Server listening on 5201 (test #1)
Feb 06 23:19:05 srv1 iperf3[2413983]: -----------------------------------------------------------
Feb 06 23:19:05 srv1 systemd[1]: Stopping iperf3 daemon...
Feb 06 23:19:05 srv1 systemd[1]: iperf3.service: Deactivated successfully.
Feb 06 23:19:05 srv1 systemd[1]: Stopped iperf3 daemon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! One comment (well with two parts) in-line.
src/iperf_api.c
Outdated
@@ -4868,7 +4868,11 @@ iperf_got_sigend(struct iperf_test *test) | |||
(void) Nwrite(test->ctrl_sck, (char*) &test->state, sizeof(signed char), Ptcp); | |||
} | |||
i_errno = (test->role == 'c') ? IECLIENTTERM : IESERVERTERM; | |||
iperf_errexit(test, "interrupt - %s", iperf_strerror(i_errno)); | |||
if (sig == SIGTERM) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple comments on this part:
- iperf3 does identical signal handling for
SIGINT
,SIGTERM
, andSIGHUP
(per the functioniperf_catch_sigend()
). If we want to treat an exit because of aSIGTERM
as a "non-error" exit, would it make sense to do the same forSIGINT
andSIGHUP
also? - In commit 0eb370d, we added conditional compilation to be sure these signal names were defined before using them (these changes were added as a part of PR Minor fix to improve the portability #935). Something similar might be necessary here as well. That PR has some more details on the environment where this was necessary, which seems somewhat different from a typical POSIX.1 environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Added
SIGHUP
to theSIGTERM
for the "non-error" exit. As I understand,SIGHUP
is sent when the controlling process is terminated, so I assume any error conditions may be handled there. RegardingSIGINT
I don't know what it the right handling. As its common use (if I understand correctly) is by the CLI "control-C" then the exit code may not be important. If you think it should be added I will do that. (Another approach could be adding an iperf3 option with the list of these signals, but it seems to be an overkill.) -
Added
#ifdef
toSIGHUP
andSIGTERM
per commit0eb370d
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes...I think this is probably the best behavior because iperf3 explicitly has code to gracefully exit for all three of those signals. So regardless of what causes something to send a signal to an iperf3 process, it'll behave consistently in all of those cases.
I'm got a question in to the perfSONAR team (our primary constituency) to confirm this isn't going to cause any problems for that use case before merging. I'm not expecting any problems.
…idef to the signals names
Greetings from the perfSONAR constituency. :-) If perfSONAR sends iperf3 a signal, we already know the program is going to stop and don't care about how it exits, although the exit code might be noted in the diagnostics. If we run iperf3 and it stops before completing the job we asked of it, that should be reported as an error. I can appreciate that If the goal here is to make a Systemd unit happy with this kind of exit, the
|
Thanks for the feedback! I'm glad to know that perfSONAR (or rather pScheduler I guess) doesn't care. iperf3 catches three signals so that it can exit cleanly. I think this behavior was intended to handle the user sending a SIGINT. As iperf3 stands now, the exit value in these cases is iperf3 follows the correct behavior for all other (uncaught) signals, it exits with I think I've done the tweak to Argh. I admit I'm still fuzzy on what exactly the correct behavior should be. It feels to me like the latest of this PR makes things better though? |
That doesn't work because iperf3 currently exits with 1 on SIGTERM, making it impossible to distinguish between successful and erronous exit.
Yes, this makes it better, because now a clean exit isn't mapped to error code '1'. But I'm fine with the exit code being 128 + 15 when receiving SIGTERM (15) too. |
Version of iperf3 (or development branch, such as
master
or3.1-STABLE
) to which this pull request applies:master
Issues fixed (if any): Better daemon mode #1009
Brief description of code changes (suitable for use as a commit message):
Exit with code 0 on termination because of SIGTERM. Termination because of all other signals remain with exit code 1.