Skip to content

Commit

Permalink
Systemd-based socket activation
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Schaten committed Jun 19, 2021
1 parent 3b31c4b commit d2d7088
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,14 @@ AC_SEARCH_LIBS(clock_gettime, [rt posix4])
# Check for clock_gettime support
AC_CHECK_FUNCS([clock_gettime])


#
# Check for systemd to support socket-based activation
#
AC_CHECK_HEADERS([systemd/sd-daemon.h],
AC_DEFINE([HAVE_SD_DAEMON_H], [1], [Have sd-daemon support.])
AC_SEARCH_LIBS(sd_listen_fds, [systemd]))


AC_CONFIG_FILES([Makefile src/Makefile src/version.h examples/Makefile iperf3.spec])
AC_OUTPUT
5 changes: 5 additions & 0 deletions contrib/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Unit]
Description=Socket-Activated iperf3

[Service]
ExecStart=/usr/local/bin/iperf3 -s -1 -p %i --forceflush
6 changes: 6 additions & 0 deletions contrib/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Socket]
ListenStream=%i

[Install]
WantedBy=sockets.target

3 changes: 3 additions & 0 deletions src/iperf_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
/* Have SCTP support. */
#undef HAVE_SCTP_H

/* Have sd-daemon support. */
#undef HAVE_SD_DAEMON_H

/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE

Expand Down
16 changes: 16 additions & 0 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,25 @@
#endif /* TCP_CA_NAME_MAX */
#endif /* HAVE_TCP_CONGESTION */

#if defined(HAVE_SD_DAEMON_H)
#include <systemd/sd-daemon.h>
#endif

int
iperf_server_listen(struct iperf_test *test)
{
int n = 0;
retry:
#if defined(HAVE_SD_DAEMON_H)
n = sd_listen_fds(0);
if (n > 1) {
return -1;
}
if (n == 1) {
test->listener = SD_LISTEN_FDS_START + 0;
}
#endif
if (n == 0) {
if((test->listener = netannounce(test->settings->domain, Ptcp, test->bind_address, test->bind_dev, test->server_port)) < 0) {
if (errno == EAFNOSUPPORT && (test->settings->domain == AF_INET6 || test->settings->domain == AF_UNSPEC)) {
/* If we get "Address family not supported by protocol", that
Expand All @@ -85,6 +100,7 @@ iperf_server_listen(struct iperf_test *test)
return -1;
}
}
}

if (!test->json_output) {
if (test->server_last_run_rc != 2)
Expand Down

0 comments on commit d2d7088

Please sign in to comment.