]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: add -N option for s6-style service readiness notification master
authorEmery Hemingway <emery@informatics.coop>
Thu, 9 Apr 2026 14:29:11 +0000 (14:29 +0000)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 9 Apr 2026 15:15:16 +0000 (17:15 +0200)
In this notification scheme a service supervisor creates a pipe
and passes the write file descriptor to chronyd. 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
main.c

index be34c96fd2f8a3fb8d430dbaf456fbd40da8e15b..4f5eb3c4f71b29eabe6ceaabcbf82eebf960b122 100644 (file)
@@ -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.
 
 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 *-d*
+option.
+
 *-v*, *--version*::
 With this option *chronyd* will print version number to the terminal and exit.
 
 *-v*, *--version*::
 With this option *chronyd* will print version number to the terminal and exit.
 
diff --git a/main.c b/main.c
index 9c90b585f9d215a191c4c5f8fe34bb228ffe858b..c9ddca382c308b82196a69445c3942db9e570539 100644 (file)
--- a/main.c
+++ b/main.c
@@ -70,6 +70,8 @@ static int exit_status = 0;
 
 static int reload = 0;
 
 
 static int reload = 0;
 
+static int notify_fd = 0;
+
 static REF_Mode ref_mode = REF_ModeNormal;
 
 /* ================================================== */
 static REF_Mode ref_mode = REF_ModeNormal;
 
 /* ================================================== */
@@ -110,6 +112,14 @@ delete_pidfile(void)
 static void
 notify_system_manager(int start)
 {
 static void
 notify_system_manager(int start)
 {
+  /* s6-style ready notification using a pipe from the parent */
+  if (start && notify_fd) {
+    if (write(notify_fd, "\n", 1) != 1)
+      LOG_FATAL("Could not send notification requested by -N option");
+    close(notify_fd);
+    notify_fd = 0;
+  }
+
 #ifdef LINUX
   /* The systemd protocol is documented in the sd_notify(3) man page */
   const char *message, *path = getenv("NOTIFY_SOCKET");
 #ifdef LINUX
   /* The systemd protocol is documented in the sd_notify(3) man page */
   const char *message, *path = getenv("NOTIFY_SOCKET");
@@ -454,6 +464,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"
              "  -P PRIORITY\tSet process priority (0)\n"
              "  -m\t\tLock memory\n"
              "  -x\t\tDon't control clock\n"
+             "  -N FD\t\tNotify supervisor\n"
              "  -v, --version\tPrint version and exit\n"
              "  -h, --help\tPrint usage and exit\n",
              progname, DEFAULT_CONF_FILE, DEFAULT_USER);
              "  -v, --version\tPrint version and exit\n"
              "  -h, --help\tPrint usage and exit\n",
              progname, DEFAULT_CONF_FILE, DEFAULT_USER);
@@ -512,7 +523,7 @@ int main
   optind = 1;
 
   /* Parse short command-line options */
   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':
     switch (opt) {
       case '4':
       case '6':
@@ -541,6 +552,9 @@ int main
       case 'n':
         nofork = 1;
         break;
       case 'n':
         nofork = 1;
         break;
+      case 'N':
+        notify_fd = parse_int_arg(optarg);
+        break;
       case 'p':
         print_config = 1;
         user_check = 0;
       case 'p':
         print_config = 1;
         user_check = 0;