From 789a17690ebc4523d7e91e5a26cbef2d8a77973e Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 8 Jan 2025 15:51:25 +0100 Subject: [PATCH] tree: Add env variables for x-d-p binaries to wait for a debugger This is especially useful when the binaries are run as part of a test and getting the debugger to the right place takes a bit of effort. --- document-portal/document-portal.c | 13 +++++++++++++ document-portal/permission-store.c | 13 +++++++++++++ src/xdg-desktop-portal.c | 13 +++++++++++++ tests/README.md | 9 +++++++++ 4 files changed, 48 insertions(+) diff --git a/document-portal/document-portal.c b/document-portal/document-portal.c index 196106be5..023595a69 100644 --- a/document-portal/document-portal.c +++ b/document-portal/document-portal.c @@ -1719,6 +1719,19 @@ main (int argc, g_autoptr(GOptionContext) context = NULL; GDBusMethodInvocation *invocation; + if (g_getenv ("XDG_DOCUMENT_PORTAL_WAIT_FOR_DEBUGGER") != NULL) + { + g_printerr ("document portal is waiting for debugger: %d\n", getpid ()); + + if (raise (SIGSTOP) == -1) + { + g_printerr ("Failed waiting for debugger\n"); + exit (1); + } + + raise (SIGCONT); + } + g_log_writer_default_set_use_stderr (TRUE); setlocale (LC_ALL, ""); diff --git a/document-portal/permission-store.c b/document-portal/permission-store.c index e1106d38a..f7c02718b 100644 --- a/document-portal/permission-store.c +++ b/document-portal/permission-store.c @@ -92,6 +92,19 @@ main (int argc, GOptionContext *context; g_autoptr(GError) error = NULL; + if (g_getenv ("XDG_PERMISSION_STORE_WAIT_FOR_DEBUGGER") != NULL) + { + g_printerr ("permission store is waiting for debugger: %d\n", getpid ()); + + if (raise (SIGSTOP) == -1) + { + g_printerr ("Failed waiting for debugger\n"); + exit (1); + } + + raise (SIGCONT); + } + g_log_writer_default_set_use_stderr (TRUE); setlocale (LC_ALL, ""); diff --git a/src/xdg-desktop-portal.c b/src/xdg-desktop-portal.c index 396ee2438..1cbb8cdd8 100644 --- a/src/xdg-desktop-portal.c +++ b/src/xdg-desktop-portal.c @@ -406,6 +406,19 @@ main (int argc, char *argv[]) g_autoptr(GSource) signal_handler_source = NULL; g_autoptr(GOptionContext) context = NULL; + if (g_getenv ("XDG_DESKTOP_PORTAL_WAIT_FOR_DEBUGGER") != NULL) + { + g_printerr ("desktop portal is waiting for debugger: %d\n", getpid ()); + + if (raise (SIGSTOP) == -1) + { + g_printerr ("Failed waiting for debugger\n"); + exit (1); + } + + raise (SIGCONT); + } + setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); diff --git a/tests/README.md b/tests/README.md index a0ac5b19d..eabc89544 100644 --- a/tests/README.md +++ b/tests/README.md @@ -29,6 +29,15 @@ but should not normally be set on production systems: * `XDP_VALIDATE_SOUND_INSECURE`: Same as `XDP_VALIDATE_ICON_INSECURE`, but for sounds +* `XDG_DESKTOP_PORTAL_WAIT_FOR_DEBUGGER`: Makes xdg-desktop-portal wait for + a debugger to attach by raising SIGSTOP + +* `XDG_DOCUMENT_PORTAL_WAIT_FOR_DEBUGGER`: Makes xdg-document-portal wait + for a debugger to attach by raising SIGSTOP + +* `XDG_PERMISSION_STORE_WAIT_FOR_DEBUGGER`: Makes xdg-permission-store wait + for a debugger to attach by raising SIGSTOP + ### Used automatically These environment variables are set automatically and shouldn't need to be