Kernel: Don't take LexicalPath as argument

LexicalPath is a big and heavy class that's really meant as a helper
for extracting parts of a path, not for storage or passing around.
Instead, pass paths around as strings and use LexicalPath locally
as needed.
This commit is contained in:
Andreas Kling 2020-12-15 11:17:01 +01:00
parent bcabbbda8b
commit ff8bf4db8d
Notes: sideshowbarker 2024-07-19 00:49:24 +09:00
4 changed files with 13 additions and 14 deletions

View file

@ -40,12 +40,12 @@
namespace Kernel {
OwnPtr<CoreDump> CoreDump::create(Process& process, const LexicalPath& output_path)
OwnPtr<CoreDump> CoreDump::create(Process& process, const String& output_path)
{
auto fd = create_target_file(process, output_path);
if (!fd)
return nullptr;
return make<CoreDump>(process, fd.release_nonnull());
return adopt_own(*new CoreDump(process, fd.release_nonnull()));
}
CoreDump::CoreDump(Process& process, NonnullRefPtr<FileDescription>&& fd)
@ -59,9 +59,10 @@ CoreDump::~CoreDump()
{
}
RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, const LexicalPath& output_path)
RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, const String& output_path)
{
auto output_directory = output_path.dirname();
LexicalPath lexical_path(output_path);
auto output_directory = lexical_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())
@ -71,7 +72,7 @@ RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, con
if (tmp_dir.is_error())
return nullptr;
auto fd_or_error = VFS::the().open(
output_path.basename(),
lexical_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(),

View file

@ -39,16 +39,14 @@ class Process;
class CoreDump {
public:
static OwnPtr<CoreDump> create(Process&, const LexicalPath& output_path);
static OwnPtr<CoreDump> create(Process&, const String& output_path);
~CoreDump();
void write();
// Has to be public for OwnPtr::make
CoreDump(Process&, NonnullRefPtr<FileDescription>&&);
private:
static RefPtr<FileDescription> create_target_file(const Process&, const LexicalPath& output_path);
CoreDump(Process&, NonnullRefPtr<FileDescription>&&);
static RefPtr<FileDescription> create_target_file(const Process&, const String& output_path);
void write_elf_header();
void write_program_headers(size_t notes_size);

View file

@ -588,7 +588,7 @@ void Process::finalize()
#endif
if (is_profiling()) {
auto coredump = CoreDump::create(*this, LexicalPath { String::format("/tmp/profiler_coredumps/%d", pid().value()) });
auto coredump = CoreDump::create(*this, String::formatted("/tmp/profiler_coredumps/{}", pid().value()));
if (coredump) {
coredump->write();
} else {
@ -598,8 +598,8 @@ void Process::finalize()
if (m_should_dump_core) {
dbgln("Generating coredump for pid: {}", m_pid.value());
auto coredump_path = String::format("/tmp/coredump/%s_%d_%u", name().characters(), m_pid.value(), RTC::now());
auto coredump = CoreDump::create(*this, LexicalPath { coredump_path });
auto coredump_path = String::formatted("/tmp/coredump/{}_{}_{}", name(), m_pid.value(), RTC::now());
auto coredump = CoreDump::create(*this, coredump_path);
if (coredump) {
coredump->write();
} else {

View file

@ -60,7 +60,7 @@ int Process::sys$profiling_disable(pid_t pid)
// We explicitly unlock here because we can't hold the lock when writing the coredump VFS
lock.unlock();
auto coredump = CoreDump::create(*process, LexicalPath { String::format("/tmp/profiler_coredumps/%d", pid) });
auto coredump = CoreDump::create(*process, String::formatted("/tmp/profiler_coredumps/%d", pid));
coredump->write();
return 0;
}