[SCM] Socket Wrapper Repository - branch master updated
Andreas Schneider
asn at samba.org
Tue Jun 20 11:39:05 UTC 2023
The branch, master has been updated
via 71a55a6 swrap: Add support for openat64()
via 6bbf07e tests: Use F_(OFD)SETLK(64) in test_fcntl_lock
via cc80f53 cmake: Define large file support for tests
from cb5d579 gitlab-ci: Add a 32bit build
https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 71a55a64d6b6dcba9582cbded86d321ce0318fc0
Author: Andreas Schneider <asn at samba.org>
Date: Mon Jun 19 16:23:50 2023 +0200
swrap: Add support for openat64()
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 6bbf07e6c4475928de5a5005c1fb5804e3cebcde
Author: Andreas Schneider <asn at samba.org>
Date: Tue May 9 09:19:07 2023 +0200
tests: Use F_(OFD)SETLK(64) in test_fcntl_lock
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit cc80f531f439af77590b0f411ed3b38742d5ac08
Author: Andreas Schneider <asn at samba.org>
Date: Tue May 9 09:09:01 2023 +0200
cmake: Define large file support for tests
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
-----------------------------------------------------------------------
Summary of changes:
ConfigureChecks.cmake | 1 +
config.h.cmake | 1 +
src/CMakeLists.txt | 6 +++++
src/socket_wrapper.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/CMakeLists.txt | 7 ++++-
tests/test_fcntl_lock.c | 9 ++++++-
6 files changed, 90 insertions(+), 2 deletions(-)
Changeset truncated at 500 lines:
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index c99e2ae..daaee2b 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -70,6 +70,7 @@ check_function_exists(timerfd_create HAVE_TIMERFD_CREATE)
check_function_exists(bindresvport HAVE_BINDRESVPORT)
check_function_exists(accept4 HAVE_ACCEPT4)
check_function_exists(open64 HAVE_OPEN64)
+check_function_exists(openat64 HAVE_OPENAT64)
check_function_exists(fopen64 HAVE_FOPEN64)
check_function_exists(getprogname HAVE_GETPROGNAME)
check_function_exists(getexecname HAVE_GETEXECNAME)
diff --git a/config.h.cmake b/config.h.cmake
index a637a34..399013e 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -43,6 +43,7 @@
#cmakedefine HAVE_BINDRESVPORT 1
#cmakedefine HAVE_ACCEPT4 1
#cmakedefine HAVE_OPEN64 1
+#cmakedefine HAVE_OPENAT64 1
#cmakedefine HAVE_FOPEN64 1
#cmakedefine HAVE_GETPROGNAME 1
#cmakedefine HAVE_GETEXECNAME 1
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a1dbfaf..19e0d26 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,6 +8,12 @@ target_compile_options(socket_wrapper
PRIVATE
${DEFAULT_C_COMPILE_FLAGS}
-D_GNU_SOURCE)
+if (CMAKE_SIZEOF_VOID_P EQUAL 4)
+ target_compile_options(socket_wrapper
+ PRIVATE
+ -D_LARGEFILE64_SOURCE)
+endif()
+
target_link_libraries(socket_wrapper
PRIVATE ${SWRAP_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index de2f732..dc07b53 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -531,6 +531,9 @@ typedef int (*__libc_open)(const char *pathname, int flags, ...);
#ifdef HAVE_OPEN64
typedef int (*__libc_open64)(const char *pathname, int flags, ...);
#endif /* HAVE_OPEN64 */
+#ifdef HAVE_OPENAT64
+typedef int (*__libc_openat64)(int dirfd, const char *pathname, int flags, ...);
+#endif /* HAVE_OPENAT64 */
typedef int (*__libc_openat)(int dirfd, const char *path, int flags, ...);
typedef int (*__libc_pipe)(int pipefd[2]);
typedef int (*__libc_read)(int fd, void *buf, size_t count);
@@ -631,6 +634,9 @@ struct swrap_libc_symbols {
SWRAP_SYMBOL_ENTRY(open);
#ifdef HAVE_OPEN64
SWRAP_SYMBOL_ENTRY(open64);
+#endif
+#ifdef HAVE_OPENAT64
+ SWRAP_SYMBOL_ENTRY(openat64);
#endif
SWRAP_SYMBOL_ENTRY(openat);
SWRAP_SYMBOL_ENTRY(pipe);
@@ -1136,6 +1142,29 @@ static int libc_vopen64(const char *pathname, int flags, va_list ap)
}
#endif /* HAVE_OPEN64 */
+#ifdef HAVE_OPENAT64
+static int
+libc_vopenat64(int dirfd, const char *pathname, int flags, va_list ap)
+{
+ int mode = 0;
+ int fd;
+
+ swrap_bind_symbol_all();
+
+ swrap_inject_o_largefile(&flags);
+
+ if (flags & O_CREAT) {
+ mode = va_arg(ap, int);
+ }
+ fd = swrap.libc.symbols._libc_openat64.f(dirfd,
+ pathname,
+ flags,
+ (mode_t)mode);
+
+ return fd;
+}
+#endif /* HAVE_OPENAT64 */
+
static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap)
{
int mode = 0;
@@ -1441,6 +1470,9 @@ static void __swrap_bind_symbol_all_once(void)
swrap_bind_symbol_libc(open);
#ifdef HAVE_OPEN64
swrap_bind_symbol_libc(open64);
+#endif
+#ifdef HAVE_OPENAT64
+ swrap_bind_symbol_libc(openat64);
#endif
swrap_bind_symbol_libc(openat);
swrap_bind_symbol_libsocket(pipe);
@@ -4691,6 +4723,42 @@ int open64(const char *pathname, int flags, ...)
}
#endif /* HAVE_OPEN64 */
+/****************************************************************************
+ * OPENAT64
+ ***************************************************************************/
+
+#ifdef HAVE_OPENAT64
+static int
+swrap_vopenat64(int dirfd, const char *pathname, int flags, va_list ap)
+{
+ int ret;
+
+ ret = libc_vopenat64(dirfd, pathname, flags, ap);
+ if (ret != -1) {
+ /*
+ * There are methods for closing descriptors (libc-internal code
+ * paths, direct syscalls) which close descriptors in ways that
+ * we can't intercept, so try to recover when we notice that
+ * that's happened
+ */
+ swrap_remove_stale(ret);
+ }
+ return ret;
+}
+
+int openat64(int dirfd, const char *pathname, int flags, ...)
+{
+ va_list ap;
+ int fd;
+
+ va_start(ap, flags);
+ fd = swrap_vopenat64(dirfd, pathname, flags, ap);
+ va_end(ap);
+
+ return fd;
+}
+#endif /* HAVE_OPENAT64 */
+
/****************************************************************************
* OPENAT
***************************************************************************/
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e35c258..17d8d3c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -127,10 +127,15 @@ function(ADD_CMOCKA_TEST_ENVIRONMENT _TEST_NAME)
ENVIRONMENT "${TORTURE_ENVIRONMENT}")
endfunction()
+if (CMAKE_SIZEOF_VOID_P EQUAL 4)
+ message(STATUS "Enabling large file support for tests")
+ set(LFS_CFLAGS "-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64")
+endif()
+
foreach(_SWRAP_TEST ${SWRAP_TESTS})
add_cmocka_test(${_SWRAP_TEST}
SOURCES ${_SWRAP_TEST}.c
- COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE
+ COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE ${LFS_CFLAGS}
LINK_LIBRARIES ${TORTURE_LIBRARY} socket_wrapper_noop
LINK_OPTIONS ${DEFAULT_LINK_FLAGS})
add_cmocka_test_environment(${_SWRAP_TEST})
diff --git a/tests/test_fcntl_lock.c b/tests/test_fcntl_lock.c
index 98cf7c0..6bf2cd1 100644
--- a/tests/test_fcntl_lock.c
+++ b/tests/test_fcntl_lock.c
@@ -52,6 +52,13 @@ static void test_fcntl_lock(void **state)
int fd, rc;
struct flock lock;
char *s = (char *)*state;
+ int cmd = F_SETLK;
+#ifdef F_SETLK64
+ cmd = F_SETLK64;
+#endif
+#ifdef F_OFD_SETLK
+ cmd = F_OFD_SETLK;
+#endif
rc = snprintf(file, sizeof(file), "%s/file", s);
assert_in_range(rc, 0, PATH_MAX);
@@ -65,7 +72,7 @@ static void test_fcntl_lock(void **state)
lock.l_len = 4;
lock.l_pid = 0;
- rc = fcntl(fd, F_SETLK, &lock);
+ rc = fcntl(fd, cmd, &lock);
assert_return_code(rc, errno);
rc = unlink(file);
--
Socket Wrapper Repository
More information about the samba-cvs
mailing list