summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_device.cpp
diff options
context:
space:
mode:
authorElias Naur <mail@eliasnaur.com>2023-03-11 13:05:25 -0600
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2023-03-26 11:48:18 +0300
commitd942bdc913c5a7f0895bfcb0180db3f279be246e (patch)
tree943e9f40827488d8275159d4428e3db5d07b4f6d /src/libcamera/v4l2_device.cpp
parente39f046f660a6d0954d81b92bd183e7ba679fa56 (diff)
libcamera: v4l2_device: openat(2) with O_CLOEXEC to cleanup after exec(3)
When an executable using libcamera calls exec(3) while a camera is in use, file descriptors corresponding to the V4L2 video devices are kept open has they have been created without O_CLOEXEC. This results in the video devices staying busy, preventing the new executable from using them: [91] ERROR V4L2 v4l2_videodevice.cpp:1047 /dev/video0[149:cap]: Unableto set format: Resource busy Fix this by opening video devices with O_CLOEXEC, which is generally a good idea in libraries. Signed-off-by: Elias Naur <mail@eliasnaur.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/v4l2_device.cpp')
-rw-r--r--src/libcamera/v4l2_device.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 57a88d96..24d208ef 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -86,7 +86,8 @@ int V4L2Device::open(unsigned int flags)
return -EBUSY;
}
- UniqueFD fd(syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(), flags));
+ UniqueFD fd(syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(),
+ flags | O_CLOEXEC));
if (!fd.isValid()) {
int ret = -errno;
LOG(V4L2, Error) << "Failed to open V4L2 device '"