[chrony-dev] [RFC PATCH v1 16/17] configure, conf, main, doc/chrony.conf: Add configuration directive for 'auxclockidfile'

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


Write the allocated clock ID to auxclockidfile when Chrony is configured to dynamically allocate an
auxiliary clock. A default auxclockidfile name 'chronyd.clkid' is configured at compile time. It is
located in the same directory as chronyd.pid. The file location can be overridden by the
auxclockidfile directive. The clock ID written to the file is used as the first argument to
clock_gettime() to read the time for the allocated auxiliary clock. This file does not get written
if an auxilliary clock is pre-allocated outside Chrony.
---
 conf.c               | 37 +++++++++++++++++++++++++++++++++++++
 conf.h               |  1 +
 configure            |  4 ++++
 doc/chrony.conf.adoc |  9 +++++++++
 main.c               | 43 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 94 insertions(+)

diff --git a/conf.c b/conf.c
index 5e99d98..7698df9 100644
--- a/conf.c
+++ b/conf.c
@@ -65,6 +65,7 @@ static void parse_ints(char *line, ARR_Instance array, int min, int max);
 
 #ifdef FEAT_AUXCLOCK
 static void parse_auxclockid(char *line, int *enable, int *clockid);
+static void parse_auxclockid_file(char *line);
 #endif
 static void parse_allow_deny(char *line, ARR_Instance restrictions, int allow);
 static void parse_authselectmode(char *);
@@ -243,6 +244,12 @@ static char *ntp_signd_socket = NULL;
  * chronyds being started. */
 static char *pidfile = NULL;
 
+/* Filename to use for storing dynamically allocated auxilliary clock ID of
+ * running chronyd */
+#ifdef FEAT_AUXCLOCK
+static char *auxclockid_file = NULL;
+#endif
+
 /* Rate limiting parameters */
 static int ntp_ratelimit_enabled = 0;
 static int ntp_ratelimit_interval = 3;
@@ -478,6 +485,9 @@ CNF_Initialise(int r, int client_only)
   } else {
     bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
     pidfile = Strdup(DEFAULT_PID_FILE);
+#ifdef FEAT_AUXCLOCK
+    auxclockid_file = Strdup(DEFAULT_AUXCLOCKID_FILE);
+#endif
   }
 
   SCK_GetAnyLocalIPAddress(IPADDR_INET4, &bind_address4);
@@ -531,6 +541,9 @@ CNF_Finalise(void)
   ARR_DestroyInstance(nts_trusted_certs_paths);
   ARR_DestroyInstance(nts_trusted_certs_ids);
 
+#ifdef FEAT_AUXCLOCK
+  free(auxclockid_file);
+#endif
   Free(drift_file);
   Free(dumpdir);
   Free(hwclock_file);
@@ -628,6 +641,8 @@ CNF_ParseLine(const char *filename, int number, char *line)
 #ifdef FEAT_AUXCLOCK
   } else if (!strcasecmp(command, "auxclockid")) {
     parse_auxclockid(p, &use_auxclock, &auxclock_id);
+  } else if (!strcasecmp(command, "auxclockidfile")) {
+    parse_auxclockid_file(p);
 #endif
   } else if (!strcasecmp(command, "bindacqaddress")) {
     parse_bindacqaddress(p);
@@ -1742,6 +1757,20 @@ static void parse_auxclockid(char *subcmd, int *enable, int *clockid)
   }
 }
 
+/* ================================================== */
+
+static void
+parse_auxclockid_file(char *line)
+{
+  parse_string(line, &auxclockid_file);
+
+  /* / disables the clock ID file handling */
+  if (strcmp(auxclockid_file, "/") == 0) {
+    Free(auxclockid_file);
+    auxclockid_file = NULL;
+  }
+}
+
 #endif /* FEAT_AUXCLOCK */
 
 /* ================================================== */
@@ -3062,6 +3091,14 @@ CNF_FreeAuxClockId(void)
 
 /* ================================================== */
 
