aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/fcntl.h
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-10-17 02:30:26 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:43:01 -0400
commit22d2b35b200f76085c16a2e14ca30b58510fcbe7 (patch)
tree669ce98845b73c0a2e12b37beaa24aed8481e1d2 /include/linux/fcntl.h
parent18796aa00243a594a2bd6733f1360aa38c3cd8f4 (diff)
F_DUPFD_CLOEXEC implementation
One more small change to extend the availability of creation of file descriptors with FD_CLOEXEC set. Adding a new command to fcntl() requires no new system call and the overall impact on code size if minimal. If this patch gets accepted we will also add this change to the next revision of the POSIX spec. To test the patch, use the following little program. Adjust the value of F_DUPFD_CLOEXEC appropriately. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #ifndef F_DUPFD_CLOEXEC # define F_DUPFD_CLOEXEC 12 #endif int main (int argc, char *argv[]) { if (argc > 1) { if (fcntl (3, F_GETFD) == 0) { puts ("descriptor not closed"); exit (1); } if (errno != EBADF) { puts ("error not EBADF"); exit (1); } exit (0); } int fd = fcntl (STDOUT_FILENO, F_DUPFD_CLOEXEC, 0); if (fd == -1 && errno == EINVAL) { puts ("F_DUPFD_CLOEXEC not supported"); return 0; } if (fd != 3) { puts ("program called with descriptors other than 0,1,2"); return 1; } execl ("/proc/self/exe", "/proc/self/exe", "1", NULL); puts ("execl failed"); return 1; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ulrich Drepper <drepper@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christoph Hellwig <hch@lst.de> Cc: <linux-arch@vger.kernel.org> Cc: Kyle McMartin <kyle@mcmartin.ca> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/fcntl.h')
-rw-r--r--include/linux/fcntl.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h
index 40b93265d4ba..86037400a6e3 100644
--- a/include/linux/fcntl.h
+++ b/include/linux/fcntl.h
@@ -3,12 +3,17 @@
3 3
4#include <asm/fcntl.h> 4#include <asm/fcntl.h>
5 5
6/* Cancel a blocking posix lock; internal use only until we expose an 6#define F_SETLEASE (F_LINUX_SPECIFIC_BASE + 0)
7 * asynchronous lock api to userspace: */ 7#define F_GETLEASE (F_LINUX_SPECIFIC_BASE + 1)
8#define F_CANCELLK (F_LINUX_SPECIFIC_BASE+5)
9 8
10#define F_SETLEASE (F_LINUX_SPECIFIC_BASE+0) 9/*
11#define F_GETLEASE (F_LINUX_SPECIFIC_BASE+1) 10 * Cancel a blocking posix lock; internal use only until we expose an
11 * asynchronous lock api to userspace:
12 */
13#define F_CANCELLK (F_LINUX_SPECIFIC_BASE + 5)
14
15/* Create a file descriptor with FD_CLOEXEC set. */
16#define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6)
12 17
13/* 18/*
14 * Request nofications on a directory. 19 * Request nofications on a directory.