[patch] fcntl.2: Add ESRCH to list of ERRORS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everyone,

when setting the notified PID for async operations using F_SETOWN
(F_SETOWN_EX respectively), the operation may fail if no process with
the specified PID is alive and visible to the caller. In this case, the
errno is set to ESRCH. This was introduced in the kernel by
f73127356f344483c82632accda2e72b7e0e5f25.

Here is an example program showing this behavior

setown_nonexisting.c:

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
static void die(const char *msg)
{
	perror(msg);
	exit(EXIT_FAILURE);
}

int main(void)
{
	int fd = open("/dev/null", O_RDONLY | O_ASYNC);
	if (fd < 0) {
		die("open");
	}
	/* Assuming there is no process with PID 999999 */
	if (fcntl(fd, F_SETOWN, 999999) < 0) {
		die("fcntl");
	}
	return EXIT_SUCCESS;
}

$ cc ./setown_nonexisting.c
$ ./a.out
fcntl: No such process

I hope my patch is according to the standards.

Best regards
Paul Bergmann
From 205e31af064cd886b6ecfb8597054007278af4b4 Mon Sep 17 00:00:00 2001
From: Paul Bergmann <paul.bergmann@xxxxxx>
Date: Thu, 10 Mar 2022 16:27:01 +0100
Subject: [PATCH] [patch] fcntl.2: Add ESRCH to list of ERRORS

When setting the notified PID for async operations using F_SETOWN
(F_SETOWN_EX respectively), the operation may fail if no process with
the specified PID is alive and visible to the caller. In this case, the
errno is set to ESRCH. This was introduced in the kernel by
f73127356f344483c82632accda2e72b7e0e5f25.

Here is an example program showing this behavior

setown_nonexisting.c:

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
static void die(const char *msg)
{
	perror(msg);
	exit(EXIT_FAILURE);
}

int main(void)
{
	int fd = open("/dev/null", O_RDONLY | O_ASYNC);
	if (fd < 0) {
		die("open");
	}
	/* Assuming there is no process with PID 999999 */
	if (fcntl(fd, F_SETOWN, 999999) < 0) {
		die("fcntl");
	}
	return EXIT_SUCCESS;
}

$ cc ./setown_nonexisting.c
$ ./a.out
fcntl: No such process
---
 man2/fcntl.2 | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/man2/fcntl.2 b/man2/fcntl.2
index 7b5604e3a..18651321f 100644
--- a/man2/fcntl.2
+++ b/man2/fcntl.2
@@ -1827,6 +1827,18 @@ but
 was not open for writing
 or the current set of seals on the file already includes
 .BR F_SEAL_SEAL .
+.TP
+.B ESRCH
+.I cmd
+was
+.BR F_SETOWN
+(
+.BR F_SETOWN_EX
+) and
+.I arg
+(
+.I arg->pid
+) does not refer to a visible process.
 .SH CONFORMING TO
 SVr4, 4.3BSD, POSIX.1-2001.
 Only the operations
-- 
2.35.1


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux