util/xmlconfig: add new sha1 application attribute

This is useful to enable workarounds for applications with a generic name.

For instance all games made with the YoYo game engine have the same executable
name "runner".

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4181>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2020-03-16 10:49:45 +01:00
parent f8f1413070
commit 8f48e7b1e9
2 changed files with 30 additions and 2 deletions

View File

@ -34,7 +34,8 @@ TODO: document the other workarounds.
<!ATTLIST device driver CDATA #IMPLIED>
<!ELEMENT application (option+)>
<!ATTLIST application name CDATA #REQUIRED
executable CDATA #REQUIRED>
executable CDATA #REQUIRED
sha1 CDATA #IMPLIED>
<!ELEMENT engine (option+)>
<!-- engine_name_match: A regexp matching the engine name -->

View File

@ -46,6 +46,7 @@
#include "strndup.h"
#include "xmlconfig.h"
#include "u_process.h"
#include "os_file.h"
/* For systems like Hurd */
#ifndef PATH_MAX
@ -780,13 +781,39 @@ parseAppAttr(struct OptConfData *data, const XML_Char **attr)
{
uint32_t i;
const XML_Char *exec = NULL;
const XML_Char *sha1 = NULL;
for (i = 0; attr[i]; i += 2) {
if (!strcmp (attr[i], "name")) /* not needed here */;
else if (!strcmp (attr[i], "executable")) exec = attr[i+1];
else if (!strcmp (attr[i], "sha1")) sha1 = attr[i+1];
else XML_WARNING("unknown application attribute: %s.", attr[i]);
}
if (exec && strcmp (exec, data->execName))
if (exec && strcmp (exec, data->execName)) {
data->ignoringApp = data->inApp;
} else if (sha1) {
if (strlen(sha1) != 40) {
XML_WARNING("Incorrect sha1 application attribute");
data->ignoringApp = data->inApp;
} else {
size_t len;
char* content;
char path[PATH_MAX];
if (util_get_process_exec_path(path, ARRAY_SIZE(path)) > 0 &&
(content = os_read_file(path, &len))) {
uint8_t sha1x[20];
char sha1s[40];
_mesa_sha1_compute(content, len, sha1x);
_mesa_sha1_format((char*) sha1s, sha1x);
free(content);
if (memcmp(sha1, sha1s, SHA1_DIGEST_LENGTH)) {
data->ignoringApp = data->inApp;
}
} else {
data->ignoringApp = data->inApp;
}
}
}
}
/** \brief Parse attributes of an application element. */