Skip to content
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

Systemd-based socket activation #1171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,13 @@ AC_SEARCH_LIBS(clock_nanosleep, [rt posix4])
# Check for clock_nanosleep support
AC_CHECK_FUNCS([clock_nanosleep])

#
# 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 @@ -66,6 +66,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
17 changes: 16 additions & 1 deletion src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
#endif /* TCP_CA_NAME_MAX */
#endif /* HAVE_TCP_CONGESTION */

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

void *
iperf_server_worker_run(void *s) {
struct iperf_stream *sp = (struct iperf_stream *) s;
Expand Down Expand Up @@ -112,8 +116,19 @@ iperf_server_worker_run(void *s) {
int
iperf_server_listen(struct iperf_test *test)
{
int n_systemd_fds = 0;
retry:
if((test->listener = netannounce(test->settings->domain, Ptcp, test->bind_address, test->bind_dev, test->server_port)) < 0) {
#if defined(HAVE_SD_DAEMON_H)
n_systemd_fds = sd_listen_fds(0);
// Got more than one fd from systemd, or sd_listen_fds encountered an error:
if (n_systemd_fds > 1 || n_systemd_fds < 0)
return -1;

if (1 == n_systemd_fds)
test->listener = SD_LISTEN_FDS_START + 0;
#endif

if (0 == n_systemd_fds && (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
** probably means we were compiled with IPv6 but the running
Expand Down