v4l2: Set O_CLOEXEC on the device fd
authorArun Raghavan <git@arunraghavan.net>
Tue, 3 Nov 2015 16:31:07 +0000 (22:01 +0530)
committerArun Raghavan <git@arunraghavan.net>
Tue, 3 Nov 2015 16:32:38 +0000 (22:02 +0530)
This is needed to make sure that child processes don't inherit the video
device fd which can cause problems with some drivers.

sys/v4l2/gstv4l2.c

index 08ff3f582aa362d3ec52e66990f5b939cceff112..8333eab41e26b11f467585d3e397d452f633c7b2 100644 (file)
 #include "config.h"
 #endif
 
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE            /* O_CLOEXEC */
+#endif
+
 #include "gst/gst-i18n-plugin.h"
 
 #include <gst/gst.h>
@@ -124,7 +128,8 @@ gst_v4l2_probe_and_register (GstPlugin * plugin)
     if (video_fd >= 0)
       close (video_fd);
 
-    video_fd = open (it->device_path, O_RDWR);
+    video_fd = open (it->device_path, O_RDWR | O_CLOEXEC);
+
     if (video_fd == -1) {
       GST_DEBUG ("Failed to open %s: %s", it->device_path, g_strerror (errno));
       continue;