summaryrefslogtreecommitdiffstats
path: root/mpvcore/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-11-30 22:40:51 +0100
committerwm4 <wm4@nowhere>2013-11-30 22:40:51 +0100
commit95cfe58e3db9d939abe7a9a26116c1d576eed60b (patch)
tree98a4738f2f989c900702d84ef8a257f9413389af /mpvcore/player/command.c
parenteea69682a6a874d540f9fc576c937466970713f6 (diff)
downloadmpv-95cfe58e3db9d939abe7a9a26116c1d576eed60b.tar.bz2
mpv-95cfe58e3db9d939abe7a9a26116c1d576eed60b.tar.xz
Use O_CLOEXEC when creating FDs
This is needed so that new processes (created with fork+exec) don't inherit open files, which can be important for a number of reasons. Since O_CLOEXEC is relatively new (POSIX.1-2008, before that Linux specific), we #define it to 0 in io.h to prevent compilation errors on older/crappy systems. At least this is the plan. input.c creates a pipe. For that, add a mp_set_cloexec() function (which is based on Weston's code in vo_wayland.c, but more correct). We could use pipe2() instead, but that is Linux specific. Technically, we have a race condition, but it won't matter.
Diffstat (limited to 'mpvcore/player/command.c')
-rw-r--r--mpvcore/player/command.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/mpvcore/player/command.c b/mpvcore/player/command.c
index d8a317413f..129c0aa58a 100644
--- a/mpvcore/player/command.c
+++ b/mpvcore/player/command.c
@@ -65,6 +65,8 @@
#include <sys/mman.h>
#endif
+#include "osdep/io.h"
+
#include "mp_core.h"
#include "mp_lua.h"
@@ -2334,7 +2336,7 @@ static int overlay_add(struct MPContext *mpctx, int id, int x, int y,
fd = -1;
close_fd = false;
} else {
- fd = open(file, O_RDONLY | O_BINARY);
+ fd = open(file, O_RDONLY | O_BINARY | O_CLOEXEC);
}
void *p = mmap(NULL, h * stride, PROT_READ, MAP_SHARED, fd, offset);
if (fd >= 0 && close_fd)