mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:17:45 +00:00
LibIPC: Make sure FDs survive when passed into a MessageBuffer
This commit is contained in:
parent
cc6db526a6
commit
de9b454f89
3 changed files with 34 additions and 4 deletions
|
@ -7,13 +7,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace IPC {
|
||||
|
||||
class AutoCloseFileDescriptor : public RefCounted<AutoCloseFileDescriptor> {
|
||||
public:
|
||||
AutoCloseFileDescriptor(int fd)
|
||||
: m_fd(fd)
|
||||
{
|
||||
}
|
||||
|
||||
~AutoCloseFileDescriptor()
|
||||
{
|
||||
if (m_fd != -1)
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
int value() const { return m_fd; }
|
||||
|
||||
private:
|
||||
int m_fd;
|
||||
};
|
||||
|
||||
struct MessageBuffer {
|
||||
Vector<u8, 1024> data;
|
||||
Vector<int> fds;
|
||||
Vector<RefPtr<AutoCloseFileDescriptor>> fds;
|
||||
};
|
||||
|
||||
class Message {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue