diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp index 70a103e861..97f98102a2 100644 --- a/Userland/Applications/CrashReporter/main.cpp +++ b/Userland/Applications/CrashReporter/main.cpp @@ -156,6 +156,12 @@ static TitleAndText build_cpu_registers(const ELF::Core::ThreadInfo& thread_info }; } +static void unlink_coredump(StringView const& coredump_path) +{ + if (Core::File::remove(coredump_path, Core::File::RecursionMode::Disallowed, false).is_error()) + dbgln("Failed deleting coredump file"); +} + int main(int argc, char** argv) { if (pledge("stdio recvfd sendfd cpath rpath unix", nullptr) < 0) { @@ -166,12 +172,12 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); const char* coredump_path = nullptr; - bool unlink_after_use = false; + bool unlink_on_exit = false; Core::ArgsParser args_parser; args_parser.set_general_help("Show information from an application crash coredump."); args_parser.add_positional_argument(coredump_path, "Coredump path", "coredump-path"); - args_parser.add_option(unlink_after_use, "Delete the coredump after its parsed", "unlink", 0); + args_parser.add_option(unlink_on_exit, "Delete the coredump after its parsed", "unlink", 0); args_parser.parse(argc, argv); Vector thread_backtraces; @@ -205,12 +211,7 @@ int main(int argc, char** argv) termination_signal = coredump->process_termination_signal(); } - if (unlink_after_use) { - if (Core::File::remove(coredump_path, Core::File::RecursionMode::Disallowed, false).is_error()) - dbgln("Failed deleting coredump file"); - } - - if (pledge("stdio recvfd sendfd rpath unix", nullptr) < 0) { + if (pledge("stdio recvfd sendfd rpath unix cpath", nullptr) < 0) { perror("pledge"); return 1; } @@ -230,6 +231,13 @@ int main(int argc, char** argv) return 1; } + if (unlink_on_exit) { + if (unveil(coredump_path, "c") < 0) { + perror("unveil"); + return 1; + } + } + if (unveil(nullptr, nullptr) < 0) { perror("unveil"); return 1; @@ -242,6 +250,10 @@ int main(int argc, char** argv) window->set_icon(app_icon.bitmap_for_size(16)); window->resize(460, 340); window->center_on_screen(); + window->on_close = [unlink_on_exit, &coredump_path]() { + if (unlink_on_exit) + unlink_coredump(coredump_path); + }; auto& widget = window->set_main_widget(); widget.load_from_gml(crash_reporter_window_gml); @@ -327,6 +339,8 @@ int main(int argc, char** argv) auto& close_button = *widget.find_descendant_of_type_named("close_button"); close_button.on_click = [&](auto) { + if (unlink_on_exit) + unlink_coredump(coredump_path); app->quit(); }; diff --git a/Userland/Services/CrashDaemon/main.cpp b/Userland/Services/CrashDaemon/main.cpp index d9f258d88c..76c9029797 100644 --- a/Userland/Services/CrashDaemon/main.cpp +++ b/Userland/Services/CrashDaemon/main.cpp @@ -29,11 +29,11 @@ static void wait_until_coredump_is_ready(const String& coredump_path) } } -static void launch_crash_reporter(const String& coredump_path, bool unlink_after_use) +static void launch_crash_reporter(const String& coredump_path, bool unlink_on_exit) { pid_t child; const char* argv[4] = { "CrashReporter" }; - if (unlink_after_use) { + if (unlink_on_exit) { argv[1] = "--unlink"; argv[2] = coredump_path.characters(); argv[3] = nullptr;