]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add option to read RTC LOCAL/UTC setting from hwclock's adjtime file
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 11 Dec 2013 10:20:58 +0000 (11:20 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 11 Dec 2013 10:22:04 +0000 (11:22 +0100)
chrony.texi.in
conf.c
conf.h
rtc_linux.c

index 3eb2730212385138f9281c24be4ec1d37f904841..1169e7e8b93297c8fa19cc73b0ff8133e7016cce 100644 (file)
@@ -1132,6 +1132,7 @@ directives can occur in any order in the file.
 * dumponexit directive::        Dump measurements when daemon exits
 * fallbackdrift directive::     Specify fallback drift intervals
 * generatecommandkey directive:: Generate command key automatically
+* hwclockfile directive::       Specify location of hwclock's adjtime file
 * include directive::           Include a configuration file
 * initstepslew directive::      Trim the system clock on boot-up
 * keyfile directive::           Specify location of file containing keys
@@ -1644,6 +1645,20 @@ command key from the /dev/urandom file and write it to the key file.
 The generated key will use SHA1 if @code{chronyd} is compiled with the support,
 otherwise MD5 will be used.
 @c }}}
+@c {{{ hwclockfile
+@node hwclockfile directive
+@subsection hwclockfile
+The @code{hwclockfile} directive sets the location of the adjtime file which is
+used by the @file{/sbin/hwclock} program.  With this directive, @code{chronyd}
+will parse the file to find out if the RTC keeps local time or UTC.  It
+overrides the @code{rtconutc} directive (@pxref{rtconutc directive}).
+
+An example of the command is
+
+@example
+hwclockfile /etc/adjtime
+@end example
+@c }}}
 @c {{{ include
 @node include directive
 @subsection include
@@ -2705,6 +2720,9 @@ or ends.
 If the @code{rtconutc} directive appears, it means the RTC is required
 to keep UTC.  The directive takes no arguments.  It is equivalent to
 specifying the @code{-u} switch to the Linux @file{/sbin/hwclock} program.
+
+Note that this setting is overriden when the @code{hwclockfile} directive
+(@pxref{hwclockfile directive}) is used.
 @c }}}
 @c {{{ rtcsync
 @node rtcsync directive
diff --git a/conf.c b/conf.c
index fdd075178642b44b9349025be122cd9dd00e881a..0a1f9eda9735e041a3c04eb4cd825a1f90c1d6db 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -124,6 +124,9 @@ static int enable_manual=0;
    incl. daylight saving). */
 static int rtc_on_utc = 0;
 
+/* Filename used to read the hwclock(8) LOCAL/UTC setting */
+static char *hwclock_file = NULL;
+
 /* Flag set if the RTC should be automatically synchronised by kernel */
 static int rtc_sync = 0;
 
@@ -365,6 +368,8 @@ CNF_ReadFile(const char *filename)
         parse_fallbackdrift(p);
       } else if (!strcasecmp(command, "generatecommandkey")) {
         generate_command_key = parse_null(p);
+      } else if (!strcasecmp(command, "hwclockfile")) {
+        parse_string(p, &hwclock_file);
       } else if (!strcasecmp(command, "include")) {
         parse_include(p);
       } else if (!strcasecmp(command, "initstepslew")) {
@@ -1620,3 +1625,11 @@ CNF_GetMinSamples(void)
 {
   return min_samples;
 }
+
+/* ================================================== */
+
+char *
+CNF_GetHwclockFile(void)
+{
+  return hwclock_file;
+}
diff --git a/conf.h b/conf.h
index 4f6d623186fa247cb22de06633b92fe13c9959f0..957aafb4d59814a012673ee03c65eaeea5df6a8a 100644 (file)
--- a/conf.h
+++ b/conf.h
@@ -100,5 +100,6 @@ extern int CNF_GetMaxSamples(void);
 extern int CNF_GetMinSamples(void);
 
 extern double CNF_GetRtcAutotrim(void);
+extern char *CNF_GetHwclockFile(void);
 
 #endif /* GOT_CONF_H */
index d6b5f33cb4a87d5b359fbdfe4cbbd7851113494c..fe758555196b779fcdf6e9ec791343447ae360c7 100644 (file)
@@ -371,6 +371,43 @@ t_from_rtc(struct tm *stm) {
 
 /* ================================================== */
 
+static void
+read_hwclock_file(const char *hwclock_file)
+{
+  FILE *in;
+  char line[256];
+  int i;
+
+  if (!hwclock_file)
+    return;
+
+  in = fopen(hwclock_file, "r");
+  if (!in) {
+    LOG(LOGS_WARN, LOGF_RtcLinux, "Could not open hwclockfile %s",
+        hwclock_file);
+    return;
+  }
+
+  /* Read third line from the file. */
+  for (i = 0; i < 3; i++) {
+    if (!fgets(line, sizeof(line), in))
+      break;
+  }
+
+  fclose(in);
+
+  if (i == 3 && !strncmp(line, "LOCAL", 5)) {
+    rtc_on_utc = 0;
+  } else if (i == 3 && !strncmp(line, "UTC", 3)) {
+    rtc_on_utc = 1;
+  } else {
+    LOG(LOGS_WARN, LOGF_RtcLinux, "Could not read LOCAL/UTC setting from hwclockfile %s",
+        hwclock_file);
+  }
+}
+
+/* ================================================== */
+
 static void
 setup_config(void)
 {
@@ -380,6 +417,8 @@ setup_config(void)
     rtc_on_utc = 0;
   }
 
+  read_hwclock_file(CNF_GetHwclockFile());
+
   autotrim_threshold = CNF_GetRtcAutotrim();
 }