mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
test: detect if we're running through gdb and disable forking mode
This commit is contained in:
parent
dc5751b569
commit
9bc840efe2
1 changed files with 30 additions and 1 deletions
|
|
@ -40,6 +40,7 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
|
#include <sys/ptrace.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
|
|
@ -1115,6 +1116,34 @@ static void list_tests(struct pwtest_context *ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_debugger_attached(void)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
bool rc;
|
||||||
|
int pid = fork();
|
||||||
|
|
||||||
|
if (pid == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
int ppid = getppid();
|
||||||
|
if (ptrace(PTRACE_ATTACH, ppid, NULL, 0) == 0) {
|
||||||
|
waitpid(ppid, NULL, 0);
|
||||||
|
ptrace(PTRACE_CONT, ppid, NULL, 0);
|
||||||
|
ptrace(PTRACE_DETACH, ppid, NULL, 0);
|
||||||
|
rc = false;
|
||||||
|
} else {
|
||||||
|
rc = true;
|
||||||
|
}
|
||||||
|
_exit(rc);
|
||||||
|
} else {
|
||||||
|
waitpid(pid, &status, 0);
|
||||||
|
rc = WEXITSTATUS(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!rc;
|
||||||
|
}
|
||||||
|
|
||||||
static void usage(FILE *fp, const char *progname)
|
static void usage(FILE *fp, const char *progname)
|
||||||
{
|
{
|
||||||
fprintf(fp, "Usage: %s [OPTIONS]\n"
|
fprintf(fp, "Usage: %s [OPTIONS]\n"
|
||||||
|
|
@ -1201,7 +1230,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RUNNING_ON_VALGRIND)
|
if (RUNNING_ON_VALGRIND || is_debugger_attached())
|
||||||
ctx->no_fork = true;
|
ctx->no_fork = true;
|
||||||
|
|
||||||
find_suites(ctx, suite_filter);
|
find_suites(ctx, suite_filter);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue