From patchwork Fri Jan 17 11:15:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1224764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=zCdxaJdh; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47zdlX2Mb7z9sR4 for ; Fri, 17 Jan 2020 22:15:36 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3957D3C2352 for ; Fri, 17 Jan 2020 12:15:33 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 959633C220B for ; Fri, 17 Jan 2020 12:15:31 +0100 (CET) Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 5C5871401A60 for ; Fri, 17 Jan 2020 12:15:30 +0100 (CET) Received: by mail-pj1-x1043.google.com with SMTP id r67so3027059pjb.0 for ; Fri, 17 Jan 2020 03:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BPkkBppjrkdlqIa4x7ppcTPgLkWitu85pqnCJSWkdqA=; b=zCdxaJdhZIr+HEOkKTNp+l53lBQY0SLSif5AA9f9DIYwS0PPR20bWMnamVj7BoIK3e NmdSktaUcYLHWJHaWP11Cj0/AV6pHMYOFLb7PY8BimA/DfpGkr8jFf6DrlL6ceWWcYcD uQtIKL78ydolMMBu1eY3Lae9aGwiMa6gk4mUQeHGvt1MyHkLapz5lU/Sy1NishnQ8TUG 0ApjrJvFlqFmg6B7fgfV3yOCs3fSzQrvwehTdbjzT8XaQWlSv2LWXNXVxtk8ZH9qAlG6 QQ6CxIMlLxH4zQhpL3fLQA5r/4R+7Vm7UsKHYVi9Gb8dxJnxfzjKoadMkj4qgDnialVv b6KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BPkkBppjrkdlqIa4x7ppcTPgLkWitu85pqnCJSWkdqA=; b=TKx335xDMIauKXF0bHABzuvXT36A/UMQyuB+y1b3hnLPFc+niZmlMxgXdXGdnEcNQ2 A94GsbVN+/PdFDCugvaeOHU0gsTE7fD9LvAj1drszfsunEYBWD9+Xe9OuBU59apR7KXH rXQDRlY2tLcXs43zAQTwhN8LyIzDQ0XN4nyZpkjsI7uQERZWu3c1Vc70WqnaSSpp6f0S ukiW3TBdDRnJA5fSUn1sXlDSYRrd16F+6A4XhqVVYTw6K1/GioJNZWR+MiMeDxgCa4pD ErAj0ei0ikDUPVEV+c926xBiXFnoiPnlNzy0DqECBck/NVVBBkhE7kqA4MS0ESyCfliI sm1w== X-Gm-Message-State: APjAAAUMOTBP5JlLv67Le7qoWPRvxDIjs83Ml1Ph/lLC6/lF5YikUcAX WYuW2lFffXVQv+9NjT50eK2O5VNLnNE= X-Google-Smtp-Source: APXvYqzToomSIMGb2eW1iMqzswoNAhs2yMV3y/wESdmduA4n+33jiiBu+m6dzkdbVvdNLaxTacYjRg== X-Received: by 2002:a17:902:8545:: with SMTP id d5mr41946865plo.116.1579259728391; Fri, 17 Jan 2020 03:15:28 -0800 (PST) Received: from localhost ([122.172.71.156]) by smtp.gmail.com with ESMTPSA id k21sm28158033pgt.22.2020.01.17.03.15.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jan 2020 03:15:27 -0800 (PST) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 17 Jan 2020 16:45:09 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] Add Syscall numbers for pidfd_open X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Viresh Kumar --- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 13 files changed, 13 insertions(+) diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in index 0e00641bcf4d..19f3aa4475bd 100644 --- a/include/lapi/syscalls/aarch64.in +++ b/include/lapi/syscalls/aarch64.in @@ -270,4 +270,5 @@ pkey_mprotect 288 pkey_alloc 289 pkey_free 290 pidfd_send_signal 424 +pidfd_open 434 _sysctl 1078 diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in index 00e99f2b99b8..29538ba50d3b 100644 --- a/include/lapi/syscalls/arm.in +++ b/include/lapi/syscalls/arm.in @@ -354,3 +354,4 @@ pkey_alloc (__NR_SYSCALL_BASE+395) pkey_free (__NR_SYSCALL_BASE+396) statx (__NR_SYSCALL_BASE+397) pidfd_send_signal (__NR_SYSCALL_BASE+424) +pidfd_open (__NR_SYSCALL_BASE+434) diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in index 4cdd109fb50e..b578d886516d 100644 --- a/include/lapi/syscalls/hppa.in +++ b/include/lapi/syscalls/hppa.in @@ -26,3 +26,4 @@ copy_file_range 346 preadv2 347 pwritev2 348 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in index 87ab4693343e..696563ebba48 100644 --- a/include/lapi/syscalls/i386.in +++ b/include/lapi/syscalls/i386.in @@ -353,3 +353,4 @@ pkey_alloc 381 pkey_free 382 statx 383 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in index cf9f73e8529b..11b236c7c507 100644 --- a/include/lapi/syscalls/ia64.in +++ b/include/lapi/syscalls/ia64.in @@ -309,3 +309,4 @@ pkey_mprotect 1354 pkey_alloc 1355 pkey_free 1356 pidfd_send_signal 1448 +pidfd_open 1458 diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in index 660165d7a37b..293d86ba54c4 100644 --- a/include/lapi/syscalls/powerpc.in +++ b/include/lapi/syscalls/powerpc.in @@ -356,6 +356,7 @@ preadv2 380 pwritev2 381 statx 383 pidfd_send_signal 424 +pidfd_open 434 pkey_mprotect 386 pkey_alloc 384 pkey_free 385 diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in index 660165d7a37b..293d86ba54c4 100644 --- a/include/lapi/syscalls/powerpc64.in +++ b/include/lapi/syscalls/powerpc64.in @@ -356,6 +356,7 @@ preadv2 380 pwritev2 381 statx 383 pidfd_send_signal 424 +pidfd_open 434 pkey_mprotect 386 pkey_alloc 384 pkey_free 385 diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in index d3f7eb1f60f7..4f4b2dbed5ef 100644 --- a/include/lapi/syscalls/s390.in +++ b/include/lapi/syscalls/s390.in @@ -343,3 +343,4 @@ pkey_mprotect 384 pkey_alloc 385 pkey_free 386 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in index 7d632d1dc0bb..673538a7217e 100644 --- a/include/lapi/syscalls/s390x.in +++ b/include/lapi/syscalls/s390x.in @@ -341,3 +341,4 @@ pkey_mprotect 384 pkey_alloc 385 pkey_free 386 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in index 132492922659..ef877fa9c25f 100644 --- a/include/lapi/syscalls/sh.in +++ b/include/lapi/syscalls/sh.in @@ -370,3 +370,4 @@ copy_file_range 391 preadv2 392 pwritev2 393 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in index 94a672428973..2b33c4983088 100644 --- a/include/lapi/syscalls/sparc.in +++ b/include/lapi/syscalls/sparc.in @@ -348,3 +348,4 @@ pkey_mprotect 362 pkey_alloc 363 pkey_free 364 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in index d17dce5cd9a3..a6157adef7b3 100644 --- a/include/lapi/syscalls/sparc64.in +++ b/include/lapi/syscalls/sparc64.in @@ -323,3 +323,4 @@ pkey_mprotect 362 pkey_alloc 363 pkey_free 364 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in index b1cbd4f2fb04..8bd6b66d3bef 100644 --- a/include/lapi/syscalls/x86_64.in +++ b/include/lapi/syscalls/x86_64.in @@ -320,3 +320,4 @@ pkey_alloc 330 pkey_free 331 statx 332 pidfd_send_signal 424 +pidfd_open 434 From patchwork Fri Jan 17 11:15:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1224765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=S62dpMFW; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47zdll1s6zz9sR4 for ; Fri, 17 Jan 2020 22:15:47 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E75F23C224E for ; Fri, 17 Jan 2020 12:15:43 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 7CA9F3C24B0 for ; Fri, 17 Jan 2020 12:15:37 +0100 (CET) Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 340A9200DD1 for ; Fri, 17 Jan 2020 12:15:33 +0100 (CET) Received: by mail-pg1-x541.google.com with SMTP id x8so11522193pgk.8 for ; Fri, 17 Jan 2020 03:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pnYLBGYGoVMpB23Ux+FhPyxs/6Pdu2xPchWkMRgD7ME=; b=S62dpMFWmLFbrLB/WrmmtGHEVNYaujBm1ERA3bCfmM4wJaeFu4SKN+vYWBfhF+h8J6 edS6LEc2K0gaU3hK4rQtm3u9F5osyQcRSipaLSREjSslm2V6PdRmUswlMawDyIvtCOwB Q8eW86texeRgqlqymAOUdtda0WBJGjmi5SiOAQdnUkGWpNuAQUoffdMqjjoWyqaqLnvT Isx42i+rVinQ/tdngHO30v4wnm/u+MadBkLhyJ0viBKQj//6uerk6LhUqP8DOHs5yq5f 3it9m33qoDlA5vFcArI0iLZW1IwhwYnOz57FHRBMIn5L+0BE3vhNQAJGFgznXiprjWrk VoLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pnYLBGYGoVMpB23Ux+FhPyxs/6Pdu2xPchWkMRgD7ME=; b=GTL5bNhkQ31FjW9rlu4pLQR/qdE1hXKqFJSiOHZtyhf2GIqZMOkRNBlGzLXBK+gj6o cpayqKaJ/3l7y0n9MgcvU89UHtYXCPrSUaSXb/gdQiRk2Glk8Ml/UvI7R2w9xwyJ0E+e 0/Kwo0ZlBtT0cA2ygIBYAtqzo93jEDfc+g6KGNUHRH/lFL0x8UeJ+1QIop0tNMrSAAn8 uPjc1mRw/4/OaehbnGqRhzHRZx4nLLVILPYxAcidqnwMOCfP0kRKxe+jMistPiln2OYx WgZkL1F1ik7kp3oje/H+mviry9ZQKdbEBA9YXbjsi9cdyultyL20VzkYCXpFGJekL6gW UpTg== X-Gm-Message-State: APjAAAVKw8cXPCovC6DmQYSH9mlOfX4dZGAo1CHq9z0TEqI0AXZbCx6o ewEl29xQVFQ3sBKUDTw6G9BHNDdPd98= X-Google-Smtp-Source: APXvYqziZmMaLukZ7jhV05/9FCM4A1+o3rJKFAHHbhoq0PtAFBHWwR/u8+6EfTMunQgZNHYbn2pCAw== X-Received: by 2002:a62:7fcd:: with SMTP id a196mr2377695pfd.208.1579259731324; Fri, 17 Jan 2020 03:15:31 -0800 (PST) Received: from localhost ([122.172.71.156]) by smtp.gmail.com with ESMTPSA id a2sm27817392pgv.64.2020.01.17.03.15.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jan 2020 03:15:30 -0800 (PST) From: Viresh Kumar To: ltp@lists.linux.it Date: Fri, 17 Jan 2020 16:45:10 +0530 Message-Id: <4dd4dabd2cd574dc2657c5926e8e3d1a0c8a8ae6.1579259595.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 2/2] syscalls/pidfd_open X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Add tests to check working of pidfd_open() syscall. Signed-off-by: Viresh Kumar --- configure.ac | 1 + include/lapi/pidfd_open.h | 21 ++++++ runtest/syscalls | 3 + .../kernel/syscalls/pidfd_open/.gitignore | 2 + testcases/kernel/syscalls/pidfd_open/Makefile | 6 ++ .../kernel/syscalls/pidfd_open/pidfd_open01.c | 38 +++++++++++ .../kernel/syscalls/pidfd_open/pidfd_open02.c | 68 +++++++++++++++++++ 7 files changed, 139 insertions(+) create mode 100644 include/lapi/pidfd_open.h create mode 100644 testcases/kernel/syscalls/pidfd_open/.gitignore create mode 100644 testcases/kernel/syscalls/pidfd_open/Makefile create mode 100644 testcases/kernel/syscalls/pidfd_open/pidfd_open01.c create mode 100644 testcases/kernel/syscalls/pidfd_open/pidfd_open02.c diff --git a/configure.ac b/configure.ac index 50d14967d3c6..1bf0911d88ad 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,7 @@ AC_CHECK_FUNCS([ \ mknodat \ name_to_handle_at \ openat \ + pidfd_open \ pidfd_send_signal \ pkey_mprotect \ preadv \ diff --git a/include/lapi/pidfd_open.h b/include/lapi/pidfd_open.h new file mode 100644 index 000000000000..ced163be83bf --- /dev/null +++ b/include/lapi/pidfd_open.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Linaro Limited. All rights reserved. + * Author: Viresh Kumar + */ + +#ifndef PIDFD_OPEN_H +#define PIDFD_OPEN_H + +#include "config.h" +#include +#include "lapi/syscalls.h" + +#ifndef HAVE_PIDFD_OPEN +int pidfd_open(pid_t pid, unsigned int flags) +{ + return tst_syscall(__NR_pidfd_open, pid, flags); +} +#endif + +#endif /* PIDFD_OPEN_H */ diff --git a/runtest/syscalls b/runtest/syscalls index fa87ef63fbc1..9d6d288780a3 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -846,6 +846,9 @@ pause03 pause03 personality01 personality01 personality02 personality02 +pidfd_open01 pidfd_open01 +pidfd_open02 pidfd_open02 + pidfd_send_signal01 pidfd_send_signal01 pidfd_send_signal02 pidfd_send_signal02 pidfd_send_signal03 pidfd_send_signal03 diff --git a/testcases/kernel/syscalls/pidfd_open/.gitignore b/testcases/kernel/syscalls/pidfd_open/.gitignore new file mode 100644 index 000000000000..be218f88647d --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/.gitignore @@ -0,0 +1,2 @@ +pidfd_open01 +pidfd_open02 diff --git a/testcases/kernel/syscalls/pidfd_open/Makefile b/testcases/kernel/syscalls/pidfd_open/Makefile new file mode 100644 index 000000000000..5ea7d67db123 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c new file mode 100644 index 000000000000..4e3417c487a6 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Viresh Kumar + * + * Description: + * Basic pidfd_open() test, fetches the PID of the current process and tries to + * get its file descriptor. + */ +#include +#include + +#include "tst_test.h" +#include "lapi/pidfd_open.h" +#include "lapi/syscalls.h" + +static void run(void) +{ + int p_id, fd; + + p_id = getpid(); + + TEST(pidfd_open(p_id, 0)); + + fd = TST_RET; + if (fd == -1) { + tst_res(TFAIL, "Cannot retrieve file descriptor to the current process"); + return; + } + + SAFE_CLOSE(fd); + + tst_res(TPASS, "Retrieved file descriptor to the current process"); +} + +static struct tst_test test = { + .min_kver = "5.3", + .test_all = run, +}; diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c new file mode 100644 index 000000000000..b67393bcafa2 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Viresh Kumar + * + * Description: + * This program opens the PID file descriptor of the child process created with + * fork(). It then uses poll to monitor the file descriptor for process exit, as + * indicated by an EPOLLIN event. + */ +#include +#include +#include +#include +#include +#include + +#include "tst_test.h" +#include "lapi/pidfd_open.h" +#include "lapi/syscalls.h" + +static void run(void) +{ + struct pollfd pollfd; + int p_id, fd, ready; + + TEST(fork()); + + if (TST_RET == -1) { + tst_res(TFAIL, "fork() Failed"); + tst_res(TBROK, "unable to continue"); + } + + if (TST_RET == 0) { + /* child */ + usleep(1000); + exit(EXIT_SUCCESS); + } else { + /* parent */ + p_id = TST_RET; + + TEST(pidfd_open(p_id, 0)); + + fd = TST_RET; + if (fd == -1) { + tst_res(TFAIL, "Cannot retrieve file descriptor to the child process"); + return; + } + + pollfd.fd = fd; + pollfd.events = POLLIN; + + ready = poll(&pollfd, 1, -1); + if (ready == -1) { + tst_res(TFAIL, "poll() Failed"); + tst_res(TBROK, "unable to continue"); + } + + printf("Events (0x%x): POLLIN is %sset\n", pollfd.revents, + (pollfd.revents & POLLIN) ? "" : "not "); + + SAFE_CLOSE(fd); + } +} + +static struct tst_test test = { + .min_kver = "5.3", + .test_all = run, +};