diff options
author | Pawel Jakub Dawidek <pjd@FreeBSD.org> | 2011-01-31 18:35:17 +0000 |
---|---|---|
committer | Pawel Jakub Dawidek <pjd@FreeBSD.org> | 2011-01-31 18:35:17 +0000 |
commit | 8046c499abd461a51517067641dc7a13de88a1cb (patch) | |
tree | 6ba0be808ae947b55743d27f5ae29dc66e331979 /sbin/hastd/proto_socketpair.c | |
parent | 2ec483c58eec542564d31694ead21852c9d76d98 (diff) | |
download | src-8046c499abd461a51517067641dc7a13de88a1cb.tar.gz src-8046c499abd461a51517067641dc7a13de88a1cb.zip |
Implement two new functions for sending descriptor and receving descriptor
over UNIX domain sockets and socket pairs.
This is in preparation for capsicum.
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=218139
Diffstat (limited to 'sbin/hastd/proto_socketpair.c')
-rw-r--r-- | sbin/hastd/proto_socketpair.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sbin/hastd/proto_socketpair.c b/sbin/hastd/proto_socketpair.c index 34f28b7ebfcc..1bb02f6690f8 100644 --- a/sbin/hastd/proto_socketpair.c +++ b/sbin/hastd/proto_socketpair.c @@ -161,6 +161,34 @@ sp_recv(void *ctx, unsigned char *data, size_t size) } static int +sp_descriptor_send(void *ctx, int fd) +{ + struct sp_ctx *spctx = ctx; + + PJDLOG_ASSERT(spctx != NULL); + PJDLOG_ASSERT(spctx->sp_magic == SP_CTX_MAGIC); + PJDLOG_ASSERT(spctx->sp_side == SP_SIDE_CLIENT); + PJDLOG_ASSERT(spctx->sp_fd[0] >= 0); + PJDLOG_ASSERT(fd > 0); + + return (proto_common_descriptor_send(spctx->sp_fd[0], fd)); +} + +static int +sp_descriptor_recv(void *ctx, int *fdp) +{ + struct sp_ctx *spctx = ctx; + + PJDLOG_ASSERT(spctx != NULL); + PJDLOG_ASSERT(spctx->sp_magic == SP_CTX_MAGIC); + PJDLOG_ASSERT(spctx->sp_side == SP_SIDE_SERVER); + PJDLOG_ASSERT(spctx->sp_fd[1] >= 0); + PJDLOG_ASSERT(fdp != NULL); + + return (proto_common_descriptor_recv(spctx->sp_fd[1], fdp)); +} + +static int sp_descriptor(const void *ctx) { const struct sp_ctx *spctx = ctx; @@ -224,6 +252,8 @@ static struct hast_proto sp_proto = { .hp_client = sp_client, .hp_send = sp_send, .hp_recv = sp_recv, + .hp_descriptor_send = sp_descriptor_send, + .hp_descriptor_recv = sp_descriptor_recv, .hp_descriptor = sp_descriptor, .hp_close = sp_close }; |