diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-21 16:19:07 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-21 16:19:07 +0100 |
commit | f0a869ea504af0adb3f03c11deeeab997f304dc7 (patch) | |
tree | 99c980c895486dfd518af99b2b65903c5d3eef67 | |
parent | ce3b548077e1eb6f7eff7720bf8705bcbdbf97c7 (diff) | |
download | serenity-f0a869ea504af0adb3f03c11deeeab997f304dc7.zip |
Kernel: Process::cwd_inode() should return a reference.
There's always a current working directory inode.
-rw-r--r-- | Kernel/LocalSocket.cpp | 4 | ||||
-rw-r--r-- | Kernel/ProcFS.cpp | 21 | ||||
-rw-r--r-- | Kernel/Process.cpp | 32 | ||||
-rw-r--r-- | Kernel/Process.h | 2 |
4 files changed, 23 insertions, 36 deletions
diff --git a/Kernel/LocalSocket.cpp b/Kernel/LocalSocket.cpp index 8ee414dd79..9073100c04 100644 --- a/Kernel/LocalSocket.cpp +++ b/Kernel/LocalSocket.cpp @@ -47,7 +47,7 @@ bool LocalSocket::bind(const sockaddr* address, socklen_t address_size, int& err kprintf("%s(%u) LocalSocket{%p} bind(%s)\n", current->name().characters(), current->pid(), this, safe_address); - m_file = VFS::the().open(safe_address, error, O_CREAT | O_EXCL, S_IFSOCK | 0666, *current->cwd_inode()); + m_file = VFS::the().open(safe_address, error, O_CREAT | O_EXCL, S_IFSOCK | 0666, current->cwd_inode()); if (!m_file) { if (error == -EEXIST) error = -EADDRINUSE; @@ -80,7 +80,7 @@ bool LocalSocket::connect(const sockaddr* address, socklen_t address_size, int& kprintf("%s(%u) LocalSocket{%p} connect(%s)\n", current->name().characters(), current->pid(), this, safe_address); - m_file = VFS::the().open(safe_address, error, 0, 0, *current->cwd_inode()); + m_file = VFS::the().open(safe_address, error, 0, 0, current->cwd_inode()); if (!m_file) { error = -ECONNREFUSED; return false; diff --git a/Kernel/ProcFS.cpp b/Kernel/ProcFS.cpp index 62e34d1721..cbdff6f889 100644 --- a/Kernel/ProcFS.cpp +++ b/Kernel/ProcFS.cpp @@ -339,10 +339,7 @@ ByteBuffer procfs$pid_cwd(InodeIdentifier identifier) auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) return { }; - auto& process = handle->process(); - auto inode = process.cwd_inode(); - ASSERT(inode); - return VFS::the().absolute_path(*inode).to_byte_buffer(); + return VFS::the().absolute_path(handle->process().cwd_inode()).to_byte_buffer(); } ByteBuffer procfs$self(InodeIdentifier) @@ -902,12 +899,8 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&) auto& process = handle->process(); for (auto& entry : fs().m_entries) { if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) { - if (entry.proc_file_type == FI_PID_exe || entry.proc_file_type == FI_PID_cwd) { - if (entry.proc_file_type == FI_PID_exe && !process.executable_inode()) - continue; - if (entry.proc_file_type == FI_PID_cwd && !process.cwd_inode()) - continue; - } + if (entry.proc_file_type == FI_PID_exe && !process.executable_inode()) + continue; // FIXME: strlen() here is sad. callback({ entry.name, strlen(entry.name), to_identifier(fsid(), PDI_PID, pid, (ProcFileType)entry.proc_file_type), 0 }); } @@ -987,12 +980,8 @@ InodeIdentifier ProcFSInode::lookup(const String& name) auto& process = handle->process(); for (auto& entry : fs().m_entries) { if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) { - if (entry.proc_file_type == FI_PID_exe || entry.proc_file_type == FI_PID_cwd) { - if (entry.proc_file_type == FI_PID_exe && !process.executable_inode()) - continue; - if (entry.proc_file_type == FI_PID_cwd && !process.cwd_inode()) - continue; - } + if (entry.proc_file_type == FI_PID_exe && !process.executable_inode()) + continue; if (entry.name == nullptr) continue; if (!strcmp(entry.name, name.characters())) { diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 54be7f4c88..814177116e 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -291,7 +291,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir return -ENOENT; int error; - auto descriptor = VFS::the().open(path, error, 0, 0, *cwd_inode()); + auto descriptor = VFS::the().open(path, error, 0, 0, cwd_inode()); if (!descriptor) { ASSERT(error != 0); return error; @@ -1127,7 +1127,7 @@ int Process::sys$utime(const char* pathname, const utimbuf* buf) return -EFAULT; String path(pathname); int error; - auto descriptor = VFS::the().open(move(path), error, 0, 0, *cwd_inode()); + auto descriptor = VFS::the().open(move(path), error, 0, 0, cwd_inode()); if (!descriptor) return error; auto& inode = *descriptor->inode(); @@ -1217,7 +1217,7 @@ int Process::sys$lstat(const char* path, stat* statbuf) if (!validate_write_typed(statbuf)) return -EFAULT; int error; - if (!VFS::the().stat(move(path), error, O_NOFOLLOW_NOERROR, *cwd_inode(), *statbuf)) + if (!VFS::the().stat(move(path), error, O_NOFOLLOW_NOERROR, cwd_inode(), *statbuf)) return error; return 0; } @@ -1227,7 +1227,7 @@ int Process::sys$stat(const char* path, stat* statbuf) if (!validate_write_typed(statbuf)) return -EFAULT; int error; - if (!VFS::the().stat(move(path), error, 0, *cwd_inode(), *statbuf)) + if (!VFS::the().stat(move(path), error, 0, cwd_inode(), *statbuf)) return error; return 0; } @@ -1240,7 +1240,7 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size) return -EFAULT; int error; - auto descriptor = VFS::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, 0, *cwd_inode()); + auto descriptor = VFS::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, 0, cwd_inode()); if (!descriptor) return error; @@ -1262,7 +1262,7 @@ int Process::sys$chdir(const char* path) if (!validate_read_str(path)) return -EFAULT; int error; - auto descriptor = VFS::the().open(path, error, 0, 0, *cwd_inode()); + auto descriptor = VFS::the().open(path, error, 0, 0, cwd_inode()); if (!descriptor) return error; if (!descriptor->is_directory()) @@ -1275,8 +1275,7 @@ int Process::sys$getcwd(char* buffer, size_t size) { if (!validate_write(buffer, size)) return -EFAULT; - ASSERT(cwd_inode()); - auto path = VFS::the().absolute_path(*cwd_inode()); + auto path = VFS::the().absolute_path(cwd_inode()); if (path.is_null()) return -EINVAL; if (size < path.length() + 1) @@ -1305,8 +1304,7 @@ int Process::sys$open(const char* path, int options, mode_t mode) if (number_of_open_file_descriptors() >= m_max_open_file_descriptors) return -EMFILE; int error = -EWHYTHO; - ASSERT(cwd_inode()); - auto descriptor = VFS::the().open(path, error, options, mode, *cwd_inode()); + auto descriptor = VFS::the().open(path, error, options, mode, cwd_inode()); if (!descriptor) return error; if (options & O_DIRECTORY && !descriptor->is_directory()) @@ -1934,7 +1932,7 @@ int Process::sys$mkdir(const char* pathname, mode_t mode) if (pathname_length >= 255) return -ENAMETOOLONG; int error; - if (!VFS::the().mkdir(String(pathname, pathname_length), mode, *cwd_inode(), error)) + if (!VFS::the().mkdir(String(pathname, pathname_length), mode, cwd_inode(), error)) return error; return 0; } @@ -2091,12 +2089,12 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout) return fds_with_revents; } -Inode* Process::cwd_inode() +Inode& Process::cwd_inode() { // FIXME: This is retarded factoring. if (!m_cwd) m_cwd = VFS::the().root_inode(); - return m_cwd.ptr(); + return *m_cwd; } int Process::sys$link(const char* old_path, const char* new_path) @@ -2106,7 +2104,7 @@ int Process::sys$link(const char* old_path, const char* new_path) if (!validate_read_str(new_path)) return -EFAULT; int error; - if (!VFS::the().link(String(old_path), String(new_path), *cwd_inode(), error)) + if (!VFS::the().link(String(old_path), String(new_path), cwd_inode(), error)) return error; return 0; } @@ -2116,7 +2114,7 @@ int Process::sys$unlink(const char* pathname) if (!validate_read_str(pathname)) return -EFAULT; int error; - if (!VFS::the().unlink(String(pathname), *cwd_inode(), error)) + if (!VFS::the().unlink(String(pathname), cwd_inode(), error)) return error; return 0; } @@ -2126,7 +2124,7 @@ int Process::sys$rmdir(const char* pathname) if (!validate_read_str(pathname)) return -EFAULT; int error; - if (!VFS::the().rmdir(String(pathname), *cwd_inode(), error)) + if (!VFS::the().rmdir(String(pathname), cwd_inode(), error)) return error; return 0; } @@ -2146,7 +2144,7 @@ int Process::sys$chmod(const char* pathname, mode_t mode) if (!validate_read_str(pathname)) return -EFAULT; int error; - if (!VFS::the().chmod(String(pathname), mode, *cwd_inode(), error)) + if (!VFS::the().chmod(String(pathname), mode, cwd_inode(), error)) return error; return 0; } diff --git a/Kernel/Process.h b/Kernel/Process.h index 316933832c..2ecd3faf8f 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -263,7 +263,7 @@ public: template<typename T> bool validate_read_typed(T* value, size_t count = 1) { return validate_read(value, sizeof(T) * count); } template<typename T> bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); } - Inode* cwd_inode(); + Inode& cwd_inode(); Inode* executable_inode() { return m_executable.ptr(); } size_t number_of_open_file_descriptors() const; |