summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-11-20 13:33:50 +0200
committerLinus Groh <mail@linusgroh.de>2021-11-20 21:22:24 +0000
commitd6d48ce9368c4fa670ab185a23d568c169d08fdb (patch)
tree9ba5f5f4335c5d9d1456bba1256ce4c0586ec7ba /Userland/Applications
parent1c0a7cde63ae4f3a29a5a09f3b78e92fff5b36a5 (diff)
downloadserenity-d6d48ce9368c4fa670ab185a23d568c169d08fdb.zip
CrashReporter: Unlink coredump file on exit
Previously, when the --unlink flag was passed to CrashReporter, it unlinked the coredump file immediately after reading it. This change makes it so the coredump file is deleted when CrashReporter exits.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/CrashReporter/main.cpp30
1 files changed, 22 insertions, 8 deletions
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<TitleAndText> 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<GUI::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<GUI::Button>("close_button");
close_button.on_click = [&](auto) {
+ if (unlink_on_exit)
+ unlink_coredump(coredump_path);
app->quit();
};