Skip to content

Commit

Permalink
tree: Add env variables for x-d-p binaries to wait for a debugger
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
swick committed Jan 8, 2025
1 parent cb16d56 commit 789a176
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions document-portal/document-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down
13 changes: 13 additions & 0 deletions document-portal/permission-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down
13 changes: 13 additions & 0 deletions src/xdg-desktop-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 789a176

Please sign in to comment.