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. --- stream/dvb_tune.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'stream/dvb_tune.c') diff --git a/stream/dvb_tune.c b/stream/dvb_tune.c index ded2e28681..ddeabd2385 100644 --- a/stream/dvb_tune.c +++ b/stream/dvb_tune.c @@ -34,7 +34,9 @@ #include #include #include + #include "config.h" +#include "osdep/io.h" #include "dvbin.h" #include "dvb_tune.h" #include "mpvcore/mp_msg.h" @@ -88,7 +90,7 @@ int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt) sprintf(frontend_dev, "/dev/dvb/adapter%d/frontend0", n); sprintf(dvr_dev, "/dev/dvb/adapter%d/dvr0", n); sprintf(demux_dev, "/dev/dvb/adapter%d/demux0", n); - priv->fe_fd = open(frontend_dev, O_RDWR | O_NONBLOCK); + priv->fe_fd = open(frontend_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC); if(priv->fe_fd < 0) { mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING FRONTEND DEVICE %s: ERRNO %d\n", frontend_dev, errno); @@ -98,7 +100,7 @@ int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt) mp_msg(MSGT_DEMUX, MSGL_V, "DVB_OPEN_DEVICES(%d)\n", demux_cnt); for(i = 0; i < demux_cnt; i++) { - priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK); + priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC); if(priv->demux_fds[i] < 0) { mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 0: %d\n", errno); @@ -112,7 +114,7 @@ int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt) } - priv->dvr_fd = open(dvr_dev, O_RDONLY| O_NONBLOCK); + priv->dvr_fd = open(dvr_dev, O_RDONLY| O_NONBLOCK | O_CLOEXEC); if(priv->dvr_fd < 0) { mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DVR DEVICE %s: %d\n", dvr_dev, errno); @@ -143,7 +145,7 @@ int dvb_fix_demuxes(dvb_priv_t *priv, int cnt) { for(i = priv->demux_fds_cnt; i < cnt; i++) { - priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK); + priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC); mp_msg(MSGT_DEMUX, MSGL_V, "FIX, OPEN fd(%d): %d\n", i, priv->demux_fds[i]); if(priv->demux_fds[i] < 0) { -- cgit v1.2.3