[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commits] r6638 - in /fsf/trunk/libc: ./ include/ io/ libio/ posix/ sysdeps/unix/sysv/linux/ sysdeps/unix/sysv/linux/bits/ sysdeps/uni...
- To: commits@xxxxxxxxxx
- Subject: [commits] r6638 - in /fsf/trunk/libc: ./ include/ io/ libio/ posix/ sysdeps/unix/sysv/linux/ sysdeps/unix/sysv/linux/bits/ sysdeps/uni...
- From: eglibc@xxxxxxxxxx
- Date: Mon, 28 Jul 2008 07:06:28 -0000
Author: eglibc
Date: Mon Jul 28 00:06:25 2008
New Revision: 6638
Log:
Import glibc-mainline for 2008-07-28
Added:
fsf/trunk/libc/libio/tst-popen1.c
Modified:
fsf/trunk/libc/ChangeLog
fsf/trunk/libc/NEWS
fsf/trunk/libc/include/unistd.h
fsf/trunk/libc/io/pipe2.c
fsf/trunk/libc/libio/Makefile
fsf/trunk/libc/libio/iopopen.c
fsf/trunk/libc/posix/wordexp.c
fsf/trunk/libc/sysdeps/unix/sysv/linux/bits/socket.h
fsf/trunk/libc/sysdeps/unix/sysv/linux/kernel-features.h
fsf/trunk/libc/sysdeps/unix/sysv/linux/sparc/bits/socket.h
fsf/trunk/libc/sysdeps/unix/sysv/linux/syscalls.list
Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Mon Jul 28 00:06:25 2008
@@ -1,3 +1,24 @@
+2008-07-27 Ulrich Drepper <drepper@xxxxxxxxxx>
+
+ * libio/iopopen.c (_IO_new_proc_open): Remove unnecessary volatile.
+
+ * posix/wordexp.c (exec_comm): Use pipe2 if possible to create
+ file descriptors with close-on-exec set.
+ (exec_comm_child): Fix the case where the write end of the pipe is
+ STDOUT_FILENO already. In case it is, clear close-on-exec.
+
+ * sysdeps/unix/sysv/linux/syscalls.list: Add __pipe2 alias.
+ * io/pipe2.c: Likewise.
+ * sysdeps/unix/sysv/linux/kernel-features.h: Define __ASSUME_PIPE2
+ instead of __ASSUME_PACCEPT.
+ * include/unistd.h: Declare __have_pipe2.
+ * libio/iopopen.c: Implement "e" flag.
+ * libio/Makefile (tests): Add tst-popen1.
+ * libio/tst-popen1.c: New file.
+
+ * sysdeps/unix/sysv/linux/bits/socket.h: Define PF_ISDN and AF_ISDN.
+ * sysdeps/unix/sysv/linux/sparc/bits/socket.h: Likewise.
+
2008-07-26 Ulrich Drepper <drepper@xxxxxxxxxx>
[BZ #6771]
Modified: fsf/trunk/libc/NEWS
==============================================================================
--- fsf/trunk/libc/NEWS (original)
+++ fsf/trunk/libc/NEWS Mon Jul 28 00:06:25 2008
@@ -1,4 +1,4 @@
-GNU C Library NEWS -- history of user-visible changes. 2008-5-14
+GNU C Library NEWS -- history of user-visible changes. 2008-7-27
Copyright (C) 1992-2007, 2008 Free Software Foundation, Inc.
See the end for copying conditions.
@@ -22,10 +22,18 @@
* New implementation of memmem, strstr, and strcasestr which is O(n).
Implemented by Eric Blake.
+
+* New Linux interfaces: inotify_init1, paccept, dup3, epoll_create2, pipe2
+
+* Implement "e" option for popen to open file descriptor with the
+ close-on-exec flag set
+
+* Many functions, exported and internal, now atomically set the close-on-exec
+ flag when run on a sufficiently new kernel. Implemented by Ulrich Drepper.
Version 2.8
-* New locales: bo_CN, bo_IN.
+* New locales: bo_CN, bo_IN, shs_CA.
* New encoding: HP-ROMAN9, HP-GREEK8, HP-THAI8, HP-TURKISH8.
Modified: fsf/trunk/libc/include/unistd.h
==============================================================================
--- fsf/trunk/libc/include/unistd.h (original)
+++ fsf/trunk/libc/include/unistd.h Mon Jul 28 00:06:25 2008
@@ -48,6 +48,7 @@
libc_hidden_proto (__libc_write)
extern int __pipe (int __pipedes[2]);
libc_hidden_proto (__pipe)
+extern int __pipe2 (int __pipedes[2], int __flags);
extern unsigned int __sleep (unsigned int __seconds);
extern int __chown (__const char *__file,
__uid_t __owner, __gid_t __group);
@@ -165,4 +166,10 @@
/* Not cancelable variant. */
extern int __pause_nocancel (void) attribute_hidden;
+extern int __have_sock_cloexec;
+/* At lot of other functionality became available at the same time as
+ SOCK_CLOEXEC. Avoid defining separate variables for all of them
+ unless it is really necessary. */
+#define __have_pipe2 __have_sock_cloexec
+
#endif
Modified: fsf/trunk/libc/io/pipe2.c
==============================================================================
--- fsf/trunk/libc/io/pipe2.c (original)
+++ fsf/trunk/libc/io/pipe2.c Mon Jul 28 00:06:25 2008
@@ -25,7 +25,7 @@
PIPEDES[1] can be read from PIPEDES[0]. Apply FLAGS to the new
file descriptors. Returns 0 if successful, -1 if not. */
int
-pipe2 (pipedes, flags)
+__pipe2 (pipedes, flags)
int pipedes[2];
int flags;
{
@@ -38,6 +38,7 @@
__set_errno (ENOSYS);
return -1;
}
+weak_alias (__pipe2, pipe2)
stub_warning (pipe2)
#include <stub-tag.h>
Modified: fsf/trunk/libc/libio/Makefile
==============================================================================
--- fsf/trunk/libc/libio/Makefile (original)
+++ fsf/trunk/libc/libio/Makefile Mon Jul 28 00:06:25 2008
@@ -1,4 +1,4 @@
-# Copyright (C) 1995-2002,2003,2004,2006,2007 Free Software Foundation, Inc.
+# Copyright (C) 1995-2004,2006,2007,2008 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -58,7 +58,7 @@
tst-memstream1 tst-memstream2 \
tst-wmemstream1 tst-wmemstream2 \
bug-memstream1 bug-wmemstream1 \
- tst-setvbuf1
+ tst-setvbuf1 tst-popen1
test-srcs = test-freopen
all: # Make this the default target; it will be defined in Rules.
Modified: fsf/trunk/libc/libio/iopopen.c
==============================================================================
--- fsf/trunk/libc/libio/iopopen.c (original)
+++ fsf/trunk/libc/libio/iopopen.c Mon Jul 28 00:06:25 2008
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1997-2002, 2003, 2004, 2007
+/* Copyright (C) 1993, 1997-2002, 2003, 2004, 2007, 2008
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Per Bothner <bothner@xxxxxxxxxx>.
@@ -44,6 +44,7 @@
#endif
#include <sys/types.h>
#include <sys/wait.h>
+#include <kernel-features.h>
#ifndef _IO_fork
#ifdef _LIBC
@@ -55,15 +56,6 @@
#endif
#endif /* _IO_HAVE_SYS_WAIT */
-
-#ifndef _IO_pipe
-#ifdef _LIBC
-#define _IO_pipe __pipe
-#else
-#define _IO_pipe pipe
-#endif
-extern int _IO_pipe (int des[2]) __THROW;
-#endif
#ifndef _IO_dup2
#ifdef _LIBC
@@ -127,45 +119,103 @@
const char *mode;
{
#if _IO_HAVE_SYS_WAIT
- volatile int read_or_write;
- volatile int parent_end, child_end;
+ int read_or_write;
+ int parent_end, child_end;
int pipe_fds[2];
_IO_pid_t child_pid;
+
+ int do_read = 0;
+ int do_write = 0;
+ int do_cloexec = 0;
+ while (*mode != '\0')
+ switch (*mode++)
+ {
+ case 'r':
+ do_read = 1;
+ break;
+ case 'w':
+ do_write = 1;
+ break;
+ case 'e':
+ do_cloexec = 1;
+ break;
+ default:
+ errout:
+ __set_errno (EINVAL);
+ return NULL;
+ }
+
+ if ((do_read ^ do_write) == 0)
+ goto errout;
+
if (_IO_file_is_open (fp))
return NULL;
- if (_IO_pipe (pipe_fds) < 0)
- return NULL;
- if (mode[0] == 'r' && mode[1] == '\0')
+
+#ifdef O_CLOEXEC
+# ifndef __ASSUME_PIPE2
+ if (__have_pipe2 >= 0)
+# endif
+ {
+ int r = __pipe2 (pipe_fds, O_CLOEXEC);
+# ifndef __ASSUME_PIPE2
+ if (__have_pipe2 == 0)
+ __have_pipe2 = r != -1 || errno != ENOSYS ? 1 : -1;
+
+ if (__have_pipe2 > 0)
+# endif
+ if (r < 0)
+ return NULL;
+ }
+#endif
+#ifndef __ASSUME_PIPE2
+# ifdef O_CLOEXEC
+ if (__have_pipe2 < 0)
+# endif
+ if (__pipe (pipe_fds) < 0)
+ return NULL;
+#endif
+
+ if (do_read)
{
parent_end = pipe_fds[0];
child_end = pipe_fds[1];
read_or_write = _IO_NO_WRITES;
}
- else if (mode[0] == 'w' && mode[1] == '\0')
+ else
{
parent_end = pipe_fds[1];
child_end = pipe_fds[0];
read_or_write = _IO_NO_READS;
}
- else
- {
- _IO_close (pipe_fds[0]);
- _IO_close (pipe_fds[1]);
- __set_errno (EINVAL);
- return NULL;
- }
+
((_IO_proc_file *) fp)->pid = child_pid = _IO_fork ();
if (child_pid == 0)
{
- int child_std_end = mode[0] == 'r' ? 1 : 0;
+ int child_std_end = do_read ? 1 : 0;
struct _IO_proc_file *p;
+#ifndef __ASSUME_PIPE2
+ /* If we have pipe2 the descriptor is marked for close-on-exec. */
_IO_close (parent_end);
+#endif
if (child_end != child_std_end)
{
_IO_dup2 (child_end, child_std_end);
+#ifndef __ASSUME_PIPE2
_IO_close (child_end);
+#endif
}
+#ifdef O_CLOEXEC
+ else
+ {
+ /* The descriptor is already the one we will use. But it must
+ not be marked close-on-exec. Undo the effects. */
+# ifndef __ASSUME_PIPE2
+ if (__have_pipe2 > 0)
+# endif
+ __fcntl (child_end, F_SETFD, 0);
+ }
+#endif
/* POSIX.2: "popen() shall ensure that any streams from previous
popen() calls that remain open in the parent process are closed
in the new child process." */
@@ -189,6 +239,28 @@
_IO_close (parent_end);
return NULL;
}
+
+ if (do_cloexec)
+ {
+#ifndef __ASSUME_PIPE2
+# ifdef O_CLOEXEC
+ if (__have_pipe2 < 0)
+# endif
+ __fcntl (parent_end, F_SETFD, FD_CLOEXEC);
+#endif
+ }
+ else
+ {
+#ifdef O_CLOEXEC
+ /* Undo the effects of the pipe2 call which set the
+ close-on-exec flag. */
+# ifndef __ASSUME_PIPE2
+ if (__have_pipe2 > 0)
+# endif
+ __fcntl (parent_end, F_SETFD, 0);
+#endif
+ }
+
_IO_fileno (fp) = parent_end;
/* Link into proc_file_chain. */
Added: fsf/trunk/libc/libio/tst-popen1.c
==============================================================================
--- fsf/trunk/libc/libio/tst-popen1.c (added)
+++ fsf/trunk/libc/libio/tst-popen1.c Mon Jul 28 00:06:25 2008
@@ -1,0 +1,49 @@
+#include <fcntl.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+ int res = 0;
+
+ FILE *fp = popen ("echo hello", "r");
+ if (fp == NULL)
+ {
+ puts ("first popen failed");
+ res = 1;
+ }
+ else
+ {
+ int fd = fileno (fp);
+ if (fcntl (fd, F_GETFD) == FD_CLOEXEC)
+ {
+ puts ("first popen(\"r\") set FD_CLOEXEC");
+ res = 1;
+ }
+
+ fclose (fp);
+ }
+
+ fp = popen ("echo hello", "re");
+ if (fp == NULL)
+ {
+ puts ("second popen failed");
+ res = 1;
+ }
+ else
+ {
+ int fd = fileno (fp);
+ if (fcntl (fd, F_GETFD) != FD_CLOEXEC)
+ {
+ puts ("second popen(\"r\") did not set FD_CLOEXEC");
+ res = 1;
+ }
+
+ fclose (fp);
+ }
+
+ return res;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
Modified: fsf/trunk/libc/posix/wordexp.c
==============================================================================
--- fsf/trunk/libc/posix/wordexp.c (original)
+++ fsf/trunk/libc/posix/wordexp.c Mon Jul 28 00:06:25 2008
@@ -1,5 +1,5 @@
/* POSIX.2 wordexp implementation.
- Copyright (C) 1997-2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997-2003, 2005, 2006, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Tim Waugh <tim@xxxxxxxxxxxxxxxxxxxx>.
@@ -42,6 +42,7 @@
# include <wchar.h>
#endif
#include <wordexp.h>
+#include <kernel-features.h>
#include <bits/libc-lock.h>
#include <stdio-common/_itoa.h>
@@ -824,17 +825,30 @@
args[1] = "-nc";
/* Redirect output. */
- __dup2 (fildes[1], STDOUT_FILENO);
- __close (fildes[1]);
+ if (__builtin_expect (fildes[1] != STDOUT_FILENO, 1))
+ {
+ __dup2 (fildes[1], STDOUT_FILENO);
+ __close (fildes[1]);
+ }
+ else
+ {
+#ifdef O_CLOEXEC
+ /* Reset the close-on-exec flag (if necessary). */
+# ifndef __ASSUME_PIPE2
+ if (__have_pipe2 > 0)
+# endif
+ __fcntl (fildes[1], F_SETFD, 0);
+#endif
+ }
/* Redirect stderr to /dev/null if we have to. */
if (showerr == 0)
{
struct stat64 st;
int fd;
- __close (2);
+ __close (STDERR_FILENO);
fd = __open (_PATH_DEVNULL, O_WRONLY);
- if (fd >= 0 && fd != 2)
+ if (fd >= 0 && fd != STDERR_FILENO)
{
__dup2 (fd, STDERR_FILENO);
__close (fd);
@@ -885,18 +899,38 @@
if (!comm || !*comm)
return 0;
- if (__pipe (fildes))
- /* Bad */
- return WRDE_NOSPACE;
+#ifdef O_CLOEXEC
+# ifndef __ASSUME_PIPE2
+ if (__have_pipe2 >= 0)
+# endif
+ {
+ int r = __pipe2 (fildes, O_CLOEXEC);
+# ifndef __ASSUME_PIPE2
+ if (__have_pipe2 == 0)
+ __have_pipe2 = r != -1 || errno != ENOSYS ? 1 : -1;
+
+ if (__have_pipe2 > 0)
+# endif
+ if (r < 0)
+ /* Bad */
+ return WRDE_NOSPACE;
+ }
+#endif
+#ifndef __ASSUME_PIPE2
+# ifdef O_CLOEXEC
+ if (__have_pipe2 < 0)
+# endif
+ if (__pipe (fildes) < 0)
+ /* Bad */
+ return WRDE_NOSPACE;
+#endif
again:
if ((pid = __fork ()) < 0)
{
/* Bad */
- if (fildes[0] != -1)
- __close (fildes[0]);
- if (fildes[1] != -1)
- __close (fildes[1]);
+ __close (fildes[0]);
+ __close (fildes[1]);
return WRDE_NOSPACE;
}
Modified: fsf/trunk/libc/sysdeps/unix/sysv/linux/bits/socket.h
==============================================================================
--- fsf/trunk/libc/sysdeps/unix/sysv/linux/bits/socket.h (original)
+++ fsf/trunk/libc/sysdeps/unix/sysv/linux/bits/socket.h Mon Jul 28 00:06:25 2008
@@ -102,7 +102,8 @@
#define PF_BLUETOOTH 31 /* Bluetooth sockets. */
#define PF_IUCV 32 /* IUCV sockets. */
#define PF_RXRPC 33 /* RxRPC sockets. */
-#define PF_MAX 34 /* For now.. */
+#define PF_ISDN 34 /* mISDN sockets. */
+#define PF_MAX 35 /* For now.. */
/* Address families. */
#define AF_UNSPEC PF_UNSPEC
@@ -136,6 +137,7 @@
#define AF_BLUETOOTH PF_BLUETOOTH
#define AF_IUCV PF_IUCV
#define AF_RXRPC PF_RXRPC
+#define AF_ISDN PF_ISDN
#define AF_MAX PF_MAX
/* Socket level values. Others are defined in the appropriate headers.
Modified: fsf/trunk/libc/sysdeps/unix/sysv/linux/kernel-features.h
==============================================================================
--- fsf/trunk/libc/sysdeps/unix/sysv/linux/kernel-features.h (original)
+++ fsf/trunk/libc/sysdeps/unix/sysv/linux/kernel-features.h Mon Jul 28 00:06:25 2008
@@ -505,5 +505,5 @@
|| defined __ia64__ || defined __sparc__)
# define __ASSUME_SOCK_CLOEXEC 1
# define __ASSUME_IN_NONBLOCK 1
-# define __ASSUME_PACCEPT 1
-#endif
+# define __ASSUME_PIPE2 1
+#endif
Modified: fsf/trunk/libc/sysdeps/unix/sysv/linux/sparc/bits/socket.h
==============================================================================
--- fsf/trunk/libc/sysdeps/unix/sysv/linux/sparc/bits/socket.h (original)
+++ fsf/trunk/libc/sysdeps/unix/sysv/linux/sparc/bits/socket.h Mon Jul 28 00:06:25 2008
@@ -101,7 +101,8 @@
#define PF_BLUETOOTH 31 /* Bluetooth sockets. */
#define PF_IUCV 32 /* IUCV sockets. */
#define PF_RXRPC 33 /* RxRPC sockets. */
-#define PF_MAX 34 /* For now.. */
+#define PF_ISDN 34 /* mISDN sockets. */
+#define PF_MAX 35 /* For now.. */
/* Address families. */
#define AF_UNSPEC PF_UNSPEC
@@ -135,6 +136,7 @@
#define AF_BLUETOOTH PF_BLUETOOTH
#define AF_IUCV PF_IUCV
#define AF_RXRPC PF_RXRPC
+#define AF_ISDN PF_ISDN
#define AF_MAX PF_MAX
/* Socket level values. Others are defined in the appropriate headers.
Modified: fsf/trunk/libc/sysdeps/unix/sysv/linux/syscalls.list
==============================================================================
--- fsf/trunk/libc/sysdeps/unix/sysv/linux/syscalls.list (original)
+++ fsf/trunk/libc/sysdeps/unix/sysv/linux/syscalls.list Mon Jul 28 00:06:25 2008
@@ -47,7 +47,7 @@
pause - pause Ci: __libc_pause pause
personality EXTRA personality i:i __personality personality
pipe - pipe i:f __pipe pipe
-pipe2 - pipe2 i:fi pipe2
+pipe2 - pipe2 i:fi __pipe2 pipe2
pivot_root EXTRA pivot_root i:ss pivot_root
prctl EXTRA prctl i:iiiii __prctl prctl
putpmsg - putpmsg i:ippii putpmsg