Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp1295492ybd; Sun, 23 Jun 2019 04:28:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqysaCzwlVbqvuObwt87tNsQjxuigoqjo358EiujnsevqOrIlPPjVLC2mtzXysJVupRNeR29 X-Received: by 2002:a63:d748:: with SMTP id w8mr26901531pgi.157.1561289314583; Sun, 23 Jun 2019 04:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561289314; cv=none; d=google.com; s=arc-20160816; b=jjNPsI8p96HGF1so0zMzBQ6XRfQNxEGroKP+GOtPTqvpju9mAdLSp7SinYmdu2z9XC wD429fLbcbG1xknBwNMX5pj9pFZsEA3CnodYZy6kJdqwHvPPCS+oooS/fhq6E6pOPEhI UYQud0rSjMDU/zrZJGZuGpgPFQsrTJUdHA4luQZQcPxXAtVCskiVLIeTaBt3LyC//xJ6 cKr5w/q7aGFznKl8q5mCs5qfQShrazACBb+FynMxX9dXZX0wchUkc7OpPBX+1SxhSoZu kNp5OPXlUC2rvIm+wp7I0Zn0CI3X8I1lblCAsPGmY2cHXnyyAChy6XHFVX5b5MJmVHhN ZEIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=GpYz53dhVbV49PTO1ZVjKAfttU/vLKHeBoyZzX+WICo=; b=ah4BgH6H7ewH6Q8UJFfFRMLWzkUhvlxLetwsilHlzrzx/kIDf4v58BfTGkINPeCm7d oirV1jMuLdPk4BSmUC8gYTpwX0fEWPWrOT42IPll/iD8whoxdFDfkac3bvzwvg//ZWIG I6xMqgM5rmvDT5cNY73FkyM+VnLcOqPEnUPyzSfxzMWc+BXHpaMPIP9cfefcc3UhHcH9 LYkFs5uCrdap4PNGAUO3Z8cVpWZ/3Qvj/lg8l19aoB/V8i+N17Sj++3zTztJwQGRp8zv vwlnLb4hF3O980d86zzHjsgju38yxaeu4hDNbUvUnS2HG3DYoso3hcgQNNYZzX+EvLF0 8obA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q18si5515691pll.175.2019.06.23.04.28.12; Sun, 23 Jun 2019 04:28:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726549AbfFWL2D (ORCPT + 99 others); Sun, 23 Jun 2019 07:28:03 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:39540 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726350AbfFWL2C (ORCPT ); Sun, 23 Jun 2019 07:28:02 -0400 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 93EAC72CC6C; Sun, 23 Jun 2019 14:28:00 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 893797CCE2E; Sun, 23 Jun 2019 14:28:00 +0300 (MSK) Date: Sun, 23 Jun 2019 14:28:00 +0300 From: "Dmitry V. Levin" To: Christian Brauner Cc: Jann Horn , Oleg Nesterov , Arnd Bergmann , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] samples: make pidfd-metadata fail gracefully on older kernels Message-ID: <20190623112800.GB20697@altlinux.org> References: <20190620103105.cdxgqfelzlnkmblv@brauner.io> <20190620110037.GA4998@altlinux.org> <20190620111036.asi3mbcv4ax5ekrw@brauner.io> <20190621170613.GA26182@altlinux.org> <20190621221339.6yj4vg4zexv4y2j7@brauner.io> <20190623112717.GA20697@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190623112717.GA20697@altlinux.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Initialize pidfd to an invalid descriptor, to fail gracefully on those kernels that do not implement CLONE_PIDFD and leave pidfd unchanged. Signed-off-by: Dmitry V. Levin --- samples/pidfd/pidfd-metadata.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/pidfd/pidfd-metadata.c b/samples/pidfd/pidfd-metadata.c index 14b454448429..c459155daf9a 100644 --- a/samples/pidfd/pidfd-metadata.c +++ b/samples/pidfd/pidfd-metadata.c @@ -83,7 +83,7 @@ static int pidfd_metadata_fd(pid_t pid, int pidfd) int main(int argc, char *argv[]) { - int pidfd = 0, ret = EXIT_FAILURE; + int pidfd = -1, ret = EXIT_FAILURE; char buf[4096] = { 0 }; pid_t pid; int procfd, statusfd; @@ -91,7 +91,11 @@ int main(int argc, char *argv[]) pid = pidfd_clone(CLONE_PIDFD, &pidfd); if (pid < 0) - exit(ret); + err(ret, "CLONE_PIDFD"); + if (pidfd == -1) { + warnx("CLONE_PIDFD is not supported by the kernel"); + goto out; + } procfd = pidfd_metadata_fd(pid, pidfd); close(pidfd); -- ldv