From patchwork Sat Jul 25 12:24:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 8997 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 44157BD878 for ; Sat, 25 Jul 2020 13:03:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1ED9061384; Sat, 25 Jul 2020 15:03:28 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A4F5461223 for ; Sat, 25 Jul 2020 14:24:49 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id f7so1014111pln.13 for ; Sat, 25 Jul 2020 05:24:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ScdbYZrkdaR2xP65QRge/jc73B6q7JflgJPqSB4oq78=; b=gnFPC/dku6vG3liWiSe5vbazzYY4kjHgvIQG/gR2iuIaINqwwVTZqmKxfW/1JOZmIu wt15WlgUn1R/qmgV9BHMtCr0dQHpABnqJAWwLM9XwVAQDKERIO65pGFDNkus64Er4Wfc GHJMth/+uGNrUV4tzyqJQ75lZrCqI/R1Cqic3RUIA6rsrIsUcgsxzIf0R9YqBiCp3QVF DRzACM85SAD7f9RMmdbH9Z0liJcpi+6Ph/8sBKizU6UPHZqHgh2zfbxfpJunAw0ZAAcD WHUsc+8UqOVBroNOO337BR05onmgyDltRm8+vWX7mQRefpOLLdcy7QRKMWDsKiUxb9xx dQpA== X-Gm-Message-State: AOAM531WD7VYNXqL7ZWT234nm4tRAqkldIkGwuJqS+9/6t1f4PG6Rh/w tq6xBwhDcqtK5UAKtQWk9IGo+vkQw/4= X-Google-Smtp-Source: ABdhPJy3F4tTVMmiIgPo8q+gg8ebqtv9eUu0GEnbjRVSYVUffc4JbGQJoPG9ScF0xjbpIV3NdYNFOA== X-Received: by 2002:a17:90a:c68e:: with SMTP id n14mr9507183pjt.182.1595679887714; Sat, 25 Jul 2020 05:24:47 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id n25sm9631393pff.51.2020.07.25.05.24.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 05:24:46 -0700 (PDT) From: You-Sheng Yang To: libcamera-devel@lists.libcamera.org Date: Sat, 25 Jul 2020 20:24:40 +0800 Message-Id: <20200725122442.1679820-2-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200725122442.1679820-1-vicamo.yang@canonical.com> References: <20200725122442.1679820-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 25 Jul 2020 15:03:26 +0200 Subject: [libcamera-devel] [PATCH 1/3] libcamera: process: fix killing innocent processes unexpectedly 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When a libcamera::process is being destructed or called kill() without a previous successful call to start(), it's pid_ may remains -1, which causes all the killable processes being killed when passed to `kill(pid_, SIG_KILL)`. Signed-off-by: You-Sheng Yang Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/process.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index e816ee8..8311d27 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -373,7 +373,8 @@ void Process::died(int wstatus) */ void Process::kill() { - ::kill(pid_, SIGKILL); + if (pid_ > 0) + ::kill(pid_, SIGKILL); } } /* namespace libcamera */ From patchwork Sat Jul 25 12:24:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 8998 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 20BCEBD878 for ; Sat, 25 Jul 2020 13:03:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B586D61392; Sat, 25 Jul 2020 15:03:28 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DAC561247 for ; Sat, 25 Jul 2020 14:24:52 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id k4so5897073pld.12 for ; Sat, 25 Jul 2020 05:24:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ozfoK3uawtbjSmM8oTXxM7sgf8Ans2dye0VC8eogObo=; b=DtsR2lBZdbHjeJ5eQEM8SBfXhkAbxlgGLjUqD2hus5gx/gsvCjcF5FTKFJ6fFBoUFG wvBpHi4g5KLWb+MukaZFUzqBphdSInBkrRaWZfQiioPP/IZPCkamC4FoD77/CDyP8l3/ fwJaPgkABd2tnTX3mm3GiM3pQgeSciqCWJaBtikzVgTR/uXXB0jPlTcvv9+bA1p6GNWv lnOd/L5VQeKTe37bZEf2FUhxyHEWMZg+RzKhFKVLT1ej+qyJZtnLshEOPxROVcNahSGj LQuSdHvpHyUit1ZSU/E7rx1czZgb0r8sgCLSFvdZJUVQ3cFHTRuZWKrxYYEFXq/nfJxl 0Keg== X-Gm-Message-State: AOAM531YaDHdqm+h9pJ60N9RtFhjun78Y2f/cEmEqbp41kBM2TyCkxFW VdHFopIqFNre62Zc0z6pP/2d9fEd5nI= X-Google-Smtp-Source: ABdhPJxUYEFlWO0YXnDFtTrZ9KtyFguDArp/wrQPEVSBw3i6uds1hmad/TDYfSf9qrR7yJ7vF8eW7A== X-Received: by 2002:a17:902:7e01:: with SMTP id b1mr12317419plm.310.1595679890537; Sat, 25 Jul 2020 05:24:50 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id q24sm9479757pfg.95.2020.07.25.05.24.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 05:24:49 -0700 (PDT) From: You-Sheng Yang To: libcamera-devel@lists.libcamera.org Date: Sat, 25 Jul 2020 20:24:41 +0800 Message-Id: <20200725122442.1679820-3-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200725122442.1679820-1-vicamo.yang@canonical.com> References: <20200725122442.1679820-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 25 Jul 2020 15:03:26 +0200 Subject: [libcamera-devel] [PATCH 2/3] test: log/process: check CAP_SYS_ADMIN in test init 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" While these tests may be executed as normal user at build time, unshare() call will fail and so are tests log_process and process_test. This change checks if one is granted with necessary capabilities so that we don't fail the build unexpectedly. Signed-off-by: You-Sheng Yang --- test/log/log_process.cpp | 20 ++++++++++++++++++++ test/log/meson.build | 2 +- test/meson.build | 2 ++ test/process/meson.build | 2 +- test/process/process_test.cpp | 23 +++++++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp index d46d5e3..876da22 100644 --- a/test/log/log_process.cpp +++ b/test/log/log_process.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,25 @@ class LogProcessTest : public Test protected: int init() { + int ret = TestPass; + + cap_t caps = cap_get_proc(); + if (caps == NULL) { + cerr << "failed to check process capabilities" << endl; + return TestFail; + } + + /* Check required permissions: CAP_SYS_ADMIN: unshare */ + cap_flag_value_t fv; + if ((cap_get_flag(caps, CAP_SYS_ADMIN, CAP_EFFECTIVE, &fv) < 0) || (fv != CAP_SET)) { + cerr << "skip due to insufficient capability" << endl; + ret = TestSkip; + } + + cap_free(caps); + if (ret != TestPass) + return ret; + random_device random; num_ = random(); logPath_ = "/tmp/libcamera.worker.test." + diff --git a/test/log/meson.build b/test/log/meson.build index 8cd664e..000f980 100644 --- a/test/log/meson.build +++ b/test/log/meson.build @@ -7,7 +7,7 @@ log_test = [ foreach t : log_test exe = executable(t[0], t[1], - dependencies : libcamera_dep, + dependencies : [libcamera_dep, libcap], link_with : test_libraries, include_directories : test_includes_internal) diff --git a/test/meson.build b/test/meson.build index f41d6e7..b4db328 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 +libcap = dependency('libcap', required : true) + subdir('libtest') subdir('camera') diff --git a/test/process/meson.build b/test/process/meson.build index c215fa7..828c17b 100644 --- a/test/process/meson.build +++ b/test/process/meson.build @@ -6,7 +6,7 @@ process_tests = [ foreach t : process_tests exe = executable(t[0], t[1], - dependencies : libcamera_dep, + dependencies : [libcamera_dep, libcap], link_with : test_libraries, include_directories : test_includes_internal) diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp index ce0cc7c..ffa2143 100644 --- a/test/process/process_test.cpp +++ b/test/process/process_test.cpp @@ -5,6 +5,8 @@ * process_test.cpp - Process test */ +#include + #include #include #include @@ -41,6 +43,27 @@ public: } protected: + int init() + { + int ret = TestPass; + + cap_t caps = cap_get_proc(); + if (caps == NULL) { + cerr << "failed to check process capabilities" << endl; + return TestFail; + } + + /* Check required permissions: CAP_SYS_ADMIN: unshare */ + cap_flag_value_t fv; + if ((cap_get_flag(caps, CAP_SYS_ADMIN, CAP_EFFECTIVE, &fv) < 0) || (fv != CAP_SET)) { + cerr << "skip due to insufficient capability" << endl; + ret = TestSkip; + } + + cap_free(caps); + return ret; + } + int run() { EventDispatcher *dispatcher = Thread::current()->eventDispatcher(); From patchwork Sat Jul 25 12:24:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 8999 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 6D3B4BD879 for ; Sat, 25 Jul 2020 13:03:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 467D8612F1; Sat, 25 Jul 2020 15:03:29 +0200 (CEST) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A77261223 for ; Sat, 25 Jul 2020 14:24:55 +0200 (CEST) Received: by mail-pg1-f171.google.com with SMTP id w2so6843052pgg.10 for ; Sat, 25 Jul 2020 05:24:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kSKmT6S8K89Zy2ALnmBZGLkqWO9SHmmfudG5vSedVO4=; b=NkGxbvNk/ssS9R2YDe72D4dou7yj8vaL68FYY62YQUV6NM6wCv4IRENONk4GWBBtel Y90YwF41ZMbA6RYvekCkCw9C6IyzS/uQyCDMlQl1sv8/MBuT9XBc6BgN7sHl3kXFWD54 AqbyEmim54Fcaee2dv0csVpmehO9wsEksGOW2otm18JsTxLcA/bZqNZe2WIfubU3krBi 3IW4PBkRTipVlJaZg/2VzwX4jY5xz5CIi5iO4jrH57dOdu3QBGIRGEPIEzxTug2V1C1x z8z1Qamdx//nhZj4rtJPRXU/sWkft8R6bFM5wrgDa0qe5AdL8yoTXHritqmVeJR5AuZ2 9KdQ== X-Gm-Message-State: AOAM532CE9MY5XSJwNyLtvsjB5hh/7hrOBW6hv0bR61pN3hEwcxTlKXJ X9ApsyaZPV+j5zV3vWHxcDyIXmEHiFY= X-Google-Smtp-Source: ABdhPJwWoPVi44SPzj+rJGk4vNy3Emz6YM4dfrnet6ECwbpbmxFmUQ/t/bMA/1YC9mNephwtEqMxDA== X-Received: by 2002:a63:9201:: with SMTP id o1mr11028193pgd.99.1595679893751; Sat, 25 Jul 2020 05:24:53 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id d37sm8887731pgd.18.2020.07.25.05.24.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 05:24:53 -0700 (PDT) From: You-Sheng Yang To: libcamera-devel@lists.libcamera.org Date: Sat, 25 Jul 2020 20:24:42 +0800 Message-Id: <20200725122442.1679820-4-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200725122442.1679820-1-vicamo.yang@canonical.com> References: <20200725122442.1679820-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 25 Jul 2020 15:03:26 +0200 Subject: [libcamera-devel] [PATCH 3/3] test: list-cameras: skip if no camera is available 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Signed-off-by: You-Sheng Yang --- test/list-cameras.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/list-cameras.cpp b/test/list-cameras.cpp index e6a407a..f4cd3b7 100644 --- a/test/list-cameras.cpp +++ b/test/list-cameras.cpp @@ -26,7 +26,7 @@ protected: return TestFail; } - return 0; + return cm_->cameras().size() ? TestPass : TestSkip; } int run()