[Mesa-dev] [PATCH v3 2/6] xmlconfig: read more config files from drirc.d/
Qiang Yu
Qiang.Yu at amd.com
Mon Aug 6 03:19:23 UTC 2018
Driver and application can put their drirc files in
${datadir}/drirc.d/ with name xxx.conf. Config files
will be read and applied in file name alphabetic order.
So there are three places for drirc listed in order:
1. /usr/share/drirc.d/
2. /etc/drirc
3. ~/.drirc
v3:
1. seperate driParseConfigFiles refine into another patch
2. fix entries[i] mem leak
v2:
drop /etc/drirc.d
Signed-off-by: Qiang Yu <Qiang.Yu at amd.com>
---
docs/autoconf.html | 7 +++++++
src/util/Makefile.am | 1 +
src/util/meson.build | 4 +++-
src/util/xmlconfig.c | 42 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/docs/autoconf.html b/docs/autoconf.html
index df243c2..0dd8a7b 100644
--- a/docs/autoconf.html
+++ b/docs/autoconf.html
@@ -94,6 +94,13 @@ Currently there's only one config file provided when dri drivers are
enabled - it's <code>drirc</code>.</p>
</dd>
+<dt><code>--datadir=DIR</code></dt>
+<dd><p>This option specifies the directory where the data files will
+be installed. The default is <code>${prefix}/share</code>.
+Currently when dri drivers are enabled, <code>drirc.d/</code> is at
+this place.</p>
+</dd>
+
<dt><code>--enable-static, --disable-shared</code></dt>
<dd><p>By default, Mesa
will build shared libraries. Either of these options will force static
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index bafb574..8d8c156 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -67,6 +67,7 @@ libxmlconfig_la_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-DSYSCONFDIR=\"$(sysconfdir)\" \
+ -DDATADIR=\"$(datadir)\" \
$(VISIBILITY_CFLAGS) \
$(EXPAT_CFLAGS)
libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm
diff --git a/src/util/meson.build b/src/util/meson.build
index 8c91be8..108524b 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -121,7 +121,9 @@ libxmlconfig = static_library(
c_args : [
c_msvc_compat_args, c_vis_args,
'-DSYSCONFDIR="@0@"'.format(
- join_paths(get_option('prefix'), get_option('sysconfdir'))
+ join_paths(get_option('prefix'), get_option('sysconfdir')),
+ '-DDATADIR="@0@"'.format(
+ join_paths(get_option('prefix'), get_option('datadir'))
),
],
build_by_default : false,
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index 50beede..f12760a 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -36,6 +36,8 @@
#include <math.h>
#include <unistd.h>
#include <errno.h>
+#include <dirent.h>
+#include <fnmatch.h>
#include "xmlconfig.h"
#include "process.h"
@@ -928,10 +930,49 @@ parseOneConfigFile(struct OptConfData *data, const char *filename)
XML_ParserFree (p);
}
+static int
+scandir_filter(const struct dirent *ent)
+{
+ if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
+ return 0;
+
+ if (fnmatch("*.conf", ent->d_name, 0))
+ return 0;
+
+ return 1;
+}
+
+/** \brief Parse configuration files in a directory */
+static void
+parseConfigDir(struct OptConfData *data, const char *dirname)
+{
+ int i, count;
+ struct dirent **entries = NULL;
+
+ count = scandir(dirname, &entries, scandir_filter, alphasort);
+ if (count < 0)
+ return;
+
+ for (i = 0; i < count; i++) {
+ char filename[PATH_MAX];
+
+ snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name);
+ free(entries[i]);
+
+ parseOneConfigFile(data, filename);
+ }
+
+ free(entries);
+}
+
#ifndef SYSCONFDIR
#define SYSCONFDIR "/etc"
#endif
+#ifndef DATADIR
+#define DATADIR "/usr/share"
+#endif
+
void
driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
int screenNum, const char *driverName)
@@ -946,6 +987,7 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
userData.driverName = driverName;
userData.execName = util_get_process_name();
+ parseConfigDir(&userData, DATADIR "/drirc.d");
parseOneConfigFile(&userData, SYSCONFDIR "/drirc");
if ((home = getenv ("HOME"))) {
--
2.7.4
More information about the mesa-dev
mailing list