]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add common refclock driver option parsing
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Jan 2010 08:14:42 +0000 (09:14 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Jan 2010 09:10:16 +0000 (10:10 +0100)
chrony.texi
refclock.c
refclock.h
refclock_pps.c

index db48bc39f4306c124a977290141d4a7c78db85ee..b0235cda1cef8519e8dc43e5256f0ab1f23c5d4f 100644 (file)
@@ -2229,8 +2229,8 @@ There are currently three drivers implemented:
 @table @code
 @item PPS
 Pulse per second (PPS) API driver.  The parameter is a path to the PPS
-device.  Assert events are used by default.  The path can have
-:1 appended to use clear events instead.
+device.  Assert events are used by default.  Driver option
+@code{:clear} can be appended to the path to use clear events instead.
 
 PPS refclock needs another source (NTP or non-PPS refclock) or local
 directive (@pxref{local directive}) enabled to function.  For example:
index 0a9473a93e1bc8a693279d5e21701de9b1e9e1fc..ddbc0751dcb392174708485663eca0fe6088a60f 100644 (file)
@@ -58,6 +58,7 @@ struct RCL_Instance_Record {
   RefclockDriver *driver;
   void *data;
   char *driver_parameter;
+  int driver_parameter_length;
   int driver_poll;
   int driver_polled;
   int poll;
@@ -169,6 +170,7 @@ RCL_AddRefclock(RefclockParameters *params)
 
   inst->data = NULL;
   inst->driver_parameter = params->driver_parameter;
+  inst->driver_parameter_length = 0;
   inst->driver_poll = params->driver_poll;
   inst->poll = params->poll;
   inst->missed_samples = 0;
@@ -181,6 +183,15 @@ RCL_AddRefclock(RefclockParameters *params)
   inst->timeout_id = -1;
   inst->source = NULL;
 
+  if (inst->driver_parameter) {
+    int i;
+
+    inst->driver_parameter_length = strlen(inst->driver_parameter);
+    for (i = 0; i < inst->driver_parameter_length; i++)
+      if (inst->driver_parameter[i] == ':')
+        inst->driver_parameter[i] = '\0';
+  }
+
   if (pps_source) {
     if (inst->pps_rate < 1)
       inst->pps_rate = 1;
@@ -278,6 +289,31 @@ RCL_GetDriverParameter(RCL_Instance instance)
   return instance->driver_parameter;
 }
 
+char *
+RCL_GetDriverOption(RCL_Instance instance, char *name)
+{
+  char *s, *e;
+  int n;
+
+  s = instance->driver_parameter;
+  e = s + instance->driver_parameter_length;
+  n = strlen(name);
+
+  while (1) {
+    s += strlen(s) + 1;
+    if (s >= e)
+      break;
+    if (!strncmp(name, s, n)) {
+      if (s[n] == '=')
+        return s + n + 1;
+      if (s[n] == '\0')
+        return s + n;
+    }
+  }
+
+  return NULL;
+}
+
 int
 RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status)
 {
index f6fb6aa892ce72afe531ec17b8d19b6a5b63def6..a9ab0ae75dda99beacc6971f44ae8cce082110fe 100644 (file)
@@ -64,6 +64,7 @@ extern void RCL_CycleLogFile(void);
 extern void RCL_SetDriverData(RCL_Instance instance, void *data);
 extern void *RCL_GetDriverData(RCL_Instance instance);
 extern char *RCL_GetDriverParameter(RCL_Instance instance);
+extern char *RCL_GetDriverOption(RCL_Instance instance, char *name);
 extern int RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status);
 extern int RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second);
 
index b41d194caea2109e4bb94bd435e99dfeb85b50cb..68d5e6ae246ae5a0a9fdc31f91a3fae7926c5262 100644 (file)
@@ -46,15 +46,10 @@ static int pps_initialise(RCL_Instance instance) {
   pps_params_t params;
   struct pps_instance *pps;
   int fd, edge_clear, mode;
-  char *path, *s;
+  char *path;
 
   path = RCL_GetDriverParameter(instance);
-
-  edge_clear = 0;
-  if ((s = strrchr(path, ':')) != NULL) {
-    *s = '\0';
-    edge_clear = atoi(s + 1);
-  }
+  edge_clear = RCL_GetDriverOption(instance, "clear") ? 1 : 0;
 
   fd = open(path, O_RDWR);
   if (fd < 0) {