diff options
author | Ulrich Drepper <drepper@redhat.com> | 2008-07-24 00:29:40 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-24 13:47:29 -0400 |
commit | be61a86d7237dd80510615f38ae21d6e1e98660c (patch) | |
tree | 3dfe6c8275c724533f88525970a4065ae795f6e3 /include/linux/fs.h | |
parent | 6b1ef0e60d42f2fdaec26baee8327eb156347b4f (diff) |
flag parameters: NONBLOCK in pipe
This patch adds O_NONBLOCK support to pipe2. It is minimally more involved
than the patches for eventfd et.al but still trivial. The interfaces of the
create_write_pipe and create_read_pipe helper functions were changed and the
one other caller as well.
The following test must be adjusted for architectures other than x86 and
x86-64 and in case the syscall numbers changed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#ifndef __NR_pipe2
# ifdef __x86_64__
# define __NR_pipe2 293
# elif defined __i386__
# define __NR_pipe2 331
# else
# error "need __NR_pipe2"
# endif
#endif
int
main (void)
{
int fds[2];
if (syscall (__NR_pipe2, fds, 0) == -1)
{
puts ("pipe2(0) failed");
return 1;
}
for (int i = 0; i < 2; ++i)
{
int fl = fcntl (fds[i], F_GETFL);
if (fl == -1)
{
puts ("fcntl failed");
return 1;
}
if (fl & O_NONBLOCK)
{
printf ("pipe2(0) set non-blocking mode for fds[%d]\n", i);
return 1;
}
close (fds[i]);
}
if (syscall (__NR_pipe2, fds, O_NONBLOCK) == -1)
{
puts ("pipe2(O_NONBLOCK) failed");
return 1;
}
for (int i = 0; i < 2; ++i)
{
int fl = fcntl (fds[i], F_GETFL);
if (fl == -1)
{
puts ("fcntl failed");
return 1;
}
if ((fl & O_NONBLOCK) == 0)
{
printf ("pipe2(O_NONBLOCK) does not set non-blocking mode for fds[%d]\n", i);
return 1;
}
close (fds[i]);
}
puts ("OK");
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Ulrich Drepper <drepper@redhat.com>
Acked-by: Davide Libenzi <davidel@xmailserver.org>
Cc: Michael Kerrisk <mtk.manpages@googlemail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r-- | include/linux/fs.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index 0e80cd717d32..4b86f806014c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1778,8 +1778,8 @@ static inline void allow_write_access(struct file *file) | |||
1778 | } | 1778 | } |
1779 | extern int do_pipe(int *); | 1779 | extern int do_pipe(int *); |
1780 | extern int do_pipe_flags(int *, int); | 1780 | extern int do_pipe_flags(int *, int); |
1781 | extern struct file *create_read_pipe(struct file *f); | 1781 | extern struct file *create_read_pipe(struct file *f, int flags); |
1782 | extern struct file *create_write_pipe(void); | 1782 | extern struct file *create_write_pipe(int flags); |
1783 | extern void free_write_pipe(struct file *); | 1783 | extern void free_write_pipe(struct file *); |
1784 | 1784 | ||
1785 | extern struct file *do_filp_open(int dfd, const char *pathname, | 1785 | extern struct file *do_filp_open(int dfd, const char *pathname, |