BACKPORT: util/xmlconfig: add MESA_DRICONF_EXECUTABLE_OVERRIDE

Allow the loading process to affect driconf option matching without
changing the behavior throughout mesa common code or leaking the name of
the loading process to logs, artifact storage, or in sub-thread naming,
as can be the case with the broader MESA_PROCESS_NAME override.

This new MESA_DRICONF_EXECUTABLE_OVERRIDE takes higher precedence over
MESA_PROCESS_NAME in the case where both are set.

Backport notes:
* changed formatting of docs/envvars.rst to conform to old conventions
* added `#include "os_misc.h"`

BUG=b:266008251
TEST=vkcube in VM; check host-visible thread names

Change-Id: Ifc64a935163d816f7c82e5f6b9a50b63f2c5ee41
Signed-off-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20779>
(cherry picked from commit 65adf0c0af5b91f7ea3a9754556540ede40d9c14)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/mesa/+/4220891
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
diff --git a/docs/envvars.rst b/docs/envvars.rst
index 56550ec..b15b545 100644
--- a/docs/envvars.rst
+++ b/docs/envvars.rst
@@ -136,6 +136,12 @@
    integers, such as ``130``. Mesa will not really implement all the
    features of the given language version if it's higher than what's
    normally reported. (for developers only)
+
+:envvar:`MESA_DRICONF_EXECUTABLE_OVERRIDE`
+   if set, overrides the "executable" string used specifically for driconf
+   option matching. This takes higher precedence over more general process
+   name override (e.g. MESA_PROCESS_NAME).
+
 :envvar:`MESA_SHADER_CACHE_DISABLE`
    if set to ``true``, disables the on-disk shader cache. If set to
    ``false``, enables the on-disk shader cache when it is disabled by
diff --git a/src/util/tests/xmlconfig.cpp b/src/util/tests/xmlconfig.cpp
index 377d598..62170a5 100644
--- a/src/util/tests/xmlconfig.cpp
+++ b/src/util/tests/xmlconfig.cpp
@@ -288,4 +288,15 @@
    EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 7);
    driDestroyOptionCache(&cache);
 }
+
+TEST_F(xmlconfig_test, drirc_exec_override)
+{
+   putenv("MESA_DRICONF_EXECUTABLE_OVERRIDE=app1");
+   driOptionCache cache = drirc_init("driver", "drm",
+                                     NULL,
+                                     NULL, 0,
+                                     NULL, 0);
+   EXPECT_EQ(driQueryOptioni(&cache, "mesa_drirc_option"), 1);
+   driDestroyOptionCache(&cache);
+}
 #endif
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index 491dc4b..6d7db81 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -59,6 +59,7 @@
 #include "strndup.h"
 #include "u_process.h"
 #include "os_file.h"
+#include "os_misc.h"
 
 /* For systems like Hurd */
 #ifndef PATH_MAX
@@ -1194,6 +1195,11 @@
    initOptionCache(cache, info);
    struct OptConfData userData = {0};
 
+   if (!execname)
+      execname = os_get_option("MESA_DRICONF_EXECUTABLE_OVERRIDE");
+   if (!execname)
+      execname = util_get_process_name();
+
    userData.cache = cache;
    userData.screenNum = screenNum;
    userData.driverName = driverName;
@@ -1203,7 +1209,7 @@
    userData.applicationVersion = applicationVersion;
    userData.engineName = engineName ? engineName : "";
    userData.engineVersion = engineVersion;
-   userData.execName = execname ? execname : util_get_process_name();
+   userData.execName = execname;
 
 #if WITH_XMLCONFIG
    char *home;