mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
Kernel: Pass full path of output coredump file to CoreDump
This commit is contained in:
parent
dfdd977a82
commit
39890af833
Notes:
sideshowbarker
2024-07-19 00:50:35 +09:00
Author: https://github.com/itamar8910
Commit: 39890af833
Pull-request: https://github.com/SerenityOS/serenity/pull/3738
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
4 changed files with 15 additions and 11 deletions
|
@ -40,9 +40,9 @@
|
|||
|
||||
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)
|
||||
return nullptr;
|
||||
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";
|
||||
if (VFS::the().open_directory(coredumps_directory, VFS::the().root_custody()).is_error()) {
|
||||
auto res = VFS::the().mkdir(coredumps_directory, 0777, VFS::the().root_custody());
|
||||
auto output_directory = output_path.dirname();
|
||||
if (VFS::the().open_directory(output_directory, VFS::the().root_custody()).is_error()) {
|
||||
auto res = VFS::the().mkdir(output_directory, 0777, VFS::the().root_custody());
|
||||
if (res.is_error())
|
||||
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())
|
||||
return nullptr;
|
||||
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,
|
||||
0, // We will enable reading from userspace when we finish generating the coredump file
|
||||
*tmp_dir.value(),
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <Kernel/Forward.h>
|
||||
|
@ -38,7 +39,7 @@ class Process;
|
|||
|
||||
class CoreDump {
|
||||
public:
|
||||
static OwnPtr<CoreDump> create(Process&);
|
||||
static OwnPtr<CoreDump> create(Process&, const LexicalPath& output_path);
|
||||
|
||||
~CoreDump();
|
||||
void write();
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
CoreDump(Process&, NonnullRefPtr<FileDescription>&&);
|
||||
|
||||
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_program_headers(size_t notes_size);
|
||||
|
|
|
@ -589,7 +589,9 @@ void Process::finalize()
|
|||
|
||||
if (m_should_dump_core) {
|
||||
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) {
|
||||
dbgln("Could not create coredump");
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <Kernel/CoreDump.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Profiling.h>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue