[SCM] Socket Wrapper Repository - branch master updated
Andreas Schneider
asn at samba.org
Thu Mar 2 09:36:54 UTC 2017
The branch, master has been updated
via 6e1a3b5 swrap: use proper blocks for early returns
via 1de39d8 swrap: Add support for openat()
from 68e1cbf Increase wait time during echo_server's pid-file check
https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 6e1a3b50fb344107f7cfbcef35a4cf10c1e12113
Author: Michael Adam <obnox at samba.org>
Date: Fri Sep 23 16:33:52 2016 +0200
swrap: use proper blocks for early returns
This is better to read and might reduce the
diff of later patches.
Signed-off-by: Michael Adam <obnox at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit 1de39d82428fc6559ea5ea2d35187808020be9bf
Author: Andreas Schneider <asn at samba.org>
Date: Thu Mar 2 09:56:29 2017 +0100
swrap: Add support for openat()
-----------------------------------------------------------------------
Summary of changes:
src/socket_wrapper.c | 132 ++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 115 insertions(+), 17 deletions(-)
Changeset truncated at 500 lines:
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 3d468c3..1d94a89 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -438,6 +438,7 @@ typedef int (*__libc_getsockopt)(int sockfd,
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_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);
typedef ssize_t (*__libc_readv)(int fd, const struct iovec *iov, int iovcnt);
@@ -501,6 +502,7 @@ struct swrap_libc_symbols {
SWRAP_SYMBOL_ENTRY(ioctl);
SWRAP_SYMBOL_ENTRY(listen);
SWRAP_SYMBOL_ENTRY(open);
+ SWRAP_SYMBOL_ENTRY(openat);
SWRAP_SYMBOL_ENTRY(pipe);
SWRAP_SYMBOL_ENTRY(read);
SWRAP_SYMBOL_ENTRY(readv);
@@ -876,6 +878,34 @@ static int libc_open(const char *pathname, int flags, ...)
return fd;
}
+static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap)
+{
+ long 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);
+
+ return fd;
+}
+
+#if 0
+static int libc_openat(int dirfd, const char *path, int flags, ...)
+{
+ va_list ap;
+ int fd;
+
+ va_start(ap, flags);
+ fd = libc_vopenat(dirfd, path, flags, ap);
+ va_end(ap);
+
+ return fd;
+}
+#endif
+
static int libc_pipe(int pipefd[2])
{
swrap_bind_symbol_libsocket(pipe);
@@ -2279,7 +2309,9 @@ static int swrap_pcap_get_fd(const char *fname)
{
static int fd = -1;
- if (fd != -1) return fd;
+ if (fd != -1) {
+ return fd;
+ }
fd = libc_open(fname, O_WRONLY|O_CREAT|O_EXCL|O_APPEND, 0644);
if (fd != -1) {
@@ -2332,7 +2364,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
switch (type) {
case SWRAP_CONNECT_SEND:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
src_addr = &si->myname.sa.s;
dest_addr = addr;
@@ -2346,7 +2380,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_CONNECT_RECV:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
dest_addr = &si->myname.sa.s;
src_addr = addr;
@@ -2360,7 +2396,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_CONNECT_UNREACH:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
dest_addr = &si->myname.sa.s;
src_addr = addr;
@@ -2374,7 +2412,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_CONNECT_ACK:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
src_addr = &si->myname.sa.s;
dest_addr = addr;
@@ -2386,7 +2426,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_ACCEPT_SEND:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
dest_addr = &si->myname.sa.s;
src_addr = addr;
@@ -2400,7 +2442,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_ACCEPT_RECV:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
src_addr = &si->myname.sa.s;
dest_addr = addr;
@@ -2414,7 +2458,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_ACCEPT_ACK:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
dest_addr = &si->myname.sa.s;
src_addr = addr;
@@ -2521,7 +2567,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_CLOSE_SEND:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
src_addr = &si->myname.sa.s;
dest_addr = &si->peername.sa.s;
@@ -2535,7 +2583,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_CLOSE_RECV:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
dest_addr = &si->myname.sa.s;
src_addr = &si->peername.sa.s;
@@ -2549,7 +2599,9 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si,
break;
case SWRAP_CLOSE_ACK:
- if (si->type != SOCK_STREAM) return NULL;
+ if (si->type != SOCK_STREAM) {
+ return NULL;
+ }
src_addr = &si->myname.sa.s;
dest_addr = &si->peername.sa.s;
@@ -3143,7 +3195,9 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
if (stat(un_addr.sa.un.sun_path, &st) == 0) continue;
ret = libc_bind(fd, &un_addr.sa.s, un_addr.sa_socklen);
- if (ret == -1) return ret;
+ if (ret == -1) {
+ return ret;
+ }
si->un_addr = un_addr.sa.un;
@@ -3188,7 +3242,9 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr,
if (si->bound == 0) {
ret = swrap_auto_bind(s, si, serv_addr->sa_family);
- if (ret == -1) return -1;
+ if (ret == -1) {
+ return -1;
+ }
}
if (si->family != serv_addr->sa_family) {
@@ -3198,7 +3254,9 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr,
ret = sockaddr_convert_to_un(si, serv_addr,
addrlen, &un_addr.sa.un, 0, &bcast);
- if (ret == -1) return -1;
+ if (ret == -1) {
+ return -1;
+ }
if (bcast) {
errno = ENETUNREACH;
@@ -3357,7 +3415,9 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen)
&un_addr.sa.un,
1,
&si->bcast);
- if (ret == -1) return -1;
+ if (ret == -1) {
+ return -1;
+ }
unlink(un_addr.sa.un.sun_path);
@@ -3549,6 +3609,40 @@ int open(const char *pathname, int flags, ...)
}
/****************************************************************************
+ * OPENAT
+ ***************************************************************************/
+
+static int swrap_vopenat(int dirfd, const char *path, int flags, va_list ap)
+{
+ int ret;
+
+ ret = libc_vopenat(dirfd, path, 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 openat(int dirfd, const char *path, int flags, ...)
+{
+ va_list ap;
+ int fd;
+
+ va_start(ap, flags);
+ fd = swrap_vopenat(dirfd, path, flags, ap);
+ va_end(ap);
+
+ return fd;
+}
+
+/****************************************************************************
* GETPEERNAME
***************************************************************************/
@@ -4217,7 +4311,9 @@ static ssize_t swrap_sendmsg_before(int fd,
ret = sockaddr_convert_to_un(si, msg_name, msg->msg_namelen,
tmp_un, 0, bcast);
- if (ret == -1) return -1;
+ if (ret == -1) {
+ return -1;
+ }
if (to_un) {
*to_un = tmp_un;
@@ -4252,7 +4348,9 @@ static ssize_t swrap_sendmsg_before(int fd,
tmp_un,
0,
NULL);
- if (ret == -1) return -1;
+ if (ret == -1) {
+ return -1;
+ }
ret = libc_connect(fd,
(struct sockaddr *)(void *)tmp_un,
--
Socket Wrapper Repository
More information about the samba-cvs
mailing list