1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:47:45 +00:00

LibCore+Ladybird: Extract helper into generic Process::is_being_debugged

This commit is contained in:
Sebastian Zaha 2023-08-02 10:27:58 +02:00 committed by Andrew Kaster
parent 002e206af0
commit 216667368d
3 changed files with 28 additions and 14 deletions

View file

@ -15,6 +15,7 @@
#include <Browser/Database.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Process.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGfx/Font/FontDatabase.h>
@ -48,20 +49,9 @@ static ErrorOr<void> handle_attached_debugger()
// incorrectly forwards the signal to us even when it's set to
// "nopass". See https://sourceware.org/bugzilla/show_bug.cgi?id=9425
// for details.
auto unbuffered_status_file = TRY(Core::File::open("/proc/self/status"sv, Core::File::OpenMode::Read));
auto status_file = TRY(Core::InputBufferedFile::create(move(unbuffered_status_file)));
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
while (TRY(status_file->can_read_line())) {
auto line = TRY(status_file->read_line(buffer));
auto const parts = line.split_view(':');
if (parts.size() < 2 || parts[0] != "TracerPid"sv)
continue;
auto tracer_pid = parts[1].to_uint<u32>();
if (tracer_pid != 0UL) {
dbgln("Debugger is attached, ignoring SIGINT");
TRY(Core::System::signal(SIGINT, SIG_IGN));
}
break;
if (TRY(Core::Process::is_being_debugged())) {
dbgln("Debugger is attached, ignoring SIGINT");
TRY(Core::System::signal(SIGINT, SIG_IGN));
}
#endif
return {};