]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: allow wildcard patterns in include directive
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 24 Aug 2015 13:08:39 +0000 (15:08 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 24 Aug 2015 13:25:02 +0000 (15:25 +0200)
Use glob() to match and read multiple configuration files with one
include directive.

chrony.texi.in
conf.c
sysincl.h

index 0b31bb666b277289d9d05e6d15724060b47971d4..d44399ad4bfd24e5dc315544c714e9a1b9900871 100644 (file)
@@ -1668,12 +1668,15 @@ hwclockfile /etc/adjtime
 @c {{{ include
 @node include directive
 @subsection include
-The @code{include} directive includes a specified configuration file.
-This is useful when maintaining configuration on multiple hosts to
-keep the differences in a separate file.
+The @code{include} directive includes a specified configuration file or
+multiple configuration files when a wildcard pattern is specified.  This can be
+useful when maintaining configuration on multiple hosts to keep the differences
+in separate files.
+
+An example of the command is
 
 @example
-include @SYSCONFDIR@/chrony/local.conf
+include @SYSCONFDIR@/chrony.d/*.conf
 @end example
 @c }}}
 @c {{{ initstepslew
diff --git a/conf.c b/conf.c
index 1613bcbe2db84c5fb9cdc3db7ec67586dd9123e4..0d58b0eecb8456edec314d9f1cb74c5ebef0ea23 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -1236,8 +1236,20 @@ parse_tempcomp(char *line)
 static void
 parse_include(char *line)
 {
+  glob_t gl;
+  size_t i;
+
   check_number_of_args(line, 1);
-  CNF_ReadFile(line);
+
+  if (glob(line, 0, NULL, &gl)) {
+    DEBUG_LOG(LOGF_Configure, "glob of %s failed", line);
+    return;
+  }
+
+  for (i = 0; i < gl.gl_pathc; i++)
+    CNF_ReadFile(gl.gl_pathv[i]);
+
+  globfree(&gl);
 }
 
 /* ================================================== */
index 81ae97e56ededd4718c8fd18629655ddb8177ace..4976e97c7687af6b28d874a99f53d420d6ea9fe6 100644 (file)
--- a/sysincl.h
+++ b/sysincl.h
@@ -39,6 +39,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <float.h>
+#include <glob.h>
 #if !defined(__FreeBSD__) && !defined(MACOSX)
 #include <malloc.h>
 #endif