Introduce a new MESA_USER_DRIRC environment variable to load a customized drirc file.
This can be used mostly for two things: 1. Force the load of a different user drirc configuration for an application without touching/creating a user global ${HOME}/.drirc file or passing their values through a list of env variables. 2. Avoid the load of the ${HOME}/.drirc file and ensure that only the system /etc/drirc file is used. Examples: 1. Set the variable to a file to load it instead of ${HOME}/.drirc: MESA_USER_DRIRC=~/glthread.drirc glxgears 2. Set the variable to an empty string to avoid the load of the user defined ${HOME}/.drirc file (if it exists): MESA_USER_DRIRC="" glxgears v2: - extend the documentation of the envvar usage (Gustaw) - describe usefulness of the envvar in commit message (Eric) --- docs/envvars.html | 7 +++++++ src/mesa/drivers/dri/common/xmlconfig.c | 26 +++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/docs/envvars.html b/docs/envvars.html index 653736565e..44a5ef6c74 100644 --- a/docs/envvars.html +++ b/docs/envvars.html @@ -130,6 +130,13 @@ that variable is set), or else within .cache/mesa within the user's home directory. <li>MESA_GLSL - <a href="shading.html#envvars">shading language compiler options</a> <li>MESA_NO_MINMAX_CACHE - when set, the minmax index cache is globally disabled. +<li>MESA_USER_DRIRC - load a user defined drirc file, instead of the default +.drirc file in the user home directory. Setting the variable to an empty +string will also avoid to load the default user .drirc file. Examples: +<ul> + <li>MESA_USER_DRIRC="/tmp/special.drirc" loads a special config file + <li>MESA_USER_DRIRC="" skips the load of the default ${HOME}/.drirc +</ul> </ul> diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c index fef007996e..dd4b46f3a4 100644 --- a/src/mesa/drivers/dri/common/xmlconfig.c +++ b/src/mesa/drivers/dri/common/xmlconfig.c @@ -988,7 +988,6 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, int screenNum, const char *driverName) { char *filenames[2] = { SYSCONFDIR "/drirc", NULL}; - char *home; uint32_t i; struct OptConfData userData; @@ -999,14 +998,23 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, userData.driverName = driverName; userData.execName = GET_PROGRAM_NAME(); - if ((home = getenv ("HOME"))) { - uint32_t len = strlen (home); - filenames[1] = malloc(len + 7+1); - if (filenames[1] == NULL) - __driUtilMessage ("Can't allocate memory for %s/.drirc.", home); - else { - memcpy (filenames[1], home, len); - memcpy (filenames[1] + len, "/.drirc", 7+1); + const char *userDrirc = getenv("MESA_USER_DRIRC"); + + if (userDrirc) { + filenames[1] = malloc(strlen(userDrirc) + 1); + strcpy(filenames[1], userDrirc); + } + else { + const char *home = getenv("HOME"); + if (home) { + uint32_t len = strlen (home); + filenames[1] = malloc(len + 7+1); + if (filenames[1] == NULL) + __driUtilMessage ("Can't allocate memory for %s/.drirc.", home); + else { + memcpy (filenames[1], home, len); + memcpy (filenames[1] + len, "/.drirc", 7+1); + } } } -- 2.11.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev