From 71b2f409633823e3544f9adc328429ff55cf2da1 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 19 Oct 2023 12:57:13 +0000 Subject: [PATCH] sd_notify(3): set the MONOTONIC_USEC field with RELOADING=1 When using sd_notify(3) to send a message to the service manager about named being reloaded, systemd also requires the MONOTONIC_USEC field to be set to the current monotonic time in microseconds, otherwise the 'systemctl reload' command fails. Add the MONOTONIC_USEC field to the message. See 'man 5 systemd.service' for more information. --- bin/named/server.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/bin/named/server.c b/bin/named/server.c index f23e28547a..9333d206c8 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -10287,8 +10288,15 @@ reload(named_server_t *server) { atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS); #if HAVE_LIBSYSTEMD - sd_notify(0, "RELOADING=1\n" - "STATUS=reload command received\n"); + char buf[512]; + int n = snprintf(buf, sizeof(buf), + "RELOADING=1\n" + "MONOTONIC_USEC=%" PRIu64 "\n" + "STATUS=reload command received\n", + (uint64_t)isc_time_monotonic() / NS_PER_US); + if (n > 0 && (size_t)n < sizeof(buf)) { + sd_notify(0, buf); + } #endif /* HAVE_LIBSYSTEMD */ CHECK(loadconfig(server)); @@ -10668,8 +10676,15 @@ named_server_reconfigcommand(named_server_t *server) { isc_result_t result; atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS); #if HAVE_LIBSYSTEMD - sd_notify(0, "RELOADING=1\n" - "STATUS=reconfig command received\n"); + char buf[512]; + int n = snprintf(buf, sizeof(buf), + "RELOADING=1\n" + "MONOTONIC_USEC=%" PRIu64 "\n" + "STATUS=reconfig command received\n", + (uint64_t)isc_time_monotonic() / NS_PER_US); + if (n > 0 && (size_t)n < sizeof(buf)) { + sd_notify(0, buf); + } #endif /* HAVE_LIBSYSTEMD */ CHECK(loadconfig(server));