Merge tag 'spi-fix-v5.9-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
[linux-2.6-microblaze.git] / samples / pidfd / pidfd-metadata.c
index 14b4544..c459155 100644 (file)
@@ -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);