mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-16 06:30:41 +00:00
Kernel: Process::cwd_inode() should return a reference.
There's always a current working directory inode.
This commit is contained in:
parent
ce3b548077
commit
f0a869ea50
|
@ -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;
|
||||
|
|
|
@ -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())) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue