1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:17:41 +00:00

Kernel: Pass full path of output coredump file to CoreDump

This commit is contained in:
Itamar 2020-11-13 22:38:58 +02:00 committed by Andreas Kling
parent dfdd977a82
commit 39890af833
4 changed files with 15 additions and 11 deletions

View file

@ -40,9 +40,9 @@
namespace Kernel { namespace Kernel {
OwnPtr<CoreDump> CoreDump::create(Process& process) OwnPtr<CoreDump> CoreDump::create(Process& process, const LexicalPath& output_path)
{ {
auto fd = create_target_file(process); auto fd = create_target_file(process, output_path);
if (!fd) if (!fd)
return nullptr; return nullptr;
return make<CoreDump>(process, fd.release_nonnull()); return make<CoreDump>(process, fd.release_nonnull());
@ -59,19 +59,19 @@ CoreDump::~CoreDump()
{ {
} }
RefPtr<FileDescription> CoreDump::create_target_file(const Process& process) RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, const LexicalPath& output_path)
{ {
static constexpr const char* coredumps_directory = "/tmp/coredump"; auto output_directory = output_path.dirname();
if (VFS::the().open_directory(coredumps_directory, VFS::the().root_custody()).is_error()) { if (VFS::the().open_directory(output_directory, VFS::the().root_custody()).is_error()) {
auto res = VFS::the().mkdir(coredumps_directory, 0777, VFS::the().root_custody()); auto res = VFS::the().mkdir(output_directory, 0777, VFS::the().root_custody());
if (res.is_error()) if (res.is_error())
return nullptr; return nullptr;
} }
auto tmp_dir = VFS::the().open_directory(coredumps_directory, VFS::the().root_custody()); auto tmp_dir = VFS::the().open_directory(output_directory, VFS::the().root_custody());
if (tmp_dir.is_error()) if (tmp_dir.is_error())
return nullptr; return nullptr;
auto fd_or_error = VFS::the().open( auto fd_or_error = VFS::the().open(
String::format("%s_%u.core", process.name().characters(), RTC::now()), output_path.basename(),
O_CREAT | O_WRONLY | O_EXCL, O_CREAT | O_WRONLY | O_EXCL,
0, // We will enable reading from userspace when we finish generating the coredump file 0, // We will enable reading from userspace when we finish generating the coredump file
*tmp_dir.value(), *tmp_dir.value(),

View file

@ -27,6 +27,7 @@
#pragma once #pragma once
#include <AK/LexicalPath.h>
#include <AK/NonnullRefPtr.h> #include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <Kernel/Forward.h> #include <Kernel/Forward.h>
@ -38,7 +39,7 @@ class Process;
class CoreDump { class CoreDump {
public: public:
static OwnPtr<CoreDump> create(Process&); static OwnPtr<CoreDump> create(Process&, const LexicalPath& output_path);
~CoreDump(); ~CoreDump();
void write(); void write();
@ -47,7 +48,7 @@ public:
CoreDump(Process&, NonnullRefPtr<FileDescription>&&); CoreDump(Process&, NonnullRefPtr<FileDescription>&&);
private: private:
static RefPtr<FileDescription> create_target_file(const Process&); static RefPtr<FileDescription> create_target_file(const Process&, const LexicalPath& output_path);
void write_elf_header(); void write_elf_header();
void write_program_headers(size_t notes_size); void write_program_headers(size_t notes_size);

View file

@ -589,7 +589,9 @@ void Process::finalize()
if (m_should_dump_core) { if (m_should_dump_core) {
dbgln("Generating coredump for pid: {}", m_pid.value()); dbgln("Generating coredump for pid: {}", m_pid.value());
auto coredump = CoreDump::create(*this);
auto coredump_path = String::format("/tmp/coredump/%s_%u", name().characters(), RTC::now());
auto coredump = CoreDump::create(*this, LexicalPath { coredump_path });
if (!coredump) { if (!coredump) {
dbgln("Could not create coredump"); dbgln("Could not create coredump");
} }

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <Kernel/CoreDump.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Profiling.h> #include <Kernel/Profiling.h>