mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
Kernel: Make it possible to look up FIFO's by ID.
This will be useful when implementing the /proc/PID/fd/N links where N is a file descriptor referring to a FIFO.
This commit is contained in:
parent
eadcf720c0
commit
d5578826af
4 changed files with 43 additions and 8 deletions
|
@ -1,15 +1,43 @@
|
|||
#include <Kernel/FileSystem/FIFO.h>
|
||||
#include <Kernel/Lock.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/HashTable.h>
|
||||
|
||||
//#define FIFO_DEBUG
|
||||
|
||||
Retained<FIFO> FIFO::create()
|
||||
Lockable<HashTable<FIFO*>>& all_fifos()
|
||||
{
|
||||
return adopt(*new FIFO);
|
||||
static Lockable<HashTable<FIFO*>>* s_table;
|
||||
if (!s_table)
|
||||
s_table = new Lockable<HashTable<FIFO*>>;
|
||||
return *s_table;
|
||||
}
|
||||
|
||||
FIFO::FIFO()
|
||||
RetainPtr<FIFO> FIFO::from_fifo_id(dword id)
|
||||
{
|
||||
auto* ptr = reinterpret_cast<FIFO*>(id);
|
||||
LOCKER(all_fifos().lock());
|
||||
if (auto it = all_fifos().resource().find(ptr); it == all_fifos().resource().end())
|
||||
return nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Retained<FIFO> FIFO::create(uid_t uid)
|
||||
{
|
||||
return adopt(*new FIFO(uid));
|
||||
}
|
||||
|
||||
FIFO::FIFO(uid_t uid)
|
||||
: m_uid(uid)
|
||||
{
|
||||
LOCKER(all_fifos().lock());
|
||||
all_fifos().resource().set(this);
|
||||
}
|
||||
|
||||
FIFO::~FIFO()
|
||||
{
|
||||
LOCKER(all_fifos().lock());
|
||||
all_fifos().resource().remove(this);
|
||||
}
|
||||
|
||||
void FIFO::open(Direction direction)
|
||||
|
|
|
@ -11,7 +11,12 @@ public:
|
|||
Neither, Reader, Writer
|
||||
};
|
||||
|
||||
static Retained<FIFO> create();
|
||||
static RetainPtr<FIFO> from_fifo_id(dword);
|
||||
|
||||
static Retained<FIFO> create(uid_t);
|
||||
~FIFO();
|
||||
|
||||
uid_t uid() const { return m_uid; }
|
||||
|
||||
void open(Direction);
|
||||
void close(Direction);
|
||||
|
@ -23,9 +28,11 @@ public:
|
|||
bool can_write() const;
|
||||
|
||||
private:
|
||||
FIFO();
|
||||
explicit FIFO(uid_t);
|
||||
|
||||
unsigned m_writers { 0 };
|
||||
unsigned m_readers { 0 };
|
||||
DoubleBuffer m_buffer;
|
||||
|
||||
uid_t m_uid { 0 };
|
||||
};
|
||||
|
|
|
@ -402,7 +402,7 @@ KResultOr<String> FileDescriptor::absolute_path()
|
|||
if (is_tty())
|
||||
return tty()->tty_name();
|
||||
if (is_fifo())
|
||||
return String::format("fifo:%x", m_fifo.ptr());
|
||||
return String::format("fifo:%u", m_fifo.ptr());
|
||||
if (is_device())
|
||||
return String::format("device:%u,%u (%s)", m_device->major(), m_device->minor(), m_device->class_name());
|
||||
if (is_socket())
|
||||
|
|
|
@ -276,7 +276,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
|||
{
|
||||
ASSERT(is_ring3());
|
||||
|
||||
dbgprintf("%s(%d) do_exec: thread_count() = %d\n", m_name.characters(), m_pid, thread_count());
|
||||
dbgprintf("%s(%d) do_exec(%s): thread_count() = %d\n", m_name.characters(), m_pid, path.characters(), thread_count());
|
||||
// FIXME(Thread): Kill any threads the moment we commit to the exec().
|
||||
if (thread_count() != 1) {
|
||||
dbgprintf("Gonna die because I have many threads! These are the threads:\n");
|
||||
|
@ -1097,7 +1097,7 @@ int Process::sys$pipe(int pipefd[2])
|
|||
return -EFAULT;
|
||||
if (number_of_open_file_descriptors() + 2 > max_open_file_descriptors())
|
||||
return -EMFILE;
|
||||
auto fifo = FIFO::create();
|
||||
auto fifo = FIFO::create(m_uid);
|
||||
|
||||
int reader_fd = alloc_fd();
|
||||
m_fds[reader_fd].set(FileDescriptor::create_pipe_reader(*fifo));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue