diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-24 14:28:22 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-24 14:28:22 +0200 |
commit | ec1d16b307e1467391d5d314bf700cb151ca96f4 (patch) | |
tree | 0d30ef8436f114ff0fb78e71cc6aa9e4711f6266 /Kernel/Task.cpp | |
parent | eb4074bb9dd9c38d6bc7f67f382bac288c630686 (diff) | |
download | serenity-ec1d16b307e1467391d5d314bf700cb151ca96f4.zip |
Add a "pwd" utility to userland.
It's implemented as a separate process. How cute is that.
Tasks now have a current working directory. Spawned tasks inherit their
parent task's working directory.
Currently everyone just uses "/" as there's no way to chdir().
Diffstat (limited to 'Kernel/Task.cpp')
-rw-r--r-- | Kernel/Task.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Kernel/Task.cpp b/Kernel/Task.cpp index 7005394ee5..50bc885708 100644 --- a/Kernel/Task.cpp +++ b/Kernel/Task.cpp @@ -165,13 +165,13 @@ int Task::sys$munmap(void* addr, size_t size) int Task::sys$spawn(const char* path) { - auto* child = Task::create(path, m_uid, m_gid); + auto* child = Task::create(path, m_uid, m_gid, m_pid); if (child) return child->pid(); return -1; } -Task* Task::create(const String& path, uid_t uid, gid_t gid) +Task* Task::create(const String& path, uid_t uid, gid_t gid, pid_t parentPID) { auto parts = path.split('/'); if (parts.isEmpty()) @@ -186,7 +186,7 @@ Task* Task::create(const String& path, uid_t uid, gid_t gid) return nullptr; InterruptDisabler disabler; // FIXME: Get rid of this, jesus christ. This "critical" section is HUGE. - Task* t = new Task(parts.takeLast(), uid, gid); + Task* t = new Task(parts.takeLast(), uid, gid, parentPID); ExecSpace space; space.hookableAlloc = [&] (const String& name, size_t size) { @@ -222,18 +222,25 @@ Task* Task::create(const String& path, uid_t uid, gid_t gid) return t; } -Task::Task(String&& name, uid_t uid, gid_t gid) +Task::Task(String&& name, uid_t uid, gid_t gid, pid_t parentPID) : m_name(move(name)) , m_pid(next_pid++) , m_uid(uid) , m_gid(gid) , m_state(Runnable) , m_ring(Ring3) + , m_parentPID(parentPID) { m_fileHandles.append(nullptr); m_fileHandles.append(nullptr); m_fileHandles.append(nullptr); + auto* parentTask = Task::fromPID(parentPID); + if (parentTask) + m_cwd = parentTask->m_cwd; + else + m_cwd = "/"; + m_nextRegion = LinearAddress(0x600000); memset(&m_tss, 0, sizeof(m_tss)); @@ -288,6 +295,8 @@ Task::Task(void (*e)(), const char* n, IPC::Handle h, RingLevel ring) m_fileHandles.append(nullptr); m_fileHandles.append(nullptr); + m_cwd = "/"; + m_nextRegion = LinearAddress(0x600000); Region* codeRegion = nullptr; @@ -709,6 +718,17 @@ int Task::sys$lstat(const char* path, void* statbuf) return 0; } +int Task::sys$getcwd(char* buffer, size_t size) +{ + if (size < m_cwd.length() + 1) { + // FIXME: return -ERANGE; + return -1; + } + memcpy(buffer, m_cwd.characters(), m_cwd.length()); + buffer[m_cwd.length()] = '\0'; + return 0; +} + int Task::sys$open(const char* path, size_t pathLength) { Task::checkSanity("sys$open"); |