kernel-ark/arch/sh/kernel
Ulrich Drepper ed8cae8ba0 flag parameters: pipe
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>
2008-07-24 10:47:28 -07:00
..
cpu sh: add resource of USB host for SH7723 2008-06-09 16:04:13 +09:00
timers sh: replace remaining __FUNCTION__ occurrences 2008-03-06 11:18:22 +09:00
vsyscall sh: Terminate .eh_frame in VDSO with a 4-byte 0. 2007-11-02 12:29:37 +09:00
asm-offsets.c sh: use kbuild.h instead of defining macros in asm-offsets.c 2008-04-29 08:06:30 -07:00
cf-enabler.c sh: Add support for Solution Engine SH7721 board 2008-04-18 09:50:02 -07:00
cpufreq.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6 2007-10-13 09:49:04 -07:00
crash_dump.c sh: kdump support. 2007-05-07 02:11:56 +00:00
debugtraps.S sh: Use a jump call table for debug trap handlers. 2007-02-13 10:54:43 +09:00
dump_task.c sh: Fix occasional FPU register corruption under preempt. 2008-03-26 19:02:47 +09:00
early_printk.c sh: reset hardware from early printk 2008-05-08 19:51:54 +09:00
entry-common.S sh: Fix up restorer in debug_trap exception return path. 2008-05-19 19:39:33 +09:00
head_32.S sh: disable initrd defaults in .empty_zero_page. 2008-05-16 14:55:07 +09:00
head_64.S sh: comment tidying for sh64->sh migration. 2008-01-28 13:18:58 +09:00
init_task.c [PATCH] take init_files to fs/file.c 2008-05-16 17:22:20 -04:00
io_generic.c sh: trapped io support V2 2008-02-14 14:22:09 +09:00
io_trapped.c sh: Fix up section mismatches. 2008-03-06 12:43:38 +09:00
io.c sh: trapped io support V2 2008-02-14 14:22:09 +09:00
irq.c proper __do_softirq() prototype 2008-04-29 08:06:02 -07:00
kgdb_jmp.S
kgdb_stub.c sh: use the common ascii hex helpers 2008-05-16 15:09:08 +09:00
machine_kexec.c Use extended crashkernel command line on sh 2007-10-19 11:53:51 -07:00
machvec.c sh: panic on machvec section misalignment. 2007-08-07 19:13:23 +09:00
Makefile sh: Have 32-bit use arch/sh/kernel/Makefile_32. 2008-01-28 13:18:41 +09:00
Makefile_32 Generic semaphore implementation 2008-04-17 10:42:34 -04:00
Makefile_64 Generic semaphore implementation 2008-04-17 10:42:34 -04:00
module.c sh: module.c use kernel unaligned helpers 2008-06-02 12:30:00 +09:00
pm.c sh: APM/PM support. 2006-09-27 16:20:22 +09:00
process_32.c sh: Fix occasional FPU register corruption under preempt. 2008-03-26 19:02:47 +09:00
process_64.c sh64: add missing #include <asm/fpu.h>'s 2008-04-16 02:00:09 +09:00
ptrace_32.c sh: fix ptrace copy_from/to_user() compilation error 2008-02-14 14:22:09 +09:00
ptrace_64.c sh64: add missing #include <asm/fpu.h>'s 2008-04-16 02:00:09 +09:00
relocate_kernel.S sh: Fixup various PAGE_SIZE == 4096 assumptions. 2006-12-06 10:45:39 +09:00
setup.c sh: display boot params by default on entry. 2008-05-16 14:55:06 +09:00
sh_bios.c sh: Many symbol exports for nommu allmodconfig. 2007-07-20 16:59:49 +09:00
sh_ksyms_32.c sh64: Some symbol exports to make the allmodconfig happier. 2008-05-08 19:51:41 +09:00
sh_ksyms_64.c sh64: Some symbol exports to make the allmodconfig happier. 2008-05-08 19:51:41 +09:00
signal_32.c sh: Fix occasional FPU register corruption under preempt. 2008-03-26 19:02:47 +09:00
signal_64.c sh64: add missing #include <asm/fpu.h>'s 2008-04-16 02:00:09 +09:00
smp.c on_each_cpu(): kill unused 'retry' parameter 2008-06-26 11:24:38 +02:00
stacktrace.c stacktrace: export save_stack_trace[_tsk] 2008-07-03 09:17:55 +02:00
sys_sh32.c flag parameters: pipe 2008-07-24 10:47:28 -07:00
sys_sh64.c unified (weak) sys_pipe implementation 2008-05-03 13:50:33 -07:00
sys_sh.c sh: sys_sh consolidation for arch_get_unmapped_area(). 2008-01-28 13:18:49 +09:00
syscalls_32.S sh: Wire up new timerfd syscalls. 2008-02-14 14:22:08 +09:00
syscalls_64.S sh: Wire up new timerfd syscalls. 2008-02-14 14:22:08 +09:00
time_32.c sh: fix xtime_lock deadlocking. 2008-02-14 14:22:08 +09:00
time_64.c sh64: Some symbol exports to make the allmodconfig happier. 2008-05-08 19:51:41 +09:00
topology.c sh: replace remaining __FUNCTION__ occurrences 2008-03-06 11:18:22 +09:00
traps_32.c sh: arch/sh/kernel/traps_32.c needs asm/fpu.h 2008-04-16 02:03:51 +09:00
traps_64.c sh64: add missing #include <asm/fpu.h>'s 2008-04-16 02:00:09 +09:00
traps.c sh: Make is_valid_bugaddr() more intelligent on nommu. 2008-05-19 19:32:07 +09:00
vmlinux_32.lds.S move BUG_TABLE into RODATA 2008-05-25 07:06:08 +02:00
vmlinux_64.lds.S move BUG_TABLE into RODATA 2008-05-25 07:06:08 +02:00
vmlinux.lds.S sh: Split out linker script to _32 and _64 variants. 2008-01-28 13:18:45 +09:00