summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibIPC/Message.h
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-02 12:28:20 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-02 13:26:07 +0200
commitde9b454f897aee3d7b1cd1a8235a40360da5425f (patch)
tree1af38f2869028d0c3bb2df50189ce089445b2cce /Userland/Libraries/LibIPC/Message.h
parentcc6db526a6e595918a3e43312df8f724275e4e6a (diff)
downloadserenity-de9b454f897aee3d7b1cd1a8235a40360da5425f.zip
LibIPC: Make sure FDs survive when passed into a MessageBuffer
Diffstat (limited to 'Userland/Libraries/LibIPC/Message.h')
-rw-r--r--Userland/Libraries/LibIPC/Message.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/Userland/Libraries/LibIPC/Message.h b/Userland/Libraries/LibIPC/Message.h
index c483909700..0cb74bdde1 100644
--- a/Userland/Libraries/LibIPC/Message.h
+++ b/Userland/Libraries/LibIPC/Message.h
@@ -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 {