summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package/deps.mak8
-rw-r--r--src/include/skalibs/ancil.h9
-rw-r--r--src/include/skalibs/unixonacid.h1
-rw-r--r--src/libposixplz/setgroups.c4
-rw-r--r--src/libstddjb/cdb_read.c2
-rw-r--r--src/libstddjb/ipc_bind.c2
-rw-r--r--src/libstddjb/ipc_connect.c2
-rw-r--r--src/libstddjb/ipc_recv.c2
-rw-r--r--src/libstddjb/ipc_send.c2
-rw-r--r--src/libstddjb/netstring_get.c2
-rw-r--r--src/libstddjb/string_unquote_withdelim.c2
-rw-r--r--src/libunixonacid/ancil_recv_fd.c69
-rw-r--r--src/libunixonacid/ancil_send_fd.c45
-rw-r--r--src/libunixonacid/ipc_timed_send.c2
-rw-r--r--src/libunixonacid/ipc_timed_sendv.c2
-rw-r--r--src/libunixonacid/skaclient_default_cb.c2
-rw-r--r--src/libunixonacid/skaclient_server_ack.c2
-rw-r--r--src/libunixonacid/skaclient_start_cb.c2
-rw-r--r--src/libunixonacid/textclient_command.c2
-rw-r--r--src/libunixonacid/textclient_commandv.c2
-rw-r--r--src/libunixonacid/textclient_server_init_frompipe.c2
-rw-r--r--src/libunixonacid/textclient_server_init_fromsocket.c41
-rw-r--r--src/libunixonacid/textclient_start.c65
-rw-r--r--src/libunixonacid/textclient_startf.c2
-rw-r--r--src/libunixonacid/unixmessage_put.c2
-rw-r--r--src/libunixonacid/unixmessage_receive.c2
-rw-r--r--src/libunixonacid/unixmessage_sender_flush.c2
27 files changed, 162 insertions, 118 deletions
diff --git a/package/deps.mak b/package/deps.mak
index f64adc1..e537529 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -57,7 +57,7 @@ src/include/skalibs/unix-timed.h: src/include/skalibs/bufalloc.h src/include/ska
src/include/skalibs/unix-transactional.h: src/include/skalibs/stralloc.h src/include/skalibs/uint64.h
src/include/skalibs/unixconnection.h: src/include/skalibs/unixmessage.h
src/include/skalibs/unixmessage.h: src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h
-src/include/skalibs/unixonacid.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/include/skalibs/unix-transactional.h src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h
+src/include/skalibs/unixonacid.h: src/include/skalibs/ancil.h src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/include/skalibs/unix-transactional.h src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h
src/include/skalibs/webipc.h: src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/include/skalibs/tai.h
src/libdatastruct/avlnode-internal.h: src/include/skalibs/avlnode.h
src/libdatastruct/genqdyn-internal.h: src/include/skalibs/genqdyn.h
@@ -740,6 +740,8 @@ src/libstddjb/xpathexec_r.o src/libstddjb/xpathexec_r.lo: src/libstddjb/xpathexe
src/libstddjb/xpathexec_r_name.o src/libstddjb/xpathexec_r_name.lo: src/libstddjb/xpathexec_r_name.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h
src/libstddjb/xpathexec_run.o src/libstddjb/xpathexec_run.lo: src/libstddjb/xpathexec_run.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h
src/libunixonacid/access_at.o src/libunixonacid/access_at.lo: src/libunixonacid/access_at.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/unix-transactional.h
+src/libunixonacid/ancil_recv_fd.o src/libunixonacid/ancil_recv_fd.lo: src/libunixonacid/ancil_recv_fd.c src/include/skalibs/allreadwrite.h src/include/skalibs/ancil.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/sysdeps.h
+src/libunixonacid/ancil_send_fd.o src/libunixonacid/ancil_send_fd.lo: src/libunixonacid/ancil_send_fd.c src/include/skalibs/ancil.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h
src/libunixonacid/atomic_rm_rf.o src/libunixonacid/atomic_rm_rf.lo: src/libunixonacid/atomic_rm_rf.c src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h
src/libunixonacid/atomic_rm_rf_tmp.o src/libunixonacid/atomic_rm_rf_tmp.lo: src/libunixonacid/atomic_rm_rf_tmp.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h
src/libunixonacid/atomic_symlink.o src/libunixonacid/atomic_symlink.lo: src/libunixonacid/atomic_symlink.c src/include/skalibs/posixplz.h src/include/skalibs/unix-transactional.h
@@ -804,8 +806,8 @@ src/libunixonacid/textclient_commandv.o src/libunixonacid/textclient_commandv.lo
src/libunixonacid/textclient_end.o src/libunixonacid/textclient_end.lo: src/libunixonacid/textclient_end.c src/include/skalibs/djbunix.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h
src/libunixonacid/textclient_server_init.o src/libunixonacid/textclient_server_init.lo: src/libunixonacid/textclient_server_init.c src/include/skalibs/djbunix.h src/include/skalibs/textclient.h
src/libunixonacid/textclient_server_init_frompipe.o src/libunixonacid/textclient_server_init_frompipe.lo: src/libunixonacid/textclient_server_init_frompipe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/types.h
-src/libunixonacid/textclient_server_init_fromsocket.o src/libunixonacid/textclient_server_init_fromsocket.lo: src/libunixonacid/textclient_server_init_fromsocket.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/types.h src/include/skalibs/unix-timed.h
-src/libunixonacid/textclient_start.o src/libunixonacid/textclient_start.lo: src/libunixonacid/textclient_start.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/sysdeps.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/include/skalibs/webipc.h
+src/libunixonacid/textclient_server_init_fromsocket.o src/libunixonacid/textclient_server_init_fromsocket.lo: src/libunixonacid/textclient_server_init_fromsocket.c src/include/skalibs/ancil.h src/include/skalibs/djbunix.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h
+src/libunixonacid/textclient_start.o src/libunixonacid/textclient_start.lo: src/libunixonacid/textclient_start.c src/include/skalibs/allreadwrite.h src/include/skalibs/ancil.h src/include/skalibs/djbunix.h src/include/skalibs/error.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/include/skalibs/webipc.h
src/libunixonacid/textclient_startf.o src/libunixonacid/textclient_startf.lo: src/libunixonacid/textclient_startf.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h
src/libunixonacid/textclient_zero.o src/libunixonacid/textclient_zero.lo: src/libunixonacid/textclient_zero.c src/include/skalibs/textclient.h
src/libunixonacid/textmessage_handle.o src/libunixonacid/textmessage_handle.lo: src/libunixonacid/textmessage_handle.c src/include/skalibs/textmessage.h
diff --git a/src/include/skalibs/ancil.h b/src/include/skalibs/ancil.h
new file mode 100644
index 0000000..92270eb
--- /dev/null
+++ b/src/include/skalibs/ancil.h
@@ -0,0 +1,9 @@
+/* ISC license. */
+
+#ifndef SKALIBS_ANCIL_H
+#define SKALIBS_ANCIL_H
+
+extern int ancil_recv_fd (int, char) ;
+extern int ancil_send_fd (int, int, char) ;
+
+#endif
diff --git a/src/include/skalibs/unixonacid.h b/src/include/skalibs/unixonacid.h
index 7132f1c..76aca9d 100644
--- a/src/include/skalibs/unixonacid.h
+++ b/src/include/skalibs/unixonacid.h
@@ -5,6 +5,7 @@
#include <skalibs/unix-transactional.h>
#include <skalibs/unix-timed.h>
+#include <skalibs/ancil.h>
#include <skalibs/textmessage.h>
#include <skalibs/textclient.h>
#include <skalibs/unixmessage.h>
diff --git a/src/libposixplz/setgroups.c b/src/libposixplz/setgroups.c
index fff507f..0c32222 100644
--- a/src/libposixplz/setgroups.c
+++ b/src/libposixplz/setgroups.c
@@ -5,11 +5,13 @@
#ifdef SKALIBS_HASSETGROUPS
#include <skalibs/nonposix.h>
-#include <skalibs/posixishard.h>
+
#include <string.h>
#include <unistd.h>
#include <grp.h>
+
#include <skalibs/setgroups.h>
+#include <skalibs/posixishard.h>
int setgroups_and_gid (gid_t g, size_t n, gid_t const *tab)
{
diff --git a/src/libstddjb/cdb_read.c b/src/libstddjb/cdb_read.c
index 85e8dea..1d2f491 100644
--- a/src/libstddjb/cdb_read.c
+++ b/src/libstddjb/cdb_read.c
@@ -4,9 +4,9 @@
#include <string.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/cdb.h>
+#include <skalibs/posixishard.h>
int cdb_read (struct cdb *c, char *buf, unsigned int len, uint32_t pos)
{
diff --git a/src/libstddjb/ipc_bind.c b/src/libstddjb/ipc_bind.c
index b3388d7..d40a7ef 100644
--- a/src/libstddjb/ipc_bind.c
+++ b/src/libstddjb/ipc_bind.c
@@ -7,8 +7,8 @@
#include <string.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/webipc.h>
+#include <skalibs/posixishard.h>
int ipc_bind (int s, char const *p)
{
diff --git a/src/libstddjb/ipc_connect.c b/src/libstddjb/ipc_connect.c
index bb0422e..c00f683 100644
--- a/src/libstddjb/ipc_connect.c
+++ b/src/libstddjb/ipc_connect.c
@@ -7,8 +7,8 @@
#include <sys/un.h>
#include <string.h>
-#include <skalibs/posixishard.h>
#include <skalibs/webipc.h>
+#include <skalibs/posixishard.h>
int ipc_connect (int s, char const *p)
{
diff --git a/src/libstddjb/ipc_recv.c b/src/libstddjb/ipc_recv.c
index e15e3c5..4c235bb 100644
--- a/src/libstddjb/ipc_recv.c
+++ b/src/libstddjb/ipc_recv.c
@@ -7,8 +7,8 @@
#include <sys/un.h>
#include <string.h>
-#include <skalibs/posixishard.h>
#include <skalibs/webipc.h>
+#include <skalibs/posixishard.h>
ssize_t ipc_recv (int fd, char *s, size_t len, char *path)
{
diff --git a/src/libstddjb/ipc_send.c b/src/libstddjb/ipc_send.c
index 65826a6..2615a16 100644
--- a/src/libstddjb/ipc_send.c
+++ b/src/libstddjb/ipc_send.c
@@ -7,8 +7,8 @@
#include <sys/un.h>
#include <string.h>
-#include <skalibs/posixishard.h>
#include <skalibs/webipc.h>
+#include <skalibs/posixishard.h>
ssize_t ipc_send (int fd, char const *s, size_t len, char const *path)
{
diff --git a/src/libstddjb/netstring_get.c b/src/libstddjb/netstring_get.c
index 0dfa907..32a6c49 100644
--- a/src/libstddjb/netstring_get.c
+++ b/src/libstddjb/netstring_get.c
@@ -2,13 +2,13 @@
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/types.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/bytestr.h>
#include <skalibs/buffer.h>
#include <skalibs/stralloc.h>
#include <skalibs/netstring.h>
+#include <skalibs/posixishard.h>
int netstring_okeof (buffer *b, size_t w)
{
diff --git a/src/libstddjb/string_unquote_withdelim.c b/src/libstddjb/string_unquote_withdelim.c
index 702d3a5..43da0db 100644
--- a/src/libstddjb/string_unquote_withdelim.c
+++ b/src/libstddjb/string_unquote_withdelim.c
@@ -2,10 +2,10 @@
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/bytestr.h>
#include <skalibs/fmtscan.h>
#include <skalibs/skamisc.h>
+#include <skalibs/posixishard.h>
#define PUSH0 0x40
#define PUSH 0x20
diff --git a/src/libunixonacid/ancil_recv_fd.c b/src/libunixonacid/ancil_recv_fd.c
new file mode 100644
index 0000000..70f2c4f
--- /dev/null
+++ b/src/libunixonacid/ancil_recv_fd.c
@@ -0,0 +1,69 @@
+/* ISC license. */
+
+#include <skalibs/sysdeps.h>
+#include <skalibs/nonposix.h>
+
+#include <errno.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+
+#include <skalibs/allreadwrite.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/ancil.h>
+#include <skalibs/posixishard.h>
+
+union aligner_u
+{
+ struct cmsghdr cmsghdr ;
+ int i ;
+} ;
+
+int ancil_recv_fd (int sock, char expected_ch)
+{
+ static int const awesomeflags =
+#ifdef SKALIBS_HASMSGDONTWAIT
+ MSG_DONTWAIT
+#else
+ 0
+#endif
+ |
+#ifdef SKALIBS_HASCMSGCLOEXEC
+ MSG_CMSG_CLOEXEC
+#else
+ 0
+#endif
+ ;
+ struct cmsghdr *c ;
+ ssize_t r ;
+ char ch ;
+ struct iovec v = { .iov_base = &ch, .iov_len = 1 } ;
+ union aligner_u ancilbuf[1 + (CMSG_SPACE(sizeof(int)) - 1) / sizeof(union aligner_u)] ;
+ struct msghdr msghdr =
+ {
+ .msg_name = 0,
+ .msg_namelen = 0,
+ .msg_iov = &v,
+ .msg_iovlen = 1,
+ .msg_flags = 0,
+ .msg_control = ancilbuf,
+ .msg_controllen = CMSG_SPACE(sizeof(int))
+ } ;
+ do r = recvmsg(sock, &msghdr, awesomeflags) ;
+ while (r < 0 && errno == EINTR) ;
+ if (r < 0) return r ;
+ if (!r) return (errno = EPIPE, -1) ;
+ c = CMSG_FIRSTHDR(&msghdr) ;
+ if (ch != expected_ch
+ || !c
+ || c->cmsg_level != SOL_SOCKET
+ || c->cmsg_type != SCM_RIGHTS
+ || (size_t)(c->cmsg_len - (CMSG_DATA(c) - (unsigned char *)c)) != sizeof(int)) return (errno = EPROTO, -1) ;
+#ifndef SKALIBS_HASCMSGCLOEXEC
+ if (coe(*(int *)CMSG_DATA(c)) < 0)
+ {
+ fd_close(*(int *)CMSG_DATA(c)) ;
+ return -1 ;
+ }
+#endif
+ return *(int *)CMSG_DATA(c) ;
+}
diff --git a/src/libunixonacid/ancil_send_fd.c b/src/libunixonacid/ancil_send_fd.c
new file mode 100644
index 0000000..98366c7
--- /dev/null
+++ b/src/libunixonacid/ancil_send_fd.c
@@ -0,0 +1,45 @@
+/* ISC license. */
+
+#include <skalibs/nonposix.h>
+
+#include <errno.h>
+#include <string.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+
+#include <skalibs/djbunix.h>
+#include <skalibs/ancil.h>
+#include <skalibs/posixishard.h>
+
+union aligner_u
+{
+ struct cmsghdr cmsghdr ;
+ int i ;
+} ;
+
+int ancil_send_fd (int sock, int fd, char ch)
+{
+ ssize_t r ;
+ struct iovec v = { .iov_base = &ch, .iov_len = 1 } ;
+ union aligner_u ancilbuf[1 + (CMSG_SPACE(sizeof(int)) - 1) / sizeof(union aligner_u)] ;
+ struct msghdr hdr =
+ {
+ .msg_name = 0,
+ .msg_namelen = 0,
+ .msg_iov = &v,
+ .msg_iovlen = 1,
+ .msg_control = ancilbuf,
+ .msg_controllen = CMSG_SPACE(sizeof(int))
+ } ;
+ struct cmsghdr *c = CMSG_FIRSTHDR(&hdr) ;
+ memset(hdr.msg_control, 0, hdr.msg_controllen) ;
+ c->cmsg_level = SOL_SOCKET ;
+ c->cmsg_type = SCM_RIGHTS ;
+ c->cmsg_len = CMSG_LEN(sizeof(int)) ;
+ *(int *)CMSG_DATA(c) = fd ;
+ do r = sendmsg(sock, &hdr, MSG_NOSIGNAL) ;
+ while (r < 0 && errno == EINTR) ;
+ if (r <= 0) return 0 ;
+ fd_close(fd) ;
+ return 1 ;
+}
diff --git a/src/libunixonacid/ipc_timed_send.c b/src/libunixonacid/ipc_timed_send.c
index e1e75a4..2f6ce88 100644
--- a/src/libunixonacid/ipc_timed_send.c
+++ b/src/libunixonacid/ipc_timed_send.c
@@ -5,10 +5,10 @@
#include <sys/socket.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/error.h>
#include <skalibs/iopause.h>
#include <skalibs/unix-timed.h>
+#include <skalibs/posixishard.h>
int ipc_timed_send (int fd, char const *s, size_t len, tain_t const *deadline, tain_t *stamp)
{
diff --git a/src/libunixonacid/ipc_timed_sendv.c b/src/libunixonacid/ipc_timed_sendv.c
index 0fe5b1e..1bdae5b 100644
--- a/src/libunixonacid/ipc_timed_sendv.c
+++ b/src/libunixonacid/ipc_timed_sendv.c
@@ -5,11 +5,11 @@
#include <sys/socket.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/error.h>
#include <skalibs/iopause.h>
#include <skalibs/siovec.h>
#include <skalibs/unix-timed.h>
+#include <skalibs/posixishard.h>
int ipc_timed_sendv (int fd, struct iovec const *v, unsigned int n, tain_t const *deadline, tain_t *stamp)
{
diff --git a/src/libunixonacid/skaclient_default_cb.c b/src/libunixonacid/skaclient_default_cb.c
index 5bf0268..447d796 100644
--- a/src/libunixonacid/skaclient_default_cb.c
+++ b/src/libunixonacid/skaclient_default_cb.c
@@ -2,9 +2,9 @@
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/skaclient.h>
#include <skalibs/unixmessage.h>
+#include <skalibs/posixishard.h>
int skaclient_default_cb (unixmessage_t const *m, void *p)
{
diff --git a/src/libunixonacid/skaclient_server_ack.c b/src/libunixonacid/skaclient_server_ack.c
index b55eb07..9bad7cc 100644
--- a/src/libunixonacid/skaclient_server_ack.c
+++ b/src/libunixonacid/skaclient_server_ack.c
@@ -3,11 +3,11 @@
#include <errno.h>
#include <string.h>
-#include <skalibs/posixishard.h>
#include <skalibs/djbunix.h>
#include <skalibs/skaclient.h>
#include <skalibs/unixmessage.h>
#include <skalibs/webipc.h>
+#include <skalibs/posixishard.h>
int skaclient_server_ack (unixmessage_t const *clientmsg, unixmessage_sender_t *out, unixmessage_sender_t *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen)
{
diff --git a/src/libunixonacid/skaclient_start_cb.c b/src/libunixonacid/skaclient_start_cb.c
index 0c4ef49..f385b6b 100644
--- a/src/libunixonacid/skaclient_start_cb.c
+++ b/src/libunixonacid/skaclient_start_cb.c
@@ -3,9 +3,9 @@
#include <errno.h>
#include <string.h>
-#include <skalibs/posixishard.h>
#include <skalibs/unixmessage.h>
#include <skalibs/skaclient.h>
+#include <skalibs/posixishard.h>
#include "skaclient-internal.h"
int skaclient_start_cb (unixmessage_t const *m, skaclient_cbdata_t *blah)
diff --git a/src/libunixonacid/textclient_command.c b/src/libunixonacid/textclient_command.c
index 56c7122..a0015ac 100644
--- a/src/libunixonacid/textclient_command.c
+++ b/src/libunixonacid/textclient_command.c
@@ -3,8 +3,8 @@
#include <sys/uio.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/textclient.h>
+#include <skalibs/posixishard.h>
int textclient_command (textclient_t *a, char const *s, size_t len, tain_t const *deadline, tain_t *stamp)
{
diff --git a/src/libunixonacid/textclient_commandv.c b/src/libunixonacid/textclient_commandv.c
index ec61498..267e584 100644
--- a/src/libunixonacid/textclient_commandv.c
+++ b/src/libunixonacid/textclient_commandv.c
@@ -3,8 +3,8 @@
#include <sys/uio.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/textclient.h>
+#include <skalibs/posixishard.h>
int textclient_commandv (textclient_t *a, struct iovec const *v, unsigned int n, tain_t const *deadline, tain_t *stamp)
{
diff --git a/src/libunixonacid/textclient_server_init_frompipe.c b/src/libunixonacid/textclient_server_init_frompipe.c
index e606eeb..9cd549e 100644
--- a/src/libunixonacid/textclient_server_init_frompipe.c
+++ b/src/libunixonacid/textclient_server_init_frompipe.c
@@ -5,12 +5,12 @@
#include <fcntl.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/types.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/djbunix.h>
#include <skalibs/textmessage.h>
#include <skalibs/textclient.h>
+#include <skalibs/posixishard.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)
{
diff --git a/src/libunixonacid/textclient_server_init_fromsocket.c b/src/libunixonacid/textclient_server_init_fromsocket.c
index b7f4e84..4964524 100644
--- a/src/libunixonacid/textclient_server_init_fromsocket.c
+++ b/src/libunixonacid/textclient_server_init_fromsocket.c
@@ -1,25 +1,15 @@
/* ISC license. */
-#include <skalibs/nonposix.h>
-
-#include <sys/uio.h>
#include <errno.h>
#include <string.h>
-#include <sys/socket.h>
+#include <sys/uio.h>
-#include <skalibs/posixishard.h>
-#include <skalibs/types.h>
-#include <skalibs/allreadwrite.h>
#include <skalibs/djbunix.h>
#include <skalibs/unix-timed.h>
+#include <skalibs/ancil.h>
#include <skalibs/textmessage.h>
#include <skalibs/textclient.h>
-
-union aligner_u
-{
- struct cmsghdr cmsghdr ;
- int i ;
-} ;
+#include <skalibs/posixishard.h>
static int getfd (void *p)
{
@@ -35,30 +25,7 @@ static int one (void *p)
static int sendit (void *p)
{
int *fd = p ;
- union aligner_u ancilbuf[1 + (CMSG_SPACE(sizeof(int)) - 1) / sizeof(union aligner_u)] ;
- ssize_t r ;
- char ch = '|' ;
- struct iovec v = { .iov_base = &ch, .iov_len = 1 } ;
- struct msghdr hdr =
- {
- .msg_name = 0,
- .msg_namelen = 0,
- .msg_iov = &v,
- .msg_iovlen = 1,
- .msg_control = ancilbuf,
- .msg_controllen = CMSG_SPACE(sizeof(int))
- } ;
- struct cmsghdr *c = CMSG_FIRSTHDR(&hdr) ;
- memset(hdr.msg_control, 0, hdr.msg_controllen) ;
- c->cmsg_level = SOL_SOCKET ;
- c->cmsg_type = SCM_RIGHTS ;
- c->cmsg_len = CMSG_LEN(sizeof(int)) ;
- *(int *)CMSG_DATA(c) = fd[1] ;
- do r = sendmsg(fd[0], &hdr, MSG_NOSIGNAL) ;
- while (r < 0 && errno == EINTR) ;
- if (r <= 0) return 0 ;
- fd_close(fd[1]) ;
- return 1 ;
+ return ancil_send_fd(fd[0], fd[1], '|') ;
}
int textclient_server_init_fromsocket (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)
diff --git a/src/libunixonacid/textclient_start.c b/src/libunixonacid/textclient_start.c
index 8eb8b13..3074ae3 100644
--- a/src/libunixonacid/textclient_start.c
+++ b/src/libunixonacid/textclient_start.c
@@ -1,26 +1,18 @@
/* ISC license. */
-#include <skalibs/sysdeps.h>
-#include <skalibs/nonposix.h>
-
#include <sys/uio.h>
#include <string.h>
#include <errno.h>
-#include <sys/socket.h>
-#include <skalibs/posixishard.h>
#include <skalibs/allreadwrite.h>
+#include <skalibs/error.h>
#include <skalibs/webipc.h>
#include <skalibs/djbunix.h>
#include <skalibs/unix-timed.h>
+#include <skalibs/ancil.h>
#include <skalibs/textmessage.h>
#include <skalibs/textclient.h>
-
-union aligner_u
-{
- struct cmsghdr cmsghdr ;
- int i ;
-} ;
+#include <skalibs/posixishard.h>
static int getfd (void *p)
{
@@ -29,56 +21,13 @@ static int getfd (void *p)
static ssize_t get (void *p)
{
- static int const awesomeflags =
-#ifdef SKALIBS_HASMSGDONTWAIT
- MSG_DONTWAIT
-#else
- 0
-#endif
- |
-#ifdef SKALIBS_HASCMSGCLOEXEC
- MSG_CMSG_CLOEXEC
-#else
- 0
-#endif
- ;
- struct cmsghdr *c ;
int *fd = p ;
- ssize_t r ;
- union aligner_u ancilbuf[1 + (CMSG_SPACE(sizeof(int)) - 1) / sizeof(union aligner_u)] ;
- char ch ;
- struct iovec v = { .iov_base = &ch, .iov_len = 1 } ;
- struct msghdr msghdr =
- {
- .msg_name = 0,
- .msg_namelen = 0,
- .msg_iov = &v,
- .msg_iovlen = 1,
- .msg_flags = 0,
- .msg_control = ancilbuf,
- .msg_controllen = CMSG_SPACE(sizeof(int))
- } ;
- do r = recvmsg(fd[0], &msghdr, awesomeflags) ;
- while (r < 0 && errno == EINTR) ;
- if (r <= 0) return sanitize_read(r) ;
- c = CMSG_FIRSTHDR(&msghdr) ;
- if (ch != '|'
- || !c
- || c->cmsg_level != SOL_SOCKET
- || c->cmsg_type != SCM_RIGHTS
- || (size_t)(c->cmsg_len - (CMSG_DATA(c) - (unsigned char *)c)) != sizeof(int)) return (errno = EPROTO, -1) ;
-#ifndef SKALIBS_HASCMSGCLOEXEC
- if (coe(*(int *)CMSG_DATA(c)) < 0)
- {
- fd_close(*(int *)CMSG_DATA(c)) ;
- return -1 ;
- }
-#endif
- fd[1] = *(int *)CMSG_DATA(c) ;
+ int r = ancil_recv_fd(fd[0], '|') ;
+ if (r < 0) return error_isagain(errno) ? (errno = 0, 0) : r ;
+ fd[1] = r ;
return 1 ;
}
-
-
+
int textclient_start (textclient_t *a, char const *path, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp)
{
struct iovec v ;
diff --git a/src/libunixonacid/textclient_startf.c b/src/libunixonacid/textclient_startf.c
index 12c2b20..20ebe33 100644
--- a/src/libunixonacid/textclient_startf.c
+++ b/src/libunixonacid/textclient_startf.c
@@ -4,11 +4,11 @@
#include <string.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/djbunix.h>
#include <skalibs/textmessage.h>
#include <skalibs/textclient.h>
+#include <skalibs/posixishard.h>
int textclient_startf (textclient_t *a, char const *const *argv, char const *const *envp, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp)
{
diff --git a/src/libunixonacid/unixmessage_put.c b/src/libunixonacid/unixmessage_put.c
index a2ac302..9ce103d 100644
--- a/src/libunixonacid/unixmessage_put.c
+++ b/src/libunixonacid/unixmessage_put.c
@@ -3,13 +3,13 @@
#include <string.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/bitarray.h>
#include <skalibs/disize.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/siovec.h>
#include <skalibs/unixmessage.h>
+#include <skalibs/posixishard.h>
static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned char const *bits, unixmessage_sender_closecb_func_t_ref closecb, void *closecbdata)
{
diff --git a/src/libunixonacid/unixmessage_receive.c b/src/libunixonacid/unixmessage_receive.c
index 811baae..b4171f0 100644
--- a/src/libunixonacid/unixmessage_receive.c
+++ b/src/libunixonacid/unixmessage_receive.c
@@ -7,7 +7,6 @@
#include <sys/socket.h>
#include <sys/uio.h>
-#include <skalibs/posixishard.h>
#include <skalibs/uint16.h>
#include <skalibs/uint32.h>
#include <skalibs/cbuffer.h>
@@ -15,6 +14,7 @@
#include <skalibs/allreadwrite.h>
#include <skalibs/stralloc.h>
#include <skalibs/unixmessage.h>
+#include <skalibs/posixishard.h>
union aligner_u
{
diff --git a/src/libunixonacid/unixmessage_sender_flush.c b/src/libunixonacid/unixmessage_sender_flush.c
index 3f096f0..96f9112 100644
--- a/src/libunixonacid/unixmessage_sender_flush.c
+++ b/src/libunixonacid/unixmessage_sender_flush.c
@@ -9,7 +9,6 @@
#include <unistd.h>
#include <errno.h>
-#include <skalibs/posixishard.h>
#include <skalibs/uint16.h>
#include <skalibs/uint32.h>
#include <skalibs/disize.h>
@@ -17,6 +16,7 @@
#include <skalibs/genalloc.h>
#include <skalibs/djbunix.h>
#include <skalibs/unixmessage.h>
+#include <skalibs/posixishard.h>
union aligner_u
{