mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
gnulib: Fix replacement functions for pipe2/accept4
gnulib itself has a replacement for <unistd.h> which redefines pipe2
as rpl_pipe2 (etc), which is why the apparently recursive call in the
implementation of pipe2 isn't actually recursive. Since I didn't copy
that file, none of that worked and instead on platforms which have
pipe2 it recursed.
Reported-by: Laszlo Ersek
Fixes: commit 908e41e556
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifndef HAVE_ACCEPT4
|
||||
|
||||
/* Specification. */
|
||||
#include <sys/socket.h>
|
||||
|
||||
@@ -44,26 +46,6 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
|
||||
{
|
||||
int fd;
|
||||
|
||||
#if HAVE_DECL_ACCEPT4
|
||||
# undef accept4
|
||||
/* Try the system call first, if it exists. (We may be running with a glibc
|
||||
that has the function but with an older kernel that lacks it.) */
|
||||
{
|
||||
/* Cache the information whether the system call really exists. */
|
||||
static int have_accept4_really; /* 0 = unknown, 1 = yes, -1 = no */
|
||||
if (have_accept4_really >= 0)
|
||||
{
|
||||
int result = accept4 (sockfd, addr, addrlen, flags);
|
||||
if (!(result < 0 && errno == ENOSYS))
|
||||
{
|
||||
have_accept4_really = 1;
|
||||
return result;
|
||||
}
|
||||
have_accept4_really = -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Check the supported flags. */
|
||||
if ((flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK | O_TEXT | O_BINARY)) != 0)
|
||||
{
|
||||
@@ -153,3 +135,5 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_ACCEPT4 */
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifndef HAVE_PIPE2
|
||||
|
||||
/* Specification. */
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -50,26 +52,6 @@ pipe2 (int fd[2], int flags)
|
||||
tmp[0] = fd[0];
|
||||
tmp[1] = fd[1];
|
||||
|
||||
#if HAVE_PIPE2
|
||||
# undef pipe2
|
||||
/* Try the system call first, if it exists. (We may be running with a glibc
|
||||
that has the function but with an older kernel that lacks it.) */
|
||||
{
|
||||
/* Cache the information whether the system call really exists. */
|
||||
static int have_pipe2_really; /* 0 = unknown, 1 = yes, -1 = no */
|
||||
if (have_pipe2_really >= 0)
|
||||
{
|
||||
int result = pipe2 (fd, flags);
|
||||
if (!(result < 0 && errno == ENOSYS))
|
||||
{
|
||||
have_pipe2_really = 1;
|
||||
return result;
|
||||
}
|
||||
have_pipe2_really = -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Check the supported flags. */
|
||||
if ((flags & ~(O_CLOEXEC | O_NONBLOCK | O_BINARY | O_TEXT)) != 0)
|
||||
{
|
||||
@@ -169,3 +151,5 @@ pipe2 (int fd[2], int flags)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !HAVE_PIPE2 */
|
||||
|
||||
Reference in New Issue
Block a user