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>
This commit is contained in:
Elias Naur 2023-03-11 13:05:25 -06:00 committed by Laurent Pinchart
parent e39f046f66
commit d942bdc913

View file

@ -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 '"