mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
pwtest: is_debugger_attached(): rework test
Check if the "TracerPid" field in `/proc/self/status` is non-zero. This does not need libcap, and does not depend on capabilities, and it also works under qemu user emulation.
This commit is contained in:
parent
0d0108e954
commit
fcb318b9c5
3 changed files with 11 additions and 36 deletions
|
|
@ -381,9 +381,6 @@ libusb_dep = dependency('libusb-1.0', required : get_option('libusb'))
|
||||||
summary({'libusb (Bluetooth quirks)': libusb_dep.found()}, bool_yn: true, section: 'Backend')
|
summary({'libusb (Bluetooth quirks)': libusb_dep.found()}, bool_yn: true, section: 'Backend')
|
||||||
cdata.set('HAVE_LIBUSB', libusb_dep.found())
|
cdata.set('HAVE_LIBUSB', libusb_dep.found())
|
||||||
|
|
||||||
cap_lib = dependency('libcap', required : false)
|
|
||||||
cdata.set('HAVE_LIBCAP', cap_lib.found())
|
|
||||||
|
|
||||||
glib2_dep = dependency('glib-2.0', required : get_option('flatpak'))
|
glib2_dep = dependency('glib-2.0', required : get_option('flatpak'))
|
||||||
summary({'GLib-2.0 (Flatpak support)': glib2_dep.found()}, bool_yn: true, section: 'Misc dependencies')
|
summary({'GLib-2.0 (Flatpak support)': glib2_dep.found()}, bool_yn: true, section: 'Misc dependencies')
|
||||||
flatpak_support = glib2_dep.found()
|
flatpak_support = glib2_dep.found()
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ pwtest_deps = [
|
||||||
pipewire_dep,
|
pipewire_dep,
|
||||||
mathlib,
|
mathlib,
|
||||||
dl_lib,
|
dl_lib,
|
||||||
cap_lib,
|
|
||||||
epoll_shim_dep
|
epoll_shim_dep
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,6 @@
|
||||||
#ifdef HAVE_PIDFD_OPEN
|
#ifdef HAVE_PIDFD_OPEN
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef 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>
|
||||||
|
|
@ -33,6 +30,7 @@
|
||||||
#include <valgrind/valgrind.h>
|
#include <valgrind/valgrind.h>
|
||||||
|
|
||||||
#include "spa/utils/ansi.h"
|
#include "spa/utils/ansi.h"
|
||||||
|
#include "spa/utils/cleanup.h"
|
||||||
#include "spa/utils/string.h"
|
#include "spa/utils/string.h"
|
||||||
#include "spa/utils/defs.h"
|
#include "spa/utils/defs.h"
|
||||||
#include "spa/utils/list.h"
|
#include "spa/utils/list.h"
|
||||||
|
|
@ -1298,39 +1296,20 @@ static void list_tests(struct pwtest_context *ctx)
|
||||||
|
|
||||||
static bool is_debugger_attached(void)
|
static bool is_debugger_attached(void)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
spa_autofree char *line = NULL;
|
||||||
#ifdef HAVE_LIBCAP
|
size_t length = 0;
|
||||||
int status;
|
|
||||||
int pid = fork();
|
|
||||||
|
|
||||||
if (pid == -1)
|
spa_autoptr(FILE) f = fopen("/proc/self/status", "re");
|
||||||
return 0;
|
if (!f)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (pid == 0) {
|
while (getline(&line, &length, f) >= 0) {
|
||||||
int ppid = getppid();
|
unsigned int tracer_pid;
|
||||||
cap_t caps = cap_get_pid(ppid);
|
if (sscanf(line, "TracerPid: %u", &tracer_pid) == 1)
|
||||||
cap_flag_value_t cap_val;
|
return tracer_pid > 0;
|
||||||
|
|
||||||
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) {
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
return false;
|
||||||
return !!rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(FILE *fp, const char *progname)
|
static void usage(FILE *fp, const char *progname)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue