mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 06:40:08 +01:00
util/u_process: remove util_get_process_name_may_override()
Also deprecate GALLIUM_PROCESSS_NAME in favor of MESA_PROCESS_NAME, while maintaining existing functionality for use cases relying on GALLIUM_PROCESSS_NAME. GALLIUM_PROCESSS_NAME takes higher precedence over MESA_PROCESS_NAME in the case where both are set. Signed-off-by: Ryan Neph <ryanneph@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20779>
This commit is contained in:
parent
c8fe878717
commit
887ca5e1b2
5 changed files with 28 additions and 50 deletions
|
|
@ -30,14 +30,27 @@
|
|||
#define OS_PROCESS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util/u_debug.h"
|
||||
#include "util/u_process.h"
|
||||
|
||||
|
||||
static inline bool
|
||||
os_get_process_name(char *str, size_t size)
|
||||
{
|
||||
return util_get_process_name_may_override("GALLIUM_PROCESS_NAME", str, size);
|
||||
const char *process_name = debug_get_option("GALLIUM_PROCESS_NAME",
|
||||
util_get_process_name());
|
||||
if (!process_name)
|
||||
return false;
|
||||
|
||||
assert(str);
|
||||
assert(size);
|
||||
|
||||
size_t len = strnlen(process_name, size - 1);
|
||||
memcpy(str, process_name, len);
|
||||
str[len] = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -410,6 +410,16 @@ if with_tests
|
|||
env: ['BUILD_FULL_PATH='+process_test_exe_full_path]
|
||||
)
|
||||
|
||||
test(
|
||||
'process_with_overrides',
|
||||
process_test_exe,
|
||||
suite : ['util'],
|
||||
env: [
|
||||
'BUILD_FULL_PATH='+process_test_exe_full_path,
|
||||
'MESA_PROCESS_NAME=hello',
|
||||
]
|
||||
)
|
||||
|
||||
subdir('tests/hash_table')
|
||||
subdir('tests/vma')
|
||||
subdir('tests/format')
|
||||
|
|
|
|||
|
|
@ -58,19 +58,12 @@ test_util_get_process_name (void)
|
|||
const char *expected = "process_test";
|
||||
#endif
|
||||
|
||||
const char *name_override = getenv("MESA_PROCESS_NAME");
|
||||
if (name_override)
|
||||
expected = name_override;
|
||||
|
||||
const char *name = util_get_process_name();
|
||||
expect_equal_str(expected, name, "util_get_process_name");
|
||||
|
||||
/* Test util_get_process_name_may_override */
|
||||
char name_buf[PATH_MAX] = { 0 };
|
||||
util_get_process_name_may_override("TEST_MESA_OVERRIDE_PROCESS_NAME", name_buf, sizeof(name_buf));
|
||||
expect_equal_str(expected, name_buf, "util_get_process_name_may_override");
|
||||
putenv("TEST_MESA_OVERRIDE_PROCESS_NAME=hello");
|
||||
util_get_process_name_may_override("TEST_MESA_OVERRIDE_PROCESS_NAME", name_buf, sizeof(name_buf));
|
||||
expect_equal_str("hello", name_buf, "util_get_process_name_may_override");
|
||||
putenv("TEST_MESA_OVERRIDE_PROCESS_NAME=hello2");
|
||||
util_get_process_name_may_override("TEST_MESA_OVERRIDE_PROCESS_NAME", name_buf, sizeof(name_buf));
|
||||
expect_equal_str("hello2", name_buf, "util_get_process_name_may_override");
|
||||
}
|
||||
|
||||
static void posixify_path(char *path) {
|
||||
|
|
|
|||
|
|
@ -260,34 +260,6 @@ success:
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
util_get_process_name_may_override(const char *env_name, char *procname, size_t size)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* First, check if the env var with env_name is set to
|
||||
* override the normal process name query.
|
||||
*/
|
||||
name = os_get_option(env_name);
|
||||
|
||||
if (!name) {
|
||||
/* do normal query */
|
||||
name = util_get_process_name();
|
||||
}
|
||||
|
||||
assert(size > 0);
|
||||
assert(procname);
|
||||
|
||||
if (name && procname && size > 0) {
|
||||
strncpy(procname, name, size);
|
||||
procname[size - 1] = '\0';
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
util_get_command_line(char *cmdline, size_t size)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,16 +41,6 @@ util_get_process_name(void);
|
|||
size_t
|
||||
util_get_process_exec_path(char* process_path, size_t len);
|
||||
|
||||
/**
|
||||
* Return the name of the current process.
|
||||
* \param env_name the environment variable name used to override
|
||||
* \param procname returns the process name
|
||||
* \param size size of the procname buffer
|
||||
* \return true or false for success, failure
|
||||
*/
|
||||
bool
|
||||
util_get_process_name_may_override(const char *env_name, char *procname, size_t size);
|
||||
|
||||
/**
|
||||
* Return the command line for the calling process. This is basically
|
||||
* the argv[] array with the arguments separated by spaces.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue