You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Disable file descriptor sharing with subprocs.
On Unix systems, file descriptors are usually shared among child processes. This means, that if we spawn a subprocess (or we fork) like we do in the editor any open file descriptor will leak to the new process. This PR sets the close-on-exec flag when opening a file, which causes the file descriptor to not be shared with the child process.
This commit is contained in:
@@ -56,6 +56,12 @@
|
|||||||
#define S_ISREG(m) ((m)&S_IFREG)
|
#define S_ISREG(m) ((m)&S_IFREG)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_FCNTL
|
||||||
|
#include <fcntl.h>
|
||||||
|
#else
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void FileAccessUnix::check_errors() const {
|
void FileAccessUnix::check_errors() const {
|
||||||
|
|
||||||
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
|
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
|
||||||
@@ -123,11 +129,24 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
|
|||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
return last_error;
|
return last_error;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// Set close on exec to avoid leaking it to subprocesses.
|
||||||
|
int fd = fileno(f);
|
||||||
|
|
||||||
|
if (fd != -1) {
|
||||||
|
#if defined(NO_FCNTL)
|
||||||
|
unsigned long par = 0;
|
||||||
|
ioctl(fd, FIOCLEX, &par);
|
||||||
|
#else
|
||||||
|
int opts = fcntl(fd, F_GETFD);
|
||||||
|
fcntl(fd, F_SETFD, opts | FD_CLOEXEC);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
last_error = OK;
|
last_error = OK;
|
||||||
flags = p_mode_flags;
|
flags = p_mode_flags;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileAccessUnix::close() {
|
void FileAccessUnix::close() {
|
||||||
|
|||||||
Reference in New Issue
Block a user