diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-22 14:46:04 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-22 14:46:04 +0000 |
| commit | 3c1ff1523587881324fc540fece06412c29c66de (patch) | |
| tree | ecd5431551ebe81793a33297b86f26d90e12047a /src/libunixonacid/textclient_server_init_frompipe.c | |
| parent | f3c9c3c70187967a670f1c059f5461dce745d92e (diff) | |
| download | skalibs-3c1ff1523587881324fc540fece06412c29c66de.tar.gz | |
Add textclient, fix some textmessage issues
Diffstat (limited to 'src/libunixonacid/textclient_server_init_frompipe.c')
| -rw-r--r-- | src/libunixonacid/textclient_server_init_frompipe.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libunixonacid/textclient_server_init_frompipe.c b/src/libunixonacid/textclient_server_init_frompipe.c new file mode 100644 index 0000000..fb85b44 --- /dev/null +++ b/src/libunixonacid/textclient_server_init_frompipe.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <errno.h> +#include <skalibs/types.h> +#include <skalibs/error.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/djbunix.h> +#include <skalibs/textmessage.h> +#include <skalibs/textclient.h> + +int textclient_server_init_frompipe (textmessage_receiver_t *in, textmessage_sender_t *syncout, textmessage_sender_t *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) +{ + struct iovec v ; + unsigned int asyncfd ; + char *x = getenv(SKALIBS_CHILD_SPAWN_FDS_ENVVAR) ; + if (!x + || !uint0_scan(x, &asyncfd) + || asyncfd == textmessage_sender_fd(syncout) + || asyncfd == textmessage_receiver_fd(in)) return (errno = EPROTO, 0) ; + if (sanitize_read(textmessage_timed_receive(in, &v, deadline, stamp)) <= 0) return 0 ; + if (v.iov_len != beforelen || memcmp(v.iov_base, before, beforelen)) return (errno = EPROTO, 0) ; + if (fcntl(asyncfd, F_GETFD) < 0) return 0 ; + if (!textmessage_timed_send(syncout, after, afterlen, deadline, stamp)) return 0 ; + textmessage_sender_init(asyncout, asyncfd) ; + if (!textmessage_timed_send(asyncout, after, afterlen, deadline, stamp)) return 0 ; + return 1 ; +} |
