From 78cf48ba8c6f2c4403df6150e82f67826b2baa1f Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 25 Nov 2021 10:28:13 +0100 Subject: [PATCH] linux: use sd_notify_barrier if available If the sd_notify_barrier function is available, use it to synchronize systemd notify notifications and make sure they were processed by systemd. Signed-off-by: Giuseppe Scrivano --- configure.ac | 1 + src/libcrun/container.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 94c9a02d40..7e4aae185b 100644 --- a/configure.ac +++ b/configure.ac @@ -89,6 +89,7 @@ AS_IF([test "x$enable_systemd" != "xno"], [ AC_CHECK_HEADERS([systemd/sd-bus.h], [], [AC_MSG_ERROR([*** Missing libsystemd headers])]) AS_IF([test "$ac_cv_header_systemd_sd_bus_h" = "yes"], [ AC_SEARCH_LIBS(sd_bus_match_signal_async, [systemd], [AC_DEFINE([HAVE_SYSTEMD], 1, [Define if libsystemd is available])], [AC_MSG_ERROR([*** Failed to find libsystemd])]) + AC_CHECK_FUNCS(sd_notify_barrier) ]) ]) diff --git a/src/libcrun/container.c b/src/libcrun/container.c index 0c5ebc23b8..4780a6f649 100644 --- a/src/libcrun/container.c +++ b/src/libcrun/container.c @@ -2185,6 +2185,11 @@ handle_notify_socket (int notify_socketfd, libcrun_error_t *err) if (UNLIKELY (ret < 0)) return crun_make_error (err, -ret, "sd_notify"); +# if HAVE_SD_NOTIFY_BARRIER + /* Hard-code a 30 seconds timeout. Ignore errors. */ + sd_notify_barrier (0, 30 * 1000000); +# endif + return 1; } return 0;