From d942bdc913c5a7f0895bfcb0180db3f279be246e Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 11 Mar 2023 13:05:25 -0600 Subject: 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 Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- src/libcamera/v4l2_device.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libcamera/v4l2_device.cpp') 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 '" -- cgit v1.2.1