1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-01 10:06:57 +03:00

Assume that pipe2 is always available

The Debian patches for Hurd (which are already required to build
glibc before this commit) contain an implementation of pipe2.
This commit is contained in:
Florian Weimer
2017-04-18 14:09:01 +02:00
parent 025b33ae84
commit 46d8874d5b
6 changed files with 32 additions and 96 deletions

View File

@ -1,3 +1,13 @@
2017-04-18 Florian Weimer <fweimer@redhat.com>
* include/unistd.h (__have_pipe2): Remove declaration.
* socket/have_sock_cloexec.c (__have_pipe2): Remove definition.
* libio/iopopen.c (_IO_new_proc_open): Assume that pipe2 is
available.
* posix/wordexp.c (exec_comm_child, exec_comm): Likewise.
* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_PIPE2):
Remove definition.
2017-04-18 Florian Weimer <fweimer@redhat.com> 2017-04-18 Florian Weimer <fweimer@redhat.com>
* malloc/malloc.c (cfree): Turn into compat symbol. * malloc/malloc.c (cfree): Turn into compat symbol.

View File

@ -171,7 +171,6 @@ extern int __libc_pause (void);
/* Not cancelable variant. */ /* Not cancelable variant. */
extern int __pause_nocancel (void) attribute_hidden; extern int __pause_nocancel (void) attribute_hidden;
extern int __have_pipe2 attribute_hidden;
extern int __have_dup3 attribute_hidden; extern int __have_dup3 attribute_hidden;
extern int __getlogin_r_loginuid (char *name, size_t namesize) extern int __getlogin_r_loginuid (char *name, size_t namesize)

View File

@ -140,29 +140,17 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
if (_IO_file_is_open (fp)) if (_IO_file_is_open (fp))
return NULL; return NULL;
#ifdef O_CLOEXEC /* Atomically set the O_CLOEXEC flag for the pipe end used by the
# ifndef __ASSUME_PIPE2 child process (to avoid leaking the file descriptor in case of a
if (__have_pipe2 >= 0) concurrent fork). This is later reverted in the child process.
# endif When popen returns, the parent pipe end can be O_CLOEXEC or not,
{ depending on the 'e' open mode, but there is only one flag which
int r = __pipe2 (pipe_fds, O_CLOEXEC); controls both descriptors. The parent end is adjusted below,
# ifndef __ASSUME_PIPE2 after creating the child process. (In the child process, the
if (__have_pipe2 == 0) parent end should be closed on execve, so O_CLOEXEC remains set
__have_pipe2 = r != -1 || errno != ENOSYS ? 1 : -1; there.) */
if (__pipe2 (pipe_fds, O_CLOEXEC) < 0)
if (__have_pipe2 > 0) return NULL;
# 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) if (do_read)
{ {
@ -183,27 +171,13 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
int child_std_end = do_read ? 1 : 0; int child_std_end = do_read ? 1 : 0;
struct _IO_proc_file *p; 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) if (child_end != child_std_end)
{ _IO_dup2 (child_end, child_std_end);
_IO_dup2 (child_end, child_std_end);
#ifndef __ASSUME_PIPE2
_IO_close (child_end);
#endif
}
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
else else
{ /* The descriptor is already the one we will use. But it must
/* The descriptor is already the one we will use. But it must not be marked close-on-exec. Undo the effects. */
not be marked close-on-exec. Undo the effects. */ __fcntl (child_end, F_SETFD, 0);
# ifndef __ASSUME_PIPE2
if (__have_pipe2 > 0)
# endif
__fcntl (child_end, F_SETFD, 0);
}
#endif #endif
/* POSIX.2: "popen() shall ensure that any streams from previous /* POSIX.2: "popen() shall ensure that any streams from previous
popen() calls that remain open in the parent process are closed popen() calls that remain open in the parent process are closed
@ -229,26 +203,10 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
return NULL; return NULL;
} }
if (do_cloexec) if (!do_cloexec)
{ /* Undo the effects of the pipe2 call which set the
#ifndef __ASSUME_PIPE2 close-on-exec flag. */
# ifdef O_CLOEXEC __fcntl (parent_end, F_SETFD, 0);
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; _IO_fileno (fp) = parent_end;

View File

@ -836,10 +836,7 @@ exec_comm_child (char *comm, int *fildes, int showerr, int noexec)
{ {
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
/* Reset the close-on-exec flag (if necessary). */ /* Reset the close-on-exec flag (if necessary). */
# ifndef __ASSUME_PIPE2 __fcntl (fildes[1], F_SETFD, 0);
if (__have_pipe2 > 0)
# endif
__fcntl (fildes[1], F_SETFD, 0);
#endif #endif
} }
@ -905,31 +902,8 @@ exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
if (!comm || !*comm) if (!comm || !*comm)
return 0; return 0;
#ifdef O_CLOEXEC if (__pipe2 (fildes, O_CLOEXEC) < 0)
# ifndef __ASSUME_PIPE2 return WRDE_NOSPACE;
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: again:
if ((pid = __fork ()) < 0) if ((pid = __fork ()) < 0)

View File

@ -19,10 +19,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <kernel-features.h> #include <kernel-features.h>
#if defined O_CLOEXEC && !defined __ASSUME_PIPE2
int __have_pipe2;
#endif
#if defined O_CLOEXEC && !defined __ASSUME_DUP3 #if defined O_CLOEXEC && !defined __ASSUME_DUP3
int __have_dup3; int __have_dup3;
#endif #endif

View File

@ -74,7 +74,6 @@
/* Support for various CLOEXEC and NONBLOCK flags was added in /* Support for various CLOEXEC and NONBLOCK flags was added in
2.6.27. */ 2.6.27. */
#define __ASSUME_IN_NONBLOCK 1 #define __ASSUME_IN_NONBLOCK 1
#define __ASSUME_PIPE2 1
#define __ASSUME_DUP3 1 #define __ASSUME_DUP3 1
/* Support for accept4 functionality was added in 2.6.28, but for some /* Support for accept4 functionality was added in 2.6.28, but for some