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') | ||||
| 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')) | ||||
| summary({'GLib-2.0 (Flatpak support)': glib2_dep.found()}, bool_yn: true, section: 'Misc dependencies') | ||||
| flatpak_support = glib2_dep.found() | ||||
|  |  | |||
|  | @ -9,7 +9,6 @@ pwtest_deps = [ | |||
|   pipewire_dep, | ||||
|   mathlib, | ||||
|   dl_lib, | ||||
|   cap_lib, | ||||
|   epoll_shim_dep | ||||
| ] | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,9 +19,6 @@ | |||
| #ifdef HAVE_PIDFD_OPEN | ||||
| #include <sys/syscall.h> | ||||
| #endif | ||||
| #ifdef HAVE_LIBCAP | ||||
| #include <sys/capability.h> | ||||
| #endif | ||||
| #include <sys/epoll.h> | ||||
| #include <sys/ptrace.h> | ||||
| #include <sys/resource.h> | ||||
|  | @ -33,6 +30,7 @@ | |||
| #include <valgrind/valgrind.h> | ||||
| 
 | ||||
| #include "spa/utils/ansi.h" | ||||
| #include "spa/utils/cleanup.h" | ||||
| #include "spa/utils/string.h" | ||||
| #include "spa/utils/defs.h" | ||||
| #include "spa/utils/list.h" | ||||
|  | @ -1298,39 +1296,20 @@ static void list_tests(struct pwtest_context *ctx) | |||
| 
 | ||||
| static bool is_debugger_attached(void) | ||||
| { | ||||
| 	bool rc = false; | ||||
| #ifdef HAVE_LIBCAP | ||||
| 	int status; | ||||
| 	int pid = fork(); | ||||
| 	spa_autofree char *line = NULL; | ||||
| 	size_t length = 0; | ||||
| 
 | ||||
| 	if (pid == -1) | ||||
| 		return 0; | ||||
| 	spa_autoptr(FILE) f = fopen("/proc/self/status", "re"); | ||||
| 	if (!f) | ||||
| 		return false; | ||||
| 
 | ||||
| 	if (pid == 0) { | ||||
| 		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) { | ||||
| 			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); | ||||
| 	while (getline(&line, &length, f) >= 0) { | ||||
| 		unsigned int tracer_pid; | ||||
| 		if (sscanf(line, "TracerPid: %u", &tracer_pid) == 1) | ||||
| 			return tracer_pid > 0; | ||||
| 	} | ||||
| 
 | ||||
| #endif | ||||
| 	return !!rc; | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| static void usage(FILE *fp, const char *progname) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Barnabás Pőcze
						Barnabás Pőcze