LibIPC: Make received file descriptors close-on-exec by default

I noticed that programs running in the terminal had an open file
descriptor for the system theme buffer, inherited from the Terminal.

Let's be nice and always mark incoming fds with FD_CLOEXEC.
This commit is contained in:
Andreas Kling 2021-02-13 20:12:34 +01:00
parent 2ed7f75e95
commit 05bb11f482
Notes: sideshowbarker 2024-07-18 22:21:04 +09:00

View File

@ -30,6 +30,7 @@
#include <LibIPC/Decoder.h>
#include <LibIPC/Dictionary.h>
#include <LibIPC/File.h>
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
@ -175,6 +176,10 @@ bool Decoder::decode([[maybe_unused]] File& file)
dbgln("recvfd: {}", strerror(errno));
return false;
}
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
dbgln("fcntl(F_SETFD, FD_CLOEXEC)", strerror(errno));
return false;
}
file = File(fd, File::ConstructWithReceivedFileDescriptor);
return true;
#else