From: "Dmitry V. Levin" <ldv@altlinux.org>
To: Christian Brauner <christian@brauner.io>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] samples: make pidfd-metadata fail gracefully on older kernels
Date: Thu, 20 Jun 2019 06:11:44 +0300 [thread overview]
Message-ID: <20190620031144.GA32182@altlinux.org> (raw)
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 <ldv@altlinux.org>
---
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..ff109fdac3a5 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 < 0) {
+ warnx("CLONE_PIDFD is not supported by the kernel");
+ goto out;
+ }
procfd = pidfd_metadata_fd(pid, pidfd);
close(pidfd);
--
ldv
next reply other threads:[~2019-06-20 3:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 3:11 Dmitry V. Levin [this message]
2019-06-20 10:31 ` [PATCH] samples: make pidfd-metadata fail gracefully on older kernels Christian Brauner
2019-06-20 11:00 ` Dmitry V. Levin
2019-06-20 11:10 ` Christian Brauner
2019-06-21 17:06 ` Dmitry V. Levin
2019-06-21 22:13 ` Christian Brauner
2019-06-23 11:27 ` [PATCH 1/2] CLONE_PIDFD: do not use the value pointed by parent_tidptr Dmitry V. Levin
2019-06-23 11:28 ` [PATCH 2/2] samples: make pidfd-metadata fail gracefully on older kernels Dmitry V. Levin
2019-06-24 9:50 ` Christian Brauner
2019-06-24 9:49 ` [PATCH 1/2] CLONE_PIDFD: do not use the value pointed by parent_tidptr Christian Brauner
2019-06-24 11:59 ` Christian Brauner
2019-06-24 13:45 ` Dmitry V. Levin
2019-06-24 13:49 ` Christian Brauner
2019-06-23 11:32 ` [PATCH] samples: make pidfd-metadata fail gracefully on older kernels Dmitry V. Levin
2019-06-24 9:52 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190620031144.GA32182@altlinux.org \
--to=ldv@altlinux.org \
--cc=christian@brauner.io \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox