diff options
| author | Volker Lendecke <vl@samba.org> | 2014-06-01 20:57:21 +0200 |
|---|---|---|
| committer | Jeremy Allison <jra@samba.org> | 2014-06-18 18:51:13 +0200 |
| commit | 516e2f5e68aa10306a346865922b35e9a1e299c2 (patch) | |
| tree | 65403816e2bc81383a13038f05b3b1f78a576930 | |
| parent | 73a1205fe8a8aae357a96fb5074ed4dd16082fff (diff) | |
| download | samba-516e2f5e68aa10306a346865922b35e9a1e299c2.tar.gz samba-516e2f5e68aa10306a346865922b35e9a1e299c2.tar.xz samba-516e2f5e68aa10306a346865922b35e9a1e299c2.zip | |
unix_msg: Lift sockaddr_un handling from unix_msg_send
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
| -rw-r--r-- | source3/lib/messages_dgm.c | 20 | ||||
| -rw-r--r-- | source3/lib/unix_msg/test_source.c | 6 | ||||
| -rw-r--r-- | source3/lib/unix_msg/tests.c | 14 | ||||
| -rw-r--r-- | source3/lib/unix_msg/unix_msg.c | 15 | ||||
| -rw-r--r-- | source3/lib/unix_msg/unix_msg.h | 2 |
5 files changed, 24 insertions, 33 deletions
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index f71ec85959..edef8892d3 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -300,21 +300,19 @@ static NTSTATUS messaging_dgm_send(struct server_id src, { struct messaging_dgm_context *ctx = talloc_get_type_abort( backend->private_data, struct messaging_dgm_context); - fstring pid_str; - char buf[PATH_MAX]; - char *dst_sock, *to_free; struct messaging_dgm_hdr hdr; struct iovec iov2[iovlen + 1]; - ssize_t pathlen; struct server_id_buf idbuf; + struct sockaddr_un dst; + ssize_t dst_pathlen; int ret; - fstr_sprintf(pid_str, "msg/%u", (unsigned)pid.pid); + dst = (struct sockaddr_un) { .sun_family = AF_UNIX }; - pathlen = full_path_tos(ctx->cache_dir, pid_str, buf, sizeof(buf), - &dst_sock, &to_free); - if (pathlen == -1) { - return NT_STATUS_NO_MEMORY; + dst_pathlen = snprintf(dst.sun_path, sizeof(dst.sun_path), + "%s/msg/%u", ctx->cache_dir, (unsigned)pid.pid); + if (dst_pathlen >= sizeof(dst.sun_path)) { + return NT_STATUS_NAME_TOO_LONG; } hdr.msg_version = MESSAGE_VERSION; @@ -331,11 +329,9 @@ static NTSTATUS messaging_dgm_send(struct server_id src, memcpy(iov2+1, iov, iovlen*sizeof(struct iovec)); become_root(); - ret = unix_msg_send(ctx->dgm_ctx, dst_sock, iov2, iovlen + 1); + ret = unix_msg_send(ctx->dgm_ctx, &dst, iov2, iovlen + 1); unbecome_root(); - TALLOC_FREE(to_free); - if (ret != 0) { return map_nt_error_from_unix(ret); } diff --git a/source3/lib/unix_msg/test_source.c b/source3/lib/unix_msg/test_source.c index 94984d8852..7f6a7a5e8c 100644 --- a/source3/lib/unix_msg/test_source.c +++ b/source3/lib/unix_msg/test_source.c @@ -13,6 +13,7 @@ int main(int argc, const char *argv[]) int ret; unsigned i; unsigned num_ctxs = 1; + struct sockaddr_un dst; if (argc < 2) { fprintf(stderr, "Usage: %s <sockname> [num_contexts]\n", argv[0]); @@ -57,11 +58,14 @@ int main(int argc, const char *argv[]) iov.iov_base = &i; iov.iov_len = sizeof(i); + dst = (struct sockaddr_un) { .sun_family = AF_UNIX }; + strlcpy(dst.sun_path, argv[1], sizeof(dst.sun_path)); + for (i=0; i<num_ctxs; i++) { unsigned j; for (j=0; j<100000; j++) { - ret = unix_msg_send(ctxs[i], argv[1], &iov, 1); + ret = unix_msg_send(ctxs[i], &dst, &iov, 1); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); diff --git a/source3/lib/unix_msg/tests.c b/source3/lib/unix_msg/tests.c index f5a2e8c020..37ff3040a4 100644 --- a/source3/lib/unix_msg/tests.c +++ b/source3/lib/unix_msg/tests.c @@ -102,7 +102,7 @@ int main(void) state.buf = NULL; state.buflen = 0; - ret = unix_msg_send(ctx1, addr2.sun_path, NULL, 0); + ret = unix_msg_send(ctx1, &addr2, NULL, 0); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); @@ -119,7 +119,7 @@ int main(void) state.buf = &msg; state.buflen = sizeof(msg); - ret = unix_msg_send(ctx1, addr2.sun_path, &iov, 1); + ret = unix_msg_send(ctx1, &addr2, &iov, 1); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); @@ -140,13 +140,13 @@ int main(void) state.buflen = sizeof(buf); for (i=0; i<3; i++) { - ret = unix_msg_send(ctx1, addr2.sun_path, &iov, 1); + ret = unix_msg_send(ctx1, &addr2, &iov, 1); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); return 1; } - ret = unix_msg_send(ctx2, addr2.sun_path, &iov, 1); + ret = unix_msg_send(ctx2, &addr2, &iov, 1); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); @@ -185,7 +185,7 @@ int main(void) j++; } - ret = unix_msg_send(ctx1, addr1.sun_path, iovs, j); + ret = unix_msg_send(ctx1, &addr1, iovs, j); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); @@ -198,13 +198,13 @@ int main(void) printf("Filling send queues before freeing\n"); for (i=0; i<5; i++) { - ret = unix_msg_send(ctx1, addr2.sun_path, &iov, 1); + ret = unix_msg_send(ctx1, &addr2, &iov, 1); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); return 1; } - ret = unix_msg_send(ctx1, addr1.sun_path, &iov, 1); + ret = unix_msg_send(ctx1, &addr1, &iov, 1); if (ret != 0) { fprintf(stderr, "unix_msg_send failed: %s\n", strerror(ret)); diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 4087683717..f3185a3b52 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -637,7 +637,7 @@ int unix_msg_init(const struct sockaddr_un *addr, return 0; } -int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, +int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, const struct iovec *iov, int iovlen) { ssize_t msglen; @@ -646,15 +646,6 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, struct iovec *iov_copy; struct unix_msg_hdr hdr; struct iovec src_iov; - struct sockaddr_un dst; - size_t dst_len; - - dst_len = strlen(dst_sock)+1; - if (dst_len >= sizeof(dst.sun_path)) { - return ENAMETOOLONG; - } - dst = (struct sockaddr_un) { .sun_family = AF_UNIX }; - memcpy(dst.sun_path, dst_sock, dst_len); if (iovlen < 0) { return EINVAL; @@ -676,7 +667,7 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, sizeof(struct iovec) * iovlen); } - return unix_dgram_send(ctx->dgram, &dst, tmp_iov, iovlen+1); + return unix_dgram_send(ctx->dgram, dst, tmp_iov, iovlen+1); } hdr.msglen = msglen; @@ -734,7 +725,7 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, } sent += (fragment_len - sizeof(ctx->cookie) - sizeof(hdr)); - ret = unix_dgram_send(ctx->dgram, &dst, iov_copy, iov_index); + ret = unix_dgram_send(ctx->dgram, dst, iov_copy, iov_index); if (ret != 0) { break; } diff --git a/source3/lib/unix_msg/unix_msg.h b/source3/lib/unix_msg/unix_msg.h index bf9efe7c9e..a712a8f1ee 100644 --- a/source3/lib/unix_msg/unix_msg.h +++ b/source3/lib/unix_msg/unix_msg.h @@ -95,7 +95,7 @@ int unix_msg_init(const struct sockaddr_un *addr, * @return 0 on success, errno on failure */ -int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, +int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, const struct iovec *iov, int iovlen); /** |
