[SCM] Socket Wrapper Repository - branch master updated
Andreas Schneider
asn at samba.org
Thu Sep 7 05:58:08 UTC 2017
The branch, master has been updated
via c777417 swrap: Fix prototype of open[64] to prevent segfault on ppc64le
via 753f387 swrap: Improve argument handling for libc_vopen*()
via 03c0602 swrap: Improve argument handling for libc_vioctl()
via 96c93cf swrap: Improve argument handling for libc_fcntl()
via a886815 tests: Add a simple fnctl() test
via b5a67f4 swrap: Simplify printing different log prefixes
via 49d7a4e swrap: Do an early return if log level doesn't match
via d1bc679 swrap: Always enable logging
from fa9cc40 swrap: Protect the FALL_THROUGH define
https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit c7774174beffe9a8d29dd4fb38bbed43ece1cecd
Author: Andreas Schneider <asn at samba.org>
Date: Wed Aug 2 13:21:59 2017 +0200
swrap: Fix prototype of open[64] to prevent segfault on ppc64le
The calling conventions for vaarg are different on ppc64le. The patch
fixes segfaults on that platform.
Thanks to Florian Weimer who helped debugging it!
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit 753f3872370a076628c272612da51963f4996ca4
Author: Andreas Schneider <asn at samba.org>
Date: Tue Aug 1 10:58:50 2017 +0200
swrap: Improve argument handling for libc_vopen*()
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit 03c06022e29e790938a1701a686ee2863677ff3c
Author: Andreas Schneider <asn at samba.org>
Date: Tue Aug 1 10:48:47 2017 +0200
swrap: Improve argument handling for libc_vioctl()
The ioctl() only takes one or no argument.
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit 96c93cf0ff3f06b99cdf84a3270e7686a4c7a0d3
Author: Andreas Schneider <asn at samba.org>
Date: Tue Aug 1 10:20:46 2017 +0200
swrap: Improve argument handling for libc_fcntl()
fcntl() has either one or no argument.
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit a886815fc1408382a7bf0ac056e7c7d99f494345
Author: Andreas Schneider <asn at samba.org>
Date: Mon Jul 31 19:25:41 2017 +0200
tests: Add a simple fnctl() test
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit b5a67f495620a38371cec166e05fa7010df8298a
Author: Andreas Schneider <asn at samba.org>
Date: Mon Jul 31 18:25:42 2017 +0200
swrap: Simplify printing different log prefixes
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit 49d7a4efd7a7de5a0962b358eb6e8c560a3f4711
Author: Andreas Schneider <asn at samba.org>
Date: Mon Jul 31 18:25:30 2017 +0200
swrap: Do an early return if log level doesn't match
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
commit d1bc679f21155a19d5b691f695cf29c2a94b87cc
Author: Andreas Schneider <asn at samba.org>
Date: Mon Jul 31 18:21:53 2017 +0200
swrap: Always enable logging
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
-----------------------------------------------------------------------
Summary of changes:
src/socket_wrapper.c | 110 +++++++++++++++++++++------------------------------
tests/CMakeLists.txt | 1 +
tests/test_fcntl.c | 67 +++++++++++++++++++++++++++++++
3 files changed, 114 insertions(+), 64 deletions(-)
create mode 100644 tests/test_fcntl.c
Changeset truncated at 500 lines:
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 280215e..ccbe67f 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -350,10 +350,6 @@ bool socket_wrapper_enabled(void);
void swrap_constructor(void) CONSTRUCTOR_ATTRIBUTE;
void swrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
-#ifdef NDEBUG
-# define SWRAP_LOG(...)
-#else
-
static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *func, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
# define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __func__, __VA_ARGS__)
@@ -365,42 +361,40 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl,
va_list va;
const char *d;
unsigned int lvl = 0;
+ const char *prefix = "SWRAP";
d = getenv("SOCKET_WRAPPER_DEBUGLEVEL");
if (d != NULL) {
lvl = atoi(d);
}
+ if (lvl < dbglvl) {
+ return;
+ }
+
va_start(va, format);
vsnprintf(buffer, sizeof(buffer), format, va);
va_end(va);
- if (lvl >= dbglvl) {
- switch (dbglvl) {
- case SWRAP_LOG_ERROR:
- fprintf(stderr,
- "SWRAP_ERROR(%d) - %s: %s\n",
- (int)getpid(), func, buffer);
- break;
- case SWRAP_LOG_WARN:
- fprintf(stderr,
- "SWRAP_WARN(%d) - %s: %s\n",
- (int)getpid(), func, buffer);
- break;
- case SWRAP_LOG_DEBUG:
- fprintf(stderr,
- "SWRAP_DEBUG(%d) - %s: %s\n",
- (int)getpid(), func, buffer);
- break;
- case SWRAP_LOG_TRACE:
- fprintf(stderr,
- "SWRAP_TRACE(%d) - %s: %s\n",
- (int)getpid(), func, buffer);
- break;
- }
+ switch (dbglvl) {
+ case SWRAP_LOG_ERROR:
+ prefix = "SWRAP_ERROR";
+ break;
+ case SWRAP_LOG_WARN:
+ prefix = "SWRAP_WARN";
+ break;
+ case SWRAP_LOG_DEBUG:
+ prefix = "SWRAP_DEBUG";
+ break;
+ case SWRAP_LOG_TRACE:
+ prefix = "SWRAP_TRACE";
+ break;
}
+
+ fprintf(stderr,
+ "%s(%d) - %s: %s\n",
+ prefix, (int)getpid(), func, buffer);
}
-#endif
/*********************************************************
* SWRAP LOADING LIBC FUNCTIONS
@@ -448,9 +442,9 @@ typedef int (*__libc_getsockopt)(int sockfd,
socklen_t *optlen);
typedef int (*__libc_ioctl)(int d, unsigned long int request, ...);
typedef int (*__libc_listen)(int sockfd, int backlog);
-typedef int (*__libc_open)(const char *pathname, int flags, mode_t mode);
+typedef int (*__libc_open)(const char *pathname, int flags, ...);
#ifdef HAVE_OPEN64
-typedef int (*__libc_open64)(const char *pathname, int flags, mode_t mode);
+typedef int (*__libc_open64)(const char *pathname, int flags, ...);
#endif /* HAVE_OPEN64 */
typedef int (*__libc_openat)(int dirfd, const char *path, int flags, ...);
typedef int (*__libc_pipe)(int pipefd[2]);
@@ -566,7 +560,6 @@ enum swrap_lib {
SWRAP_LIBSOCKET,
};
-#ifndef NDEBUG
static const char *swrap_str_lib(enum swrap_lib lib)
{
switch (lib) {
@@ -581,7 +574,6 @@ static const char *swrap_str_lib(enum swrap_lib lib)
/* Compiler would warn us about unhandled enum value if we get here */
return "unknown";
}
-#endif
static void *swrap_load_lib_handle(enum swrap_lib lib)
{
@@ -782,22 +774,14 @@ static int libc_eventfd(int count, int flags)
DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE
static int libc_vfcntl(int fd, int cmd, va_list ap)
{
- long int args[4];
+ void *arg;
int rc;
- int i;
swrap_bind_symbol_libc(fcntl);
- for (i = 0; i < 4; i++) {
- args[i] = va_arg(ap, long int);
- }
+ arg = va_arg(ap, void *);
- rc = swrap.libc.symbols._libc_fcntl.f(fd,
- cmd,
- args[0],
- args[1],
- args[2],
- args[3]);
+ rc = swrap.libc.symbols._libc_fcntl.f(fd, cmd, arg);
return rc;
}
@@ -838,22 +822,14 @@ static int libc_getsockopt(int sockfd,
DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE
static int libc_vioctl(int d, unsigned long int request, va_list ap)
{
- long int args[4];
+ void *arg;
int rc;
- int i;
swrap_bind_symbol_libc(ioctl);
- for (i = 0; i < 4; i++) {
- args[i] = va_arg(ap, long int);
- }
+ arg = va_arg(ap, void *);
- rc = swrap.libc.symbols._libc_ioctl.f(d,
- request,
- args[0],
- args[1],
- args[2],
- args[3]);
+ rc = swrap.libc.symbols._libc_ioctl.f(d, request, arg);
return rc;
}
@@ -883,13 +859,14 @@ static FILE *libc_fopen64(const char *name, const char *mode)
static int libc_vopen(const char *pathname, int flags, va_list ap)
{
- long int mode = 0;
+ int mode = 0;
int fd;
swrap_bind_symbol_libc(open);
- mode = va_arg(ap, long int);
-
+ if (flags & O_CREAT) {
+ mode = va_arg(ap, int);
+ }
fd = swrap.libc.symbols._libc_open.f(pathname, flags, (mode_t)mode);
return fd;
@@ -910,13 +887,14 @@ static int libc_open(const char *pathname, int flags, ...)
#ifdef HAVE_OPEN64
static int libc_vopen64(const char *pathname, int flags, va_list ap)
{
- long int mode = 0;
+ int mode = 0;
int fd;
swrap_bind_symbol_libc(open64);
- mode = va_arg(ap, long int);
-
+ if (flags & O_CREAT) {
+ mode = va_arg(ap, int);
+ }
fd = swrap.libc.symbols._libc_open64.f(pathname, flags, (mode_t)mode);
return fd;
@@ -925,14 +903,18 @@ static int libc_vopen64(const char *pathname, int flags, va_list ap)
static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap)
{
- long int mode = 0;
+ int mode = 0;
int fd;
swrap_bind_symbol_libc(openat);
- mode = va_arg(ap, long int);
-
- fd = swrap.libc.symbols._libc_openat.f(dirfd, path, flags, (mode_t)mode);
+ if (flags & O_CREAT) {
+ mode = va_arg(ap, int);
+ }
+ fd = swrap.libc.symbols._libc_openat.f(dirfd,
+ path,
+ flags,
+ (mode_t)mode);
return fd;
}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c2bd799..32a457e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -23,6 +23,7 @@ set(SWRAP_TESTS
test_ioctl
test_tcp_listen
test_tcp_dup2
+ test_fcntl
test_echo_tcp_socket
test_echo_tcp_connect
test_echo_tcp_bind
diff --git a/tests/test_fcntl.c b/tests/test_fcntl.c
new file mode 100644
index 0000000..7925185
--- /dev/null
+++ b/tests/test_fcntl.c
@@ -0,0 +1,67 @@
+#include "torture.h"
+
+#include <cmocka.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static int setup(void **state)
+{
+ torture_setup_socket_dir(state);
+
+ return 0;
+}
+
+static int teardown(void **state)
+{
+ torture_teardown_socket_dir(state);
+
+ return 0;
+}
+
+static void test_fcntl_dupfd_existing_open_fd(void **state)
+{
+ int s, dup_s;
+
+ (void) state; /* unused */
+
+ s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ assert_return_code(s, errno);
+
+ dup_s = fcntl(s, F_DUPFD, 100);
+ assert_int_equal(dup_s, 100);
+
+ close(s);
+ close(dup_s);
+}
+
+static void test_fcntl_getfd_existing_open_fd(void **state)
+{
+ int s, rc, flags;
+
+ (void) state; /* unused */
+
+ s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ assert_return_code(s, errno);
+
+ rc = fcntl(s, F_SETFD, FD_CLOEXEC);
+ assert_int_equal(rc, 0);
+
+ flags = fcntl(s, F_GETFD);
+ assert_int_equal(flags, FD_CLOEXEC);
+
+ close(s);
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest tcp_fcntl_dupfd_tests[] = {
+ cmocka_unit_test(test_fcntl_dupfd_existing_open_fd),
+ cmocka_unit_test(test_fcntl_getfd_existing_open_fd),
+ };
+
+ rc = cmocka_run_group_tests(tcp_fcntl_dupfd_tests, setup, teardown);
+
+ return rc;
+}
--
Socket Wrapper Repository
More information about the samba-cvs
mailing list