mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
test: check for CAP_SYS_PTRACE before testing for an attached debugger
If we don't have the capability to ptrace, we are probably running inside a container, not the debugger. Check this first so we don't disable forking mode. Make this conditional on libcap - where libcap is not available always assume we *do not* have a debugger attached. This is easier than telling everyone who runs the tests in a confined system to install libcap. Fixes #1285
This commit is contained in:
parent
2d238f1d33
commit
7177d82c34
3 changed files with 19 additions and 1 deletions
|
|
@ -323,6 +323,11 @@ sndfile_dep = dependency('sndfile', version : '>= 1.0.20', required : get_option
|
||||||
pulseaudio_dep = dependency('libpulse', required : get_option('libpulse'))
|
pulseaudio_dep = dependency('libpulse', required : get_option('libpulse'))
|
||||||
avahi_dep = dependency('avahi-client', required : get_option('avahi'))
|
avahi_dep = dependency('avahi-client', required : get_option('avahi'))
|
||||||
|
|
||||||
|
cap_lib = dependency('libcap', required : false)
|
||||||
|
if cap_lib.found()
|
||||||
|
cdata.set('HAVE_LIBCAP', 1)
|
||||||
|
endif
|
||||||
|
|
||||||
gst_option = get_option('gstreamer')
|
gst_option = get_option('gstreamer')
|
||||||
gst_deps_def = {
|
gst_deps_def = {
|
||||||
'glib-2.0': {'version': '>=2.32.0'},
|
'glib-2.0': {'version': '>=2.32.0'},
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pwtest_deps = [
|
||||||
pipewire_dep,
|
pipewire_dep,
|
||||||
mathlib,
|
mathlib,
|
||||||
dl_lib,
|
dl_lib,
|
||||||
|
cap_lib,
|
||||||
]
|
]
|
||||||
|
|
||||||
pwtest_c_args = [
|
pwtest_c_args = [
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
#if HAVE_LIBCAP
|
||||||
|
#include <sys/capability.h>
|
||||||
|
#endif
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
@ -1135,8 +1138,9 @@ static void list_tests(struct pwtest_context *ctx)
|
||||||
|
|
||||||
static bool is_debugger_attached(void)
|
static bool is_debugger_attached(void)
|
||||||
{
|
{
|
||||||
|
bool rc = false;
|
||||||
|
#if HAVE_LIBCAP
|
||||||
int status;
|
int status;
|
||||||
bool rc;
|
|
||||||
int pid = fork();
|
int pid = fork();
|
||||||
|
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
|
|
@ -1144,6 +1148,13 @@ static bool is_debugger_attached(void)
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
int ppid = getppid();
|
int ppid = getppid();
|
||||||
|
cap_t caps = cap_get_pid(ppid);
|
||||||
|
cap_flag_value_t cap_val;
|
||||||
|
|
||||||
|
if (cap_get_flag(caps, CAP_SYS_PTRACE, CAP_EFFECTIVE, &cap_val) == -1 ||
|
||||||
|
cap_val != CAP_SET)
|
||||||
|
_exit(false);
|
||||||
|
|
||||||
if (ptrace(PTRACE_ATTACH, ppid, NULL, 0) == 0) {
|
if (ptrace(PTRACE_ATTACH, ppid, NULL, 0) == 0) {
|
||||||
waitpid(ppid, NULL, 0);
|
waitpid(ppid, NULL, 0);
|
||||||
ptrace(PTRACE_CONT, ppid, NULL, 0);
|
ptrace(PTRACE_CONT, ppid, NULL, 0);
|
||||||
|
|
@ -1158,6 +1169,7 @@ static bool is_debugger_attached(void)
|
||||||
rc = WEXITSTATUS(status);
|
rc = WEXITSTATUS(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
return !!rc;
|
return !!rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue