]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: rework local directive to have default stratum
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 30 Mar 2016 13:58:45 +0000 (15:58 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 31 Mar 2016 14:01:06 +0000 (16:01 +0200)
Allow the local directive to be specified without the stratum field.
It's an option now, with default value 10. Also, move the parsing code
to cmdparse.c to make it available to the client.

cmdparse.c
cmdparse.h
conf.c

index 591e2e46411f52049debf97411cc4b6349bcf250..a24324fd9d1cc966cae137589cc0ab77f50edd43 100644 (file)
@@ -223,6 +223,32 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
 
 /* ================================================== */
 
+int
+CPS_ParseLocal(char *line, int *stratum)
+{
+  int n;
+  char *cmd;
+
+  *stratum = 10;
+
+  while (*line) {
+    cmd = line;
+    line = CPS_SplitWord(line);
+
+    if (!strcasecmp(cmd, "stratum")) {
+      if (sscanf(line, "%d%n", stratum, &n) != 1)
+        return 0;
+    } else {
+      return 0;
+    }
+
+    line += n;
+  }
+
+  return 1;
+}
+/* ================================================== */
+
 void
 CPS_StatusToString(CPS_Status status, char *dest, int len)
 {
index 3d18adec6f3328b23680d7f9a783ed2d5a0e9794..eb1714dbfd87aef982190610bcc4615ac0742636 100644 (file)
@@ -59,6 +59,9 @@ typedef struct {
 /* Parse a command to add an NTP server or peer */
 extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
   
+/* Parse a command to enable local reference */
+extern int CPS_ParseLocal(char *line, int *stratum);
+
 /* Get a string describing error status */
 extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
 
diff --git a/conf.c b/conf.c
index b7c3ddc7f418364e150636da76e03b952aa875a9..d989a5e03c39b70d429c451841bd32ecb6e7e91f 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -817,13 +817,9 @@ parse_log(char *line)
 static void
 parse_local(char *line)
 {
-  int stratum;
-  if (sscanf(line, "stratum%d", &stratum) == 1) {
-    local_stratum = stratum;
-    enable_local = 1;
-  } else {
+  if (!CPS_ParseLocal(line, &local_stratum))
     command_parse_error();
-  }
+  enable_local = 1;
 }
 
 /* ================================================== */