const struct sockaddr *addr,
socklen_t addrlen);
typedef int (*__libc_close)(int fd);
+#ifdef HAVE___CLOSE_NOCANCEL
+typedef int (*__libc___close_nocancel)(int fd);
+#endif
typedef int (*__libc_connect)(int sockfd,
const struct sockaddr *addr,
socklen_t addrlen);
#endif
SWRAP_SYMBOL_ENTRY(bind);
SWRAP_SYMBOL_ENTRY(close);
+#ifdef HAVE___CLOSE_NOCANCEL
+ SWRAP_SYMBOL_ENTRY(__close_nocancel);
+#endif
SWRAP_SYMBOL_ENTRY(connect);
SWRAP_SYMBOL_ENTRY(dup);
SWRAP_SYMBOL_ENTRY(dup2);
return swrap.libc.symbols._libc_close.f(fd);
}
+#ifdef HAVE___CLOSE_NOCANCEL
+static int libc___close_nocancel(int fd)
+{
+ swrap_bind_symbol_all();
+
+ return swrap.libc.symbols._libc___close_nocancel.f(fd);
+}
+#endif /* HAVE___CLOSE_NOCANCEL */
+
static int libc_connect(int sockfd,
const struct sockaddr *addr,
socklen_t addrlen)
#endif
swrap_bind_symbol_libsocket(bind);
swrap_bind_symbol_libc(close);
+#ifdef HAVE___CLOSE_NOCANCEL
+ swrap_bind_symbol_libc(__close_nocancel);
+#endif
swrap_bind_symbol_libsocket(connect);
swrap_bind_symbol_libc(dup);
swrap_bind_symbol_libc(dup2);
return swrap_close(fd);
}
+#ifdef HAVE___CLOSE_NOCANCEL
+
+static int swrap___close_nocancel(int fd)
+{
+ return swrap_remove_wrapper(__func__, libc___close_nocancel, fd);
+}
+
+int __close_nocancel(int fd);
+int __close_nocancel(int fd)
+{
+ return swrap___close_nocancel(fd);
+}
+
+#endif /* HAVE___CLOSE_NOCANCEL */
+
/****************************
* DUP
***************************/
#include <cmocka.h>
#include <unistd.h>
+#include <errno.h>
+
+#ifdef HAVE___CLOSE_NOCANCEL
+extern int __close_nocancel(int fd);
+#endif
static int setup(void **state)
{
static void test_dup2_existing_open_fd(void **state)
{
int s, dup_s;
+ int rc;
(void) state; /* unused */
dup_s = dup2(s, s);
assert_int_equal(dup_s, s);
- close(s);
+#ifdef HAVE___CLOSE_NOCANCEL
+ rc = __close_nocancel(s);
+ assert_return_code(rc, errno);
+ rc = close(s);
+ assert_int_equal(rc, -1);
+ assert_int_equal(errno, EBADF);
+ rc = __close_nocancel(s);
+ assert_int_equal(rc, -1);
+ assert_int_equal(errno, EBADF);
+#else
+ rc = close(s);
+ assert_return_code(rc, errno);
+#endif
}
int main(void) {