1
linux/arch/sparc/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
..
apc.c sparc: arch/sparc/kernel/apc.c to unlocked_ioctl 2008-07-17 21:56:16 -07:00
asm-offsets.c sparc: Remove Sparc's asm-offsets for sclow.S 2008-07-19 00:44:32 -07:00
auxio.c [SPARC]: Spelling fixes. 2007-05-11 21:39:20 -07:00
cpu.c [SPARC]: Mark linux_sparc_{fpu,chips} static. 2008-02-28 21:46:59 -08:00
devices.c [SPARC]: Add missing of_node_put 2007-12-05 05:38:00 -08:00
ebus.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
entry.S sparc: export openprom.h to userspace 2008-07-17 21:42:23 -07:00
etrap.S sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
head.S sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
idprom.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
init_task.c [PATCH] take init_files to fs/file.c 2008-05-16 17:22:20 -04:00
ioport.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
irq.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
irq.h [SPARC32]: Take enable_irq/disable_irq out of line. 2007-07-21 19:19:38 -07:00
kgdb.c sparc: Add kgdb support. 2008-04-29 02:38:50 -07:00
led.c sparc: switch /proc/led to seq_file 2008-06-03 15:21:21 -07:00
Makefile sparc: Add kgdb support. 2008-04-29 02:38:50 -07:00
module.c [SPARC]: Handle UNWIND_INFO properly. 2006-05-12 12:45:50 -07:00
muldiv.c sparc: remove CVS keywords 2008-05-20 00:33:44 -07:00
of_device.c [SPARC]: Remove of_platform_device_create 2008-02-09 03:49:58 -08:00
pcic.c xtime_lock vs update_process_times 2008-02-13 13:29:25 -08:00
pmc.c
process.c sparc: Use new '%pS' infrastructure to print symbols. 2008-07-17 22:11:32 -07:00
prom.c [SPARC]: Centralize find_in_proplist() instead of duplicating N times. 2007-08-07 18:46:36 -07:00
ptrace.c sparc: Fix debugger syscall restart interactions. 2008-05-11 02:07:19 -07:00
rtrap.S sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
setup.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
signal.c sparc: Fix debugger syscall restart interactions. 2008-05-11 02:07:19 -07:00
smp.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
sparc_ksyms.c sparc: remove CVS keywords 2008-05-20 00:33:44 -07:00
sun4c_irq.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
sun4d_irq.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
sun4d_smp.c sparc32: Kill smp_message_pass() and related code. 2008-04-29 01:14:10 -07:00
sun4m_irq.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
sun4m_smp.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
sun4setup.c
sys_sparc.c flag parameters: pipe 2008-07-24 10:47:28 -07:00
systbls.S [SPARC]: Remove SunOS and Solaris binary support. 2008-04-21 15:10:15 -07:00
tadpole.c
tick14.c [SPARC32]: Take enable_irq/disable_irq out of line. 2007-07-21 19:19:38 -07:00
time.c sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
trampoline.S sparc: remove CVS keywords 2008-05-20 00:33:44 -07:00
traps.c sparc: Use new '%pS' infrastructure to print symbols. 2008-07-17 22:11:32 -07:00
una_asm.S [SPARC]: Fix link errors with gcc-4.3 2008-03-03 15:01:05 -08:00
unaligned.c sparc: remove CVS keywords 2008-05-20 00:33:44 -07:00
vmlinux.lds.S [SPARC]: Merge asm-sparc{,64}/cache.h 2008-02-09 04:17:37 -08:00
windows.c
wof.S sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00
wuf.S sparc/kernel/: possible cleanups 2008-07-17 21:37:46 -07:00