summaryrefslogtreecommitdiffstats
path: root/stream/dvb_tune.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 /stream/dvb_tune.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 'stream/dvb_tune.c')
-rw-r--r--stream/dvb_tune.c10
1 files changed, 6 insertions, 4 deletions
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 <errno.h>
#include <linux/dvb/dmx.h>
#include <linux/dvb/frontend.h>
+
#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)
{