Ulrich Drepper 336dd1f70f flag parameters: dup2
This patch adds the new dup3 syscall.  It extends the old dup2 syscall by one
parameter which is meant to hold a flag value.  Support for the O_CLOEXEC flag
is added in this patch.

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 <time.h>
#include <unistd.h>
#include <sys/syscall.h>

#ifndef __NR_dup3
# ifdef __x86_64__
#  define __NR_dup3 292
# elif defined __i386__
#  define __NR_dup3 330
# else
#  error "need __NR_dup3"
# endif
#endif

int
main (void)
{
  int fd = syscall (__NR_dup3, 1, 4, 0);
  if (fd == -1)
    {
      puts ("dup3(0) failed");
      return 1;
    }
  int coe = fcntl (fd, F_GETFD);
  if (coe == -1)
    {
      puts ("fcntl failed");
      return 1;
    }
  if (coe & FD_CLOEXEC)
    {
      puts ("dup3(0) set close-on-exec flag");
      return 1;
    }
  close (fd);

  fd = syscall (__NR_dup3, 1, 4, O_CLOEXEC);
  if (fd == -1)
    {
      puts ("dup3(O_CLOEXEC) failed");
      return 1;
    }
  coe = fcntl (fd, F_GETFD);
  if (coe == -1)
    {
      puts ("fcntl failed");
      return 1;
    }
  if ((coe & FD_CLOEXEC) == 0)
    {
      puts ("dup3(O_CLOEXEC) set close-on-exec flag");
      return 1;
    }
  close (fd);

  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
..
2008-07-18 14:35:14 +02:00
2008-07-22 10:43:44 +02:00
2008-01-30 13:34:07 +01:00
2008-05-23 20:33:28 +02:00
2008-07-21 21:35:38 +02:00
2008-04-17 17:41:33 +02:00
2008-07-09 09:14:12 +02:00
2007-10-17 20:17:13 +02:00
2008-04-19 19:19:54 +02:00
2008-02-04 16:48:04 +01:00
2007-10-17 20:17:15 +02:00
2008-07-16 12:15:17 -07:00
2008-07-08 13:10:58 +02:00
2007-10-17 20:17:08 +02:00
2008-05-25 08:58:35 +02:00
2008-07-09 09:13:59 +02:00
2008-07-14 11:37:46 +02:00
2008-05-01 08:03:58 -07:00
2008-07-18 14:10:27 +02:00
2007-10-17 20:17:08 +02:00
2007-10-17 20:17:21 +02:00
2008-07-11 11:00:54 +02:00
2008-01-30 13:33:35 +01:00
2008-07-08 10:38:19 +02:00
2008-07-09 07:43:25 +02:00
2008-01-30 13:33:14 +01:00
2008-04-18 00:46:35 +02:00
2008-01-30 13:30:28 +01:00
2008-07-16 00:29:07 +02:00
2008-05-12 21:28:05 +02:00
2008-01-30 13:30:16 +01:00
2008-05-24 11:22:12 +02:00
2008-04-17 20:05:37 +02:00
2007-10-17 20:16:47 +02:00
2008-01-30 13:31:55 +01:00
2007-10-17 20:26:15 +02:00
2008-07-08 13:10:31 +02:00
2008-07-08 13:10:31 +02:00
2008-07-08 13:10:31 +02:00
2008-01-30 13:31:43 +01:00
2008-07-08 12:24:13 +02:00
2007-10-23 22:37:24 +02:00
2008-06-10 15:52:07 +02:00
2008-07-08 13:10:24 +02:00
2008-04-17 17:40:58 +02:00
2008-07-13 08:19:45 +02:00
2008-04-19 19:19:55 +02:00
2008-07-08 11:31:25 +02:00
2008-07-22 10:43:45 +02:00
2008-07-22 10:43:45 +02:00
2008-07-16 12:15:17 -07:00
2008-06-02 12:48:23 +02:00
2008-05-25 08:58:30 +02:00
2007-10-17 20:17:08 +02:00
2008-05-25 07:09:47 +02:00
2007-10-17 20:17:08 +02:00
2008-04-19 19:19:57 +02:00
2008-06-18 12:27:03 +02:00
2007-10-17 20:17:08 +02:00
2008-04-17 10:42:34 -04:00
2007-10-23 22:37:24 +02:00
2008-07-18 17:59:13 +02:00
2008-07-16 10:55:07 +02:00
2008-07-08 15:49:08 +02:00
2007-10-23 22:37:24 +02:00
2007-10-23 22:37:24 +02:00
2008-06-18 12:27:03 +02:00
2008-02-06 10:41:02 -08:00
2007-10-17 20:26:18 +02:00
2008-07-18 18:51:57 +02:00
2008-07-09 07:43:27 +02:00
2008-07-24 10:47:28 -07:00
2008-07-24 10:47:28 -07:00
2008-04-26 17:35:46 +02:00
2007-10-17 20:32:38 +02:00
2008-06-02 12:48:23 +02:00
2008-06-18 12:27:03 +02:00
2008-06-18 12:27:03 +02:00