diff options
| author | Kyle Brenneman <kbrenneman@nvidia.com> | 2024-09-17 17:27:37 -0600 |
|---|---|---|
| committer | Daniel Stone <daniels@collabora.com> | 2025-09-15 14:45:53 +0100 |
| commit | 77730f10a0eaac1c654d1bdc689783292bdb5f2d (patch) | |
| tree | efd3d2d8d37534f519f49d5971168782befbdf16 | |
| parent | cursor: Free theme when size check fails to avoid memory leak (diff) | |
| download | wayland-77730f10a0eaac1c654d1bdc689783292bdb5f2d.tar wayland-77730f10a0eaac1c654d1bdc689783292bdb5f2d.tar.gz wayland-77730f10a0eaac1c654d1bdc689783292bdb5f2d.tar.bz2 wayland-77730f10a0eaac1c654d1bdc689783292bdb5f2d.tar.lz wayland-77730f10a0eaac1c654d1bdc689783292bdb5f2d.tar.xz wayland-77730f10a0eaac1c654d1bdc689783292bdb5f2d.tar.zst wayland-77730f10a0eaac1c654d1bdc689783292bdb5f2d.zip | |
connection: Add a function to parse WAYLAND_DEBUG tokens
Add a new function, wl_check_env_token, to scan for a token in a
comma-separated string.
Change wl_display_create in wayland-server.c and
wl_display_connect_to_fd in wayland-client.c to use that instead of a
simple substring search.
This means that WAYLAND_DEBUG will accept a value like "client,server"
but not "clientserver". But, this will make it easier to add other
tokens without worrying about overlap between them.
Signed-off-by: Kyle Brenneman <kbrenneman@nvidia.com>
| -rw-r--r-- | src/connection.c | 42 | ||||
| -rw-r--r-- | src/wayland-client.c | 2 | ||||
| -rw-r--r-- | src/wayland-private.h | 3 | ||||
| -rw-r--r-- | src/wayland-server.c | 2 |
4 files changed, 47 insertions, 2 deletions
diff --git a/src/connection.c b/src/connection.c index 593f52f..9c6a6b0 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1491,6 +1491,48 @@ wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection) return result; } +bool +wl_check_env_token(const char *env, const char *token) +{ + const char *ptr = env; + size_t token_len; + + if (env == NULL) + return false; + + token_len = strlen(token); + + // Scan the string for comma-separated tokens and look for a match. + while (true) { + const char *end; + size_t len; + + // Skip over any leading separators. + while (*ptr == ',') + ptr++; + + if (*ptr == '\x00') + return false; + + end = strchr(ptr + 1, ','); + + // If there isn't another separarator, then the rest of the string + // is one token. + if (end == NULL) + return (strcmp(ptr, token) == 0); + + len = end - ptr; + if (len == token_len && memcmp(ptr, token, len) == 0) { + return true; + } + + // Skip to the next token. + ptr += len; + } + + return false; +} + void wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send, int discarded, uint32_t (*n_parse)(union wl_argument *arg), diff --git a/src/wayland-client.c b/src/wayland-client.c index c863304..c0b361f 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -1236,7 +1236,7 @@ wl_display_connect_to_fd(int fd) no_color = getenv("NO_COLOR"); force_color = getenv("FORCE_COLOR"); debug = getenv("WAYLAND_DEBUG"); - if (debug && (strstr(debug, "client") || strstr(debug, "1"))) { + if (debug && (wl_check_env_token(debug, "client") || wl_check_env_token(debug, "1"))) { debug_client = 1; if (isatty(fileno(stderr))) debug_color = 1; diff --git a/src/wayland-private.h b/src/wayland-private.h index d7ba9da..d0e4cfc 100644 --- a/src/wayland-private.h +++ b/src/wayland-private.h @@ -237,6 +237,9 @@ wl_closure_send(struct wl_closure *closure, struct wl_connection *connection); int wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection); +bool +wl_check_env_token(const char *env, const char *token); + void wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send, int discarded, diff --git a/src/wayland-server.c b/src/wayland-server.c index 482743b..c81d98f 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -1198,7 +1198,7 @@ wl_display_create(void) no_color = getenv("NO_COLOR"); force_color = getenv("FORCE_COLOR"); debug = getenv("WAYLAND_DEBUG"); - if (debug && (strstr(debug, "server") || strstr(debug, "1"))) { + if (debug && (wl_check_env_token(debug, "server") || wl_check_env_token(debug, "1"))) { debug_server = 1; if (isatty(fileno(stderr))) debug_color = 1; |
