[libcamera-devel] [PATCH v2 1/2] libcamera: v4l2_device, v4l2_videodevice: call open system call directly
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Sun Dec 15 16:43:16 CET 2019
Hi Paul,
Thank you for the patch.
On Sun, Dec 08, 2019 at 11:56:02PM -0500, Paul Elder wrote:
> We are preparing to integrate the V4L2 adaptation layer, which will
> intercept open() calls (among others) via LD_PRELOAD. To prevent
> libcamera's own open() calls from being intercepted, replace them with a
> direct syscall.
>
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>
We may want to later use syscall() for more of our calls in order to
improve performances. I'm in particular thinking about ioctl(). We
should then provide a helper to do so, but for now, I think using
syscall() directly is fine.
> ---
> No change in v2
> ---
> src/libcamera/v4l2_device.cpp | 3 ++-
> src/libcamera/v4l2_videodevice.cpp | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 0452f801..f16931a3 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -11,6 +11,7 @@
> #include <iomanip>
> #include <string.h>
> #include <sys/ioctl.h>
> +#include <sys/syscall.h>
> #include <unistd.h>
>
> #include "log.h"
> @@ -75,7 +76,7 @@ int V4L2Device::open(unsigned int flags)
> return -EBUSY;
> }
>
> - int ret = ::open(deviceNode_.c_str(), flags);
> + int ret = syscall(SYS_open, deviceNode_.c_str(), flags);
SYS_open is deprecated (but still supported of course) in favour of
SYS_openat. Should we already switch to
int ret = syscall(SYS_openat, AT_FDCWD, deviceNode_.c_str(), flags);
? glibc does so. I'm also wondering if we should set O_LARGEFILE
unconditionally, but that seems to need some more research.
> if (ret < 0) {
> ret = -errno;
> LOG(V4L2, Error) << "Failed to open V4L2 device: "
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 99213075..2dff3d3c 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -13,6 +13,7 @@
> #include <string.h>
> #include <sys/ioctl.h>
> #include <sys/mman.h>
> +#include <sys/syscall.h>
> #include <sys/time.h>
> #include <unistd.h>
> #include <vector>
> @@ -1427,7 +1428,7 @@ int V4L2M2MDevice::open()
> * as the V4L2VideoDevice::open() retains a handle by duplicating the
> * fd passed in.
> */
> - fd = ::open(deviceNode_.c_str(), O_RDWR | O_NONBLOCK);
> + fd = syscall(SYS_open, deviceNode_.c_str(), O_RDWR | O_NONBLOCK);
Same here. With this addressed (or not if you think it's not needed),
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> if (fd < 0) {
> ret = -errno;
> LOG(V4L2, Error)
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list