From patchwork Sun Mar 12 21:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elias Naur X-Patchwork-Id: 18381 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 680BBBD80A for ; Sun, 12 Mar 2023 21:22:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A31A262709; Sun, 12 Mar 2023 22:22:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678656147; bh=4WxkpYPtetm9YgRs928jTWgIkeXtHrfo82XwUTZVtso=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QCzKZKs7qY4JWc6KIpfqyQ0yHmZPNp2CALBl82wl3bERdhKh8CFEWlBfY0gUKnoXG 8A95yhAGluX9ZbeXHPHQ/VekgsNPTOWtPj+3yKO+2u96zLTrQ38RvET5KO/9MgNyRn 6AozXz5m6cB7rZwiHfVFyV4IMUyefK2z+4EV0f5/1xn4skMPGRPSoOo8LfcdrQFEz0 fMaYqoNGx4Fh09LmaO0cTU9oCoXfQjeFWuQpN6kBnwihH5Jkjt7dk0q4wbAUAm6cxo OxTT8cJTcsX78xjqxr8hPNgeYLDxeWDGj+SPvZpn0YwIDJNM53TMBXKL8etv7I5aF4 gsTrV/AOgUzsA== Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 65F6762705 for ; Sun, 12 Mar 2023 22:22:26 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=eliasnaur.com header.i=@eliasnaur.com header.b="e86OH/5o"; dkim-atps=neutral Received: by mail-ua1-x935.google.com with SMTP id 89so160212uao.0 for ; Sun, 12 Mar 2023 14:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eliasnaur.com; s=google; t=1678656145; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hHk7FH35GQEzC75IuaVuRQmjLtjMeQoLbiO0819cHME=; b=e86OH/5oKAqhc4vkoiq8tclkmMdAiWn1cqw2ymrTtXXG3rebplq9kRwNP//yHAIy+B 8dh/5EGhLob4cNxesA5Vg4i8rV7EeyHeAYwIXPoaTNIQIdwuRO1QIeyc7+iL5M0N8j81 Y1rH+8iwx4cX7HrSpHNFkiiHvocR8iFHabD3AKcKGRGyVfHv9WUMt5Hsb1h6jC0+WAVn MTbaLrIlkuaIJbhS/gwWS4qqyF5bnwXHfvdo5dFyr+Ze/GNdrz7GT/kCfSJRmtPaQ8Js AZI+nJXDMc5+cwk9/+zLvrw7CJBkaxZulU9H2cgj9vYS57y2tEsjMzmnxPHmqlDe8tLy YrjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678656145; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hHk7FH35GQEzC75IuaVuRQmjLtjMeQoLbiO0819cHME=; b=26NJKVVXReBsLuFk/ImlOJdfbOtNtIw18qCLbBDJc6s5RxkOKcoKdGaU6CZIOdqD3x 2VHL80Ja1E6IdDQ6UV3RJRz4gEF6cOAzCWQWWoZpHNPueuXmKC35WIut1LtAVjKXpTc9 x9EJkWbD6PLwN6Xg28orVXPGEd6uhAX5Al9S3RG8wAsttGqleTNA0XPfD1u/RjoM/UPE 3nJwOepCE11s1/9+wv4n/qXLnPmbsx8oOXigsY8R8BK2fBBAuvhvd0QBZsSA85LiSY25 ijGmWt2YHLWNRxey1hFQWsbjGpTQKFnE1X8hsOLlbpe4k3xaIXVAPe7E6a8f1fs0mukp hMyQ== X-Gm-Message-State: AO0yUKXX2be3T5YBqxZM8qJOtNqzs0z9HXKaGm4ufoeBIFBGw+suRM// 1PzZJwcuaxFLsjzKHqSyqK5378CNHXrQOWXsHcA= X-Google-Smtp-Source: AK7set/RyAr1x0vAhgBnMOutSE5BJaTW6fVc36UgB1wEgov3oZ1DCBOWyzWO5PaliBoxkA9a3/2LJg== X-Received: by 2002:a1f:2790:0:b0:431:fa2d:402f with SMTP id n138-20020a1f2790000000b00431fa2d402fmr263476vkn.15.1678656144958; Sun, 12 Mar 2023 14:22:24 -0700 (PDT) Received: from localhost.localdomain ([190.53.0.133]) by smtp.gmail.com with ESMTPSA id w143-20020a1fad95000000b003bd94c3a733sm909594vke.0.2023.03.12.14.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Mar 2023 14:22:24 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sun, 12 Mar 2023 15:22:05 -0600 Message-Id: <20230312212205.44168-1-mail@eliasnaur.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: openat(2) with O_CLOEXEC to cleanup after exec(3) X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Elias Naur via libcamera-devel From: Elias Naur Reply-To: Elias Naur Cc: Elias Naur Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" It's generally a good idea to openat(2) with O_CLOEXEC, but this patch also fixes a real (corner-)case: I have an excutable that (1) uses v4l2-compat to drive a RPi camera, (2) self-updates through exec(3). Without O_CLOEXEC of the kernel devices, an update while the camera is opened will result in -EBUSY errors when the update tries to open the camera. Signed-off-by: Elias Naur --- This update fixes a style issue raised through review and clarifies the motivatition for the fix. src/libcamera/v4l2_device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git src/libcamera/v4l2_device.cpp src/libcamera/v4l2_device.cpp index 57a88d96..9eb26839 100644 --- src/libcamera/v4l2_device.cpp +++ src/libcamera/v4l2_device.cpp @@ -86,7 +86,7 @@ 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 '"