summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Smith <carl.smith@alliedtelesis.co.nz>2019-11-13 14:37:39 +1300
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-11-28 09:56:15 +0000
commitbedc513fc2deddaf1e2724cccf4b11943437e6c9 (patch)
tree0be2c27d70e4280cd6ab6f4f731e4992f4170f84
parentc48306407b070760a95ad1dbb349845e07dd3231 (diff)
vcl: Handle newer Glibc (>2.28) where fcntl is actually fcntl64
Glibc 2.28 now provides fcntl64 which is used instead of fcntl by defining fcntl as fcntl64 in fcntl.h Type: fix Change-Id: I87fedfbf3e0d241aafdc920e90f824d71353e0e6 Signed-off-by: Carl Smith <carl.smith@alliedtelesis.co.nz> (cherry picked from commit e16707b5b2195fda47c1a3db7ba61f30055d2dbc)
-rw-r--r--src/cmake/syscall.cmake9
-rw-r--r--src/vcl/ldp.c9
-rw-r--r--src/vcl/ldp_socket_wrapper.c30
-rw-r--r--src/vcl/ldp_socket_wrapper.h3
4 files changed, 51 insertions, 0 deletions
diff --git a/src/cmake/syscall.cmake b/src/cmake/syscall.cmake
index 1e0a559b5df..aa3bac45372 100644
--- a/src/cmake/syscall.cmake
+++ b/src/cmake/syscall.cmake
@@ -34,3 +34,12 @@ if (HAVE_GETCPU)
add_definitions(-DHAVE_GETCPU)
endif()
+check_c_source_compiles("
+ #define _GNU_SOURCE
+ #include <fcntl.h>
+ int main() { return fcntl64 (0, 0); }
+" HAVE_FCNTL64)
+
+if (HAVE_FCNTL64)
+ add_definitions(-DHAVE_FCNTL64)
+endif()
diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c
index 7aa38305249..e53a61e8e8c 100644
--- a/src/vcl/ldp.c
+++ b/src/vcl/ldp.c
@@ -482,8 +482,13 @@ writev (int fd, const struct iovec * iov, int iovcnt)
return size;
}
+#ifdef HAVE_FCNTL64
+int
+fcntl64 (int fd, int cmd, ...)
+#else
int
fcntl (int fd, int cmd, ...)
+#endif
{
vls_handle_t vlsh;
int rv = 0;
@@ -531,7 +536,11 @@ fcntl (int fd, int cmd, ...)
}
else
{
+#ifdef HAVE_FCNTL64
+ rv = libc_vfcntl64 (fd, cmd, ap);
+#else
rv = libc_vfcntl (fd, cmd, ap);
+#endif
}
va_end (ap);
diff --git a/src/vcl/ldp_socket_wrapper.c b/src/vcl/ldp_socket_wrapper.c
index ddf947d3bcc..81637deedfb 100644
--- a/src/vcl/ldp_socket_wrapper.c
+++ b/src/vcl/ldp_socket_wrapper.c
@@ -173,6 +173,9 @@ typedef int (*__libc_dup2) (int oldfd, int newfd);
#endif
typedef int (*__libc_fcntl) (int fd, int cmd, ...);
+#ifdef HAVE_FCNTL64
+typedef int (*__libc_fcntl64) (int fd, int cmd, ...);
+#endif
typedef FILE *(*__libc_fopen) (const char *name, const char *mode);
#ifdef HAVE_FOPEN64
typedef FILE *(*__libc_fopen64) (const char *name, const char *mode);
@@ -292,6 +295,9 @@ struct swrap_libc_symbols
SWRAP_SYMBOL_ENTRY (dup2);
#endif
SWRAP_SYMBOL_ENTRY (fcntl);
+#ifdef HAVE_FCNTL64
+ SWRAP_SYMBOL_ENTRY (fcntl64);
+#endif
SWRAP_SYMBOL_ENTRY (fopen);
#ifdef HAVE_FOPEN64
SWRAP_SYMBOL_ENTRY (fopen64);
@@ -562,6 +568,30 @@ libc_vfcntl (int fd, int cmd, va_list ap)
return rc;
}
+#ifdef HAVE_FCNTL64
+DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE int
+libc_vfcntl64 (int fd, int cmd, va_list ap)
+{
+ long int args[4];
+ int rc;
+ int i;
+
+ swrap_bind_symbol_libc (fcntl64);
+
+ for (i = 0; i < 4; i++)
+ {
+ args[i] = va_arg (ap, long int);
+ }
+
+ rc = swrap.libc.symbols._libc_fcntl64.f (fd,
+ cmd,
+ args[0], args[1], args[2],
+ args[3]);
+
+ return rc;
+}
+#endif
+
DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE int
libc_vioctl (int fd, int cmd, va_list ap)
{
diff --git a/src/vcl/ldp_socket_wrapper.h b/src/vcl/ldp_socket_wrapper.h
index 4121724c10e..b949d97f2f6 100644
--- a/src/vcl/ldp_socket_wrapper.h
+++ b/src/vcl/ldp_socket_wrapper.h
@@ -131,6 +131,9 @@ DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE int
libc_vfcntl (int fd, int cmd, va_list ap);
DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE int
+libc_vfcntl64 (int fd, int cmd, va_list ap);
+
+DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE int
libc_vioctl (int fd, int cmd, va_list ap);
int libc_getpeername (int sockfd, struct sockaddr *addr, socklen_t * addrlen);