| [chrony-dev] [PATCH] Add -N option for s6-style service readiness notification |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH] Add -N option for s6-style service readiness notification
- From: Emery Hemingway <emery@xxxxxxxxxxxxxxxx>
- Date: Thu, 9 Apr 2026 14:29:11 +0000
- Cc: Emery Hemingway <emery@xxxxxxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=informatics.coop; s=jankyemail; t=1775745045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lZkfE7yfDmT2Z/o+F7wBVGzx9qoNhAuyYLp48467O9Y=; b=vVc+evi6D13UsfPl3Szvq86qm3fXif5cw/oiJxJjDrcl5a0takgHtDWKqNKbnd5zaI4Y8j 2D3DKFs+ZkEuGvX/3JCw8xWPl6+mB9Cnc1UpxaeQOjB2yRk3UNaeMUD2pu0Sc6JqqI5b2n jCgXHok0+Zgolw1vW1kZcxlF3yeyxxR/KmcJVeh2rSX1rSt42qPuYviOAIOyXS5iOvYrx2 nk+wqFDY30D/BxGwQTT2FeSevgDt61tyRahaGSaQtiICsqvx/Gg2kRx9P1XTKzs/PNR0J5 6mYpRPzZ9XH8w3GEKnEBVSDcEEtP7XacLqbX2Uqq0lbKVC+4K6F3MykUwyhTLg==
In this notification scheme a service supervisor creates a pipe
and passes the write file descriptor to chrony. When chronyd is
initialised it writes a newline to the descriptor and the
supervisor is informed that chronyd has successfully started and
is in a ready state.
https://skarnet.org/software/s6/notifywhenup.html
---
doc/chronyd.adoc | 7 +++++++
main.c | 19 ++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/doc/chronyd.adoc b/doc/chronyd.adoc
index be34c96..76c35c6 100644
--- a/doc/chronyd.adoc
+++ b/doc/chronyd.adoc
@@ -201,6 +201,13 @@ still track its offset and frequency relative to the estimated true time. This
option allows *chronyd* to be started without the capability to adjust or set
the system clock (e.g. in some containers) to operate as an NTP server.
+*-N* _fd_::
+This option specifies a file descriptor that *chronyd* will write a newline
+to after it is fully initialised. This is to notify a service supervisor that
+*chronyd* is in a ready state. When using this option it should also be
+specified that this is a non-forking service by using either the *-n* or *-n*
+option.
+
*-v*, *--version*::
With this option *chronyd* will print version number to the terminal and exit.
diff --git a/main.c b/main.c
index 9c90b58..b833ebf 100644
--- a/main.c
+++ b/main.c
@@ -70,6 +70,8 @@ static int exit_status = 0;
static int reload = 0;
+static int notify_fd = 0;
+
static REF_Mode ref_mode = REF_ModeNormal;
/* ================================================== */
@@ -110,6 +112,17 @@ delete_pidfile(void)
static void
notify_system_manager(int start)
{
+ int r;
+ /* s6-style ready notification using a pipe from the parent.
+ Simply writing a newline is sufficient to inform the supervisor. */
+ if (start && notify_fd) {
+ r = write(notify_fd, "\n", 1);
+ if (r != 1) {
+ LOG_FATAL("Failed to write ready notification requested by -N option");
+ }
+ close(notify_fd);
+ }
+
#ifdef LINUX
/* The systemd protocol is documented in the sd_notify(3) man page */
const char *message, *path = getenv("NOTIFY_SOCKET");
@@ -454,6 +467,7 @@ print_help(const char *progname)
" -P PRIORITY\tSet process priority (0)\n"
" -m\t\tLock memory\n"
" -x\t\tDon't control clock\n"
+ " -N FD\tNotify supervisor\n"
" -v, --version\tPrint version and exit\n"
" -h, --help\tPrint usage and exit\n",
progname, DEFAULT_CONF_FILE, DEFAULT_USER);
@@ -512,7 +526,7 @@ int main
optind = 1;
/* Parse short command-line options */
- while ((opt = getopt(argc, argv, "46df:F:hl:L:mnpP:qQrRst:u:Uvx")) != -1) {
+ while ((opt = getopt(argc, argv, "46df:F:hl:L:mnN:pP:qQrRst:u:Uvx")) != -1) {
switch (opt) {
case '4':
case '6':
@@ -541,6 +555,9 @@ int main
case 'n':
nofork = 1;
break;
+ case 'N':
+ notify_fd = parse_int_arg(optarg);
+ break;
case 'p':
print_config = 1;
user_check = 0;
--
2.52.0
--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.