+const char*
+CNF_GetAuxClockIdFile()
+{
+  return auxclockid_file;
+}
+
+/* ================================================== */
+
 const int*
 CNF_GetAuxClockId()
 {
diff --git a/conf.h b/conf.h
index 88621b9..2f351db 100644
--- a/conf.h
+++ b/conf.h
@@ -184,6 +184,7 @@ extern int CNF_GetNoCertTimeCheck(void);
 extern int CNF_GetOffsetSanityCheck(void);
 #ifdef FEAT_AUXCLOCK
 extern const int *CNF_GetAuxClockId(void);
+extern const char *CNF_GetAuxClockIdFile(void);
 extern int CNF_GetAuxClockDynamic(void);
 extern void CNF_FreeAuxClockId(void);
 #endif
diff --git a/configure b/configure
index c6e3373..0498c58 100755
--- a/configure
+++ b/configure
@@ -1081,6 +1081,7 @@ if [ $feat_auxclock = "1" ] && [ $try_auxclock = "1" ] &&
      test_code 'Linux auxiliary clock support' 'linux/time.h assert.h' '' '' \
      'assert (CLOCK_AUX_LAST == (CLOCK_AUX + MAX_AUX_CLOCKS - 1));'; then
    add_def FEAT_AUXCLOCK
+   DEFAULT_AUXCLOCKID_FILE="chronyd.clkid"
 fi
 
 SYSCONFDIR=/etc
@@ -1146,6 +1147,9 @@ add_def DEFAULT_USER "\"$default_user\""
 add_def DEFAULT_CHRONYC_USER "\"$default_chronyc_user\""
 add_def DEFAULT_COMMAND_SOCKET "\"$CHRONYRUNDIR/chronyd.sock\""
 add_def MAIL_PROGRAM "\"$mail_program\""
+if [ "x$DEFAULT_AUXCLOCKID_FILE" != "x" ]; then
+  add_def DEFAULT_AUXCLOCKID_FILE "\"$CHRONYRUNDIR/$DEFAULT_AUXCLOCKID_FILE\""
+fi
 
 common_features="`get_features SECHASH IPV6 DEBUG`"
 chronyc_features="`get_features READLINE`"
diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc
index bc1d85c..63acaf2 100644
--- a/doc/chrony.conf.adoc
+++ b/doc/chrony.conf.adoc
@@ -1590,6 +1590,8 @@ at startup and frees that clock ID on exit
 ----
 auxclockid alloc
 ----
+The dynamically allocated clock ID, is found in the file specified by _auxclockidfile_
+directive (See _auxclockidfile_)
 
 [[nooffsetsanitycheck]]
 *nooffsetsanitycheck* ::
@@ -1599,6 +1601,13 @@ assuming that the reference clock is traceable to UTC/TAI. This check can be dis
 platform, but is most useful when working with Linux auxiliary clocks whose time is not required
 to be traceable. There are no options for this directive.
 
+[[auxclockidfile]]
+*auxclockidfile* _file_::
+The *auxclockidfile* directive is used to set the filename where Chrony writes the dynamically
+allocated auxiliary clock ID. The clock ID written to the file is used as the first argument
+for clock_gettime() to get the time for the auxiliary clock. The clock ID is written out only
+when the configuration requests dynamic clock allocation.
+
 === NTP server
 
 [[allow]]*allow* [*all*] [_subnet_]::
diff --git a/main.c b/main.c
index 97eaf8d..d470faa 100644
--- a/main.c
+++ b/main.c
@@ -134,6 +134,41 @@ notify_system_manager(int start)
 
 /* ================================================== */
 
+#ifdef FEAT_AUXCLOCK
+
+static void
+write_auxclockid_file(void)
+{
+  const char *auxclockid_file = CNF_GetAuxClockIdFile();
+  FILE *out;
+
+  if (!auxclockid_file || !CNF_GetAuxClockDynamic())
+    return;
+
+  if((out = UTI_OpenFile(NULL, auxclockid_file, NULL, 'W', 0644))) {
+    fprintf(out, "%d\n", *CNF_GetAuxClockId());
+    fclose(out);
+  }
+}
+
+/* ================================================== */
+
+static void
+delete_auxclockid_file(void)
+{
+  const char *auxclockid_file = CNF_GetAuxClockIdFile();
+
+  if (!auxclockid_file || !CNF_GetAuxClockDynamic())
+    return;
+
+  if (!UTI_RemoveFile(NULL, auxclockid_file, NULL))
+    ;
+}
+
+#endif
+
+/* ================================================== */
+
 void
 MAI_SystemCleanup(void)
 {
@@ -184,6 +219,9 @@ MAI_CleanupAndExit(void)
   PRV_Finalise();
 
   delete_pidfile();
+#ifdef FEAT_AUXCLOCK
+  delete_auxclockid_file();
+#endif
   
   UTI_CallSystemCleanupHandler();
   CNF_Finalise();
@@ -663,6 +701,11 @@ int main
   /* Write our pidfile to prevent other instances from running */
   write_pidfile();
 
+#ifdef FEAT_AUXCLOCK
+  /* Write out auxilliary clock ID */
+  write_auxclockid_file();
+#endif
+
   PRV_Initialise();
   LCL_Initialise();
   SCH_Initialise();
-- 
2.34.1


-- 
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.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/