mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-04-28 07:22:40 +00:00
LibIPC: Support sending file descriptors :^)
It is now possible to use the special IPC::File type in message arguments. In C++, the type is nothing more than a wrapper over a file descriptor. But when serializing/deserializing IPC::File arguments, LibIPC will use the sendfd/recvfd kernel APIs instead of sending the integer inline. This makes it quite convenient to pass files over IPC, and will allow us to significantly tighten sandboxes in the future :^) Closes https://github.com/SerenityOS/serenity/issues/3643
This commit is contained in:
committed by
Andreas Kling
parent
fa2e3e2be4
commit
23dc3ff0c2
@@ -28,6 +28,9 @@
|
||||
#include <AK/URL.h>
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Dictionary.h>
|
||||
#include <LibIPC/File.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
namespace IPC {
|
||||
|
||||
@@ -163,4 +166,21 @@ bool Decoder::decode(Dictionary& dictionary)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Decoder::decode(File& file)
|
||||
{
|
||||
#ifdef __serenity__
|
||||
int fd = recvfd(m_sockfd);
|
||||
if (fd < 0) {
|
||||
dbgln("recvfd: {}", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
file = File(fd);
|
||||
return true;
|
||||
#else
|
||||
(void)file;
|
||||
warnln("fd passing is not supported on this platform, sorry :(");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user