mirror of
https://github.com/torvalds/linux.git
synced 2026-06-04 12:35:52 +02:00
This patch introduces the new syscall pipe2 which is like pipe but it also
takes an additional parameter which takes a flag value. This patch implements
the handling of O_CLOEXEC for the flag. I did not add support for the new
syscall for the architectures which have a special sys_pipe implementation. I
think the maintainers of those archs have the chance to go with the unified
implementation but that's up to them.
The implementation introduces do_pipe_flags. I did that instead of changing
all callers of do_pipe because some of the callers are written in assembler.
I would probably screw up changing the assembly code. To avoid breaking code
do_pipe is now a small wrapper around do_pipe_flags. Once all callers are
changed over to do_pipe_flags the old do_pipe function can be removed.
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 fd[2];
if (syscall (__NR_pipe2, fd, 0) != 0)
{
puts ("pipe2(0) failed");
return 1;
}
for (int i = 0; i < 2; ++i)
{
int coe = fcntl (fd[i], F_GETFD);
if (coe == -1)
{
puts ("fcntl failed");
return 1;
}
if (coe & FD_CLOEXEC)
{
printf ("pipe2(0) set close-on-exit for fd[%d]\n", i);
return 1;
}
}
close (fd[0]);
close (fd[1]);
if (syscall (__NR_pipe2, fd, O_CLOEXEC) != 0)
{
puts ("pipe2(O_CLOEXEC) failed");
return 1;
}
for (int i = 0; i < 2; ++i)
{
int coe = fcntl (fd[i], F_GETFD);
if (coe == -1)
{
puts ("fcntl failed");
return 1;
}
if ((coe & FD_CLOEXEC) == 0)
{
printf ("pipe2(O_CLOEXEC) does not set close-on-exit for fd[%d]\n", i);
return 1;
}
}
close (fd[0]);
close (fd[1]);
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>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
|
||
|---|---|---|
| .. | ||
| 8250-platform.c | ||
| asm-offsets.c | ||
| binfmt_elfn32.c | ||
| binfmt_elfo32.c | ||
| branch.c | ||
| cevt-bcm1480.c | ||
| cevt-ds1287.c | ||
| cevt-gt641xx.c | ||
| cevt-r4k.c | ||
| cevt-sb1250.c | ||
| cevt-txx9.c | ||
| cpu-bugs64.c | ||
| cpu-probe.c | ||
| csrc-bcm1480.c | ||
| csrc-ioasic.c | ||
| csrc-r4k.c | ||
| csrc-sb1250.c | ||
| early_printk.c | ||
| entry.S | ||
| gdb-low.S | ||
| gdb-stub.c | ||
| genex.S | ||
| gpio_txx9.c | ||
| head.S | ||
| i8253.c | ||
| i8259.c | ||
| init_task.c | ||
| irq_cpu.c | ||
| irq_txx9.c | ||
| irq-gic.c | ||
| irq-gt641xx.c | ||
| irq-msc01.c | ||
| irq-rm7000.c | ||
| irq-rm9000.c | ||
| irq.c | ||
| kspd.c | ||
| linux32.c | ||
| machine_kexec.c | ||
| Makefile | ||
| mips_ksyms.c | ||
| mips-mt-fpaff.c | ||
| mips-mt.c | ||
| module.c | ||
| proc.c | ||
| process.c | ||
| ptrace.c | ||
| ptrace32.c | ||
| r4k_fpu.S | ||
| r4k_switch.S | ||
| r2300_fpu.S | ||
| r2300_switch.S | ||
| r6000_fpu.S | ||
| relocate_kernel.S | ||
| reset.c | ||
| rtlx.c | ||
| scall32-o32.S | ||
| scall64-64.S | ||
| scall64-n32.S | ||
| scall64-o32.S | ||
| setup.c | ||
| signal_n32.c | ||
| signal-common.h | ||
| signal.c | ||
| signal32.c | ||
| smp-cmp.c | ||
| smp-mt.c | ||
| smp-up.c | ||
| smp.c | ||
| smtc-asm.S | ||
| smtc-proc.c | ||
| smtc.c | ||
| spram.c | ||
| stacktrace.c | ||
| sync-r4k.c | ||
| syscall.c | ||
| time.c | ||
| topology.c | ||
| traps.c | ||
| unaligned.c | ||
| vmlinux.lds.S | ||
| vpe.c | ||