[Mesa-dev] [PATCH v2 2/2] mesa: load a user defined drirc file specified via an environment variable
Gustaw Smolarczyk
wielkiegie at gmail.com
Mon Mar 27 20:27:12 UTC 2017
2017-03-27 21:59 GMT+02:00 Edmondo Tommasina <edmondo.tommasina at gmail.com>:
> 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);
strdup?
And maybe skip this entirely when userDrirc[0] == '\0'? So that
filenames[1] stays as NULL. Of course this should skip also the else
branch below so that userDrirc != NULL && *userDrirc == '\0' would
skip the custom drirc.
Gustaw
More information about the mesa-dev
mailing list