diff options
author | pjd <pjd@FreeBSD.org> | 2011-01-31 18:32:17 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-01-31 18:32:17 +0000 |
commit | d916d2edb510181e3ab25256b84c439c5e1b8498 (patch) | |
tree | f3795a28e12aabbbc327a4d51170b148a1f2dbb2 /sbin/hastd/proto_uds.c | |
parent | 34c6c0a73948c51ae253cd9f5821beeee63cb4ca (diff) | |
download | FreeBSD-src-d916d2edb510181e3ab25256b84c439c5e1b8498.zip FreeBSD-src-d916d2edb510181e3ab25256b84c439c5e1b8498.tar.gz |
- Use pjdlog for assertions and aborts as this will log assert/abort message
to syslog if we run in background.
- Asserts in proto.c that method we want to call is implemented and remove
dummy methods from protocols implementation that are only there to abort
the program with nice message.
MFC after: 1 week
Diffstat (limited to 'sbin/hastd/proto_uds.c')
-rw-r--r-- | sbin/hastd/proto_uds.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/sbin/hastd/proto_uds.c b/sbin/hastd/proto_uds.c index 9c900e7..a114c21 100644 --- a/sbin/hastd/proto_uds.c +++ b/sbin/hastd/proto_uds.c @@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$"); #include <sys/un.h> -#include <assert.h> #include <errno.h> #include <stdbool.h> #include <stdint.h> @@ -128,10 +127,10 @@ uds_connect(void *ctx) { struct uds_ctx *uctx = ctx; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); - assert(uctx->uc_side == UDS_SIDE_CLIENT); - assert(uctx->uc_fd >= 0); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(uctx->uc_side == UDS_SIDE_CLIENT); + PJDLOG_ASSERT(uctx->uc_fd >= 0); if (connect(uctx->uc_fd, (struct sockaddr *)&uctx->uc_sun, sizeof(uctx->uc_sun)) < 0) { @@ -177,10 +176,10 @@ uds_accept(void *ctx, void **newctxp) socklen_t fromlen; int ret; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); - assert(uctx->uc_side == UDS_SIDE_SERVER_LISTEN); - assert(uctx->uc_fd >= 0); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(uctx->uc_side == UDS_SIDE_SERVER_LISTEN); + PJDLOG_ASSERT(uctx->uc_fd >= 0); newuctx = malloc(sizeof(*newuctx)); if (newuctx == NULL) @@ -207,9 +206,9 @@ uds_send(void *ctx, const unsigned char *data, size_t size) { struct uds_ctx *uctx = ctx; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); - assert(uctx->uc_fd >= 0); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(uctx->uc_fd >= 0); return (proto_common_send(uctx->uc_fd, data, size)); } @@ -219,9 +218,9 @@ uds_recv(void *ctx, unsigned char *data, size_t size) { struct uds_ctx *uctx = ctx; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); - assert(uctx->uc_fd >= 0); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(uctx->uc_fd >= 0); return (proto_common_recv(uctx->uc_fd, data, size)); } @@ -231,20 +230,12 @@ uds_descriptor(const void *ctx) { const struct uds_ctx *uctx = ctx; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); return (uctx->uc_fd); } -static bool -uds_address_match(const void *ctx __unused, const char *addr __unused) -{ - - assert(!"proto_address_match() not supported on UNIX domain sockets"); - abort(); -} - static void uds_local_address(const void *ctx, char *addr, size_t size) { @@ -252,16 +243,16 @@ uds_local_address(const void *ctx, char *addr, size_t size) struct sockaddr_un sun; socklen_t sunlen; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); - assert(addr != NULL); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(addr != NULL); sunlen = sizeof(sun); if (getsockname(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) { PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } - assert(sun.sun_family == AF_UNIX); + PJDLOG_ASSERT(sun.sun_family == AF_UNIX); if (sun.sun_path[0] == '\0') { PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; @@ -276,16 +267,16 @@ uds_remote_address(const void *ctx, char *addr, size_t size) struct sockaddr_un sun; socklen_t sunlen; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); - assert(addr != NULL); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(addr != NULL); sunlen = sizeof(sun); if (getpeername(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) { PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } - assert(sun.sun_family == AF_UNIX); + PJDLOG_ASSERT(sun.sun_family == AF_UNIX); if (sun.sun_path[0] == '\0') { PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; @@ -298,8 +289,8 @@ uds_close(void *ctx) { struct uds_ctx *uctx = ctx; - assert(uctx != NULL); - assert(uctx->uc_magic == UDS_CTX_MAGIC); + PJDLOG_ASSERT(uctx != NULL); + PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); if (uctx->uc_fd >= 0) close(uctx->uc_fd); @@ -317,7 +308,6 @@ static struct hast_proto uds_proto = { .hp_send = uds_send, .hp_recv = uds_recv, .hp_descriptor = uds_descriptor, - .hp_address_match = uds_address_match, .hp_local_address = uds_local_address, .hp_remote_address = uds_remote_address, .hp_close = uds_close |