From 95cfe58e3db9d939abe7a9a26116c1d576eed60b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 30 Nov 2013 22:40:51 +0100 Subject: 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. --- mpvcore/input/input.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'mpvcore/input') diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c index 3e0313976a..744d474919 100644 --- a/mpvcore/input/input.c +++ b/mpvcore/input/input.c @@ -2309,12 +2309,17 @@ struct input_ctx *mp_input_init(struct mpv_global *global) } #ifndef __MINGW32__ - long ret = pipe(ictx->wakeup_pipe); - for (int i = 0; i < 2 && ret >= 0; i++) { - ret = fcntl(ictx->wakeup_pipe[i], F_GETFL); - if (ret < 0) - break; - ret = fcntl(ictx->wakeup_pipe[i], F_SETFL, ret | O_NONBLOCK); + int ret = pipe(ictx->wakeup_pipe); + if (ret == 0) { + for (int i = 0; i < 2 && ret >= 0; i++) { + mp_set_cloexec(ictx->wakeup_pipe[i]); + ret = fcntl(ictx->wakeup_pipe[i], F_GETFL); + if (ret < 0) + break; + ret = fcntl(ictx->wakeup_pipe[i], F_SETFL, ret | O_NONBLOCK); + if (ret < 0) + break; + } } if (ret < 0) MP_ERR(ictx, "Failed to initialize wakeup pipe: %s\n", strerror(errno)); -- cgit v1.2.3