skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 15eda3d33f9e1160d438d370acd442ef3dbba63f
parent 332d4cbc24ab82cc77bccb0ce2c158c5e86a8fac
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Tue, 19 Feb 2019 14:54:44 +0000

 Add DragonFly macro; remove nbwaitall and ancilautoclose

Diffstat:
Mconfigure | 2--
Mpackage/deps.mak | 8++++----
Msrc/include/skalibs/nonposix.h | 2+-
Msrc/libunixonacid/textclient_server_init_fromsocket.c | 3---
Msrc/libunixonacid/unixmessage_put.c | 22----------------------
Msrc/libunixonacid/unixmessage_receive.c | 6------
Msrc/libunixonacid/unixmessage_sender_flush.c | 3---
Msrc/libunixonacid/unixmessage_sender_free.c | 4----
Dsrc/sysdeps/tryancilautoclose.c | 12------------
Dsrc/sysdeps/trynbwaitall.c | 121-------------------------------------------------------------------------------
10 files changed, 5 insertions(+), 178 deletions(-)

diff --git a/configure b/configure @@ -505,7 +505,6 @@ EOF trytypes choose clr nullispointer NULLISPOINTER 'a pointer-typed NULL' choose clr accept4 ACCEPT4 'accept4()' - choose clr ancilautoclose ANCILAUTOCLOSE 'auto-close after fd-passing' choose c cmsgcloexec CMSGCLOEXEC 'MSG_CMSG_CLOEXEC' choose clr devurandom DEVURANDOM '/dev/urandom' choose cl dirfd DIRFD 'dirfd()' @@ -518,7 +517,6 @@ EOF choose cl ipv6 IPV6 'IPv6 support' $socket_lib choose clr malloc0 MALLOC0 'non-NULL malloc(0)' choose c msgdontwait MSGDONTWAIT 'MSG_DONTWAIT' - choose clr nbwaitall NBWAITALL 'non-blocking MSG_WAITALL' choose c odirectory ODIRECTORY 'O_DIRECTORY' choose cl openat OPENAT 'openat()' choose cl linkat LINKAT 'linkat()' diff --git a/package/deps.mak b/package/deps.mak @@ -787,7 +787,7 @@ 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/error.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/error.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.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_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/error.h src/include/skalibs/nonposix.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/error.h src/include/skalibs/nonposix.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_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/error.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 @@ -820,7 +820,7 @@ src/libunixonacid/unixmessage_bits_closeall.o src/libunixonacid/unixmessage_bits src/libunixonacid/unixmessage_bits_closenone.o src/libunixonacid/unixmessage_bits_closenone.lo: src/libunixonacid/unixmessage_bits_closenone.c src/include/skalibs/bitarray.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_drop.o src/libunixonacid/unixmessage_drop.lo: src/libunixonacid/unixmessage_drop.c src/include/skalibs/djbunix.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_handle.o src/libunixonacid/unixmessage_handle.lo: src/libunixonacid/unixmessage_handle.c src/include/skalibs/unixmessage.h -src/libunixonacid/unixmessage_put.o src/libunixonacid/unixmessage_put.lo: src/libunixonacid/unixmessage_put.c src/include/skalibs/bitarray.h src/include/skalibs/disize.h src/include/skalibs/error.h src/include/skalibs/genalloc.h src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/include/skalibs/sysdeps.h src/include/skalibs/unixmessage.h +src/libunixonacid/unixmessage_put.o src/libunixonacid/unixmessage_put.lo: src/libunixonacid/unixmessage_put.c src/include/skalibs/bitarray.h src/include/skalibs/disize.h src/include/skalibs/error.h src/include/skalibs/genalloc.h src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receive.o src/libunixonacid/unixmessage_receive.lo: src/libunixonacid/unixmessage_receive.c src/include/skalibs/allreadwrite.h src/include/skalibs/cbuffer.h src/include/skalibs/djbunix.h src/include/skalibs/error.h src/include/skalibs/nonposix.h src/include/skalibs/stralloc.h src/include/skalibs/sysdeps.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receiver_0.o src/libunixonacid/unixmessage_receiver_0.lo: src/libunixonacid/unixmessage_receiver_0.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receiver_free.o src/libunixonacid/unixmessage_receiver_free.lo: src/libunixonacid/unixmessage_receiver_free.c src/include/skalibs/cbuffer.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h @@ -828,8 +828,8 @@ src/libunixonacid/unixmessage_receiver_hasmsginbuf.o src/libunixonacid/unixmessa src/libunixonacid/unixmessage_receiver_init.o src/libunixonacid/unixmessage_receiver_init.lo: src/libunixonacid/unixmessage_receiver_init.c src/include/skalibs/cbuffer.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_1.o src/libunixonacid/unixmessage_sender_1.lo: src/libunixonacid/unixmessage_sender_1.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_closecb.o src/libunixonacid/unixmessage_sender_closecb.lo: src/libunixonacid/unixmessage_sender_closecb.c src/include/skalibs/djbunix.h src/include/skalibs/unixmessage.h -src/libunixonacid/unixmessage_sender_flush.o src/libunixonacid/unixmessage_sender_flush.lo: src/libunixonacid/unixmessage_sender_flush.c src/include/skalibs/allreadwrite.h src/include/skalibs/disize.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h -src/libunixonacid/unixmessage_sender_free.o src/libunixonacid/unixmessage_sender_free.lo: src/libunixonacid/unixmessage_sender_free.c src/include/skalibs/disize.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/sysdeps.h src/include/skalibs/unixmessage.h +src/libunixonacid/unixmessage_sender_flush.o src/libunixonacid/unixmessage_sender_flush.lo: src/libunixonacid/unixmessage_sender_flush.c src/include/skalibs/allreadwrite.h src/include/skalibs/disize.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/nonposix.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h +src/libunixonacid/unixmessage_sender_free.o src/libunixonacid/unixmessage_sender_free.lo: src/libunixonacid/unixmessage_sender_free.c src/include/skalibs/disize.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_getfd.o src/libunixonacid/unixmessage_sender_getfd.lo: src/libunixonacid/unixmessage_sender_getfd.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_init.o src/libunixonacid/unixmessage_sender_init.lo: src/libunixonacid/unixmessage_sender_init.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_init_withclosecb.o src/libunixonacid/unixmessage_sender_init_withclosecb.lo: src/libunixonacid/unixmessage_sender_init_withclosecb.c src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h diff --git a/src/include/skalibs/nonposix.h b/src/include/skalibs/nonposix.h @@ -61,7 +61,7 @@ because the BSDs are bloody snowflakes. See: setgroups(). */ #undef SKALIBS_BSD_SUCKS -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__DragonFly__) # define SKALIBS_BSD_SUCKS #endif diff --git a/src/libunixonacid/textclient_server_init_fromsocket.c b/src/libunixonacid/textclient_server_init_fromsocket.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> #include <sys/uio.h> #include <errno.h> @@ -60,9 +59,7 @@ static int sendit (void *p) do r = sendmsg(fd[0], &hdr, MSG_NOSIGNAL) ; while (r < 0 && errno == EINTR) ; if (r <= 0) return 0 ; -#ifndef SKALIBS_HASANCILAUTOCLOSE fd_close(fd[1]) ; -#endif return 1 ; } diff --git a/src/libunixonacid/unixmessage_put.c b/src/libunixonacid/unixmessage_put.c @@ -1,9 +1,5 @@ /* ISC license. */ -#include <skalibs/sysdeps.h> -#ifdef SKALIBS_HASANCILAUTOCLOSE -#include <unistd.h> -#endif #include <string.h> #include <errno.h> #include <skalibs/bitarray.h> @@ -22,24 +18,6 @@ static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned cha int fd = fds[i] ; if (fd < 0) return (errno = EINVAL, -1) ; if (bitarray_peek(bits, i)) fd = - fd - 1 ; -#ifdef SKALIBS_HASANCILAUTOCLOSE - else - { - fd = dup(fd) ; - if (fd < 0) - { - int e = errno ; - while (i--) - { - s -= sizeof(int) ; - memcpy((char *)fd, s, sizeof(int)) ; - if (fd >= 0) (*closecb)(fd, closecbdata) ; - } - errno = e ; - return 0 ; - } - } -#endif memcpy(s, (char const *)&fd, sizeof(int)) ; s += sizeof(int) ; } diff --git a/src/libunixonacid/unixmessage_receive.c b/src/libunixonacid/unixmessage_receive.c @@ -27,12 +27,6 @@ static int const awesomeflags = 0 #endif | -#ifdef SKALIBS_HASNBWAITALL - MSG_WAITALL -#else - 0 -#endif - | #ifdef SKALIBS_HASCMSGCLOEXEC MSG_CMSG_CLOEXEC #else diff --git a/src/libunixonacid/unixmessage_sender_flush.c b/src/libunixonacid/unixmessage_sender_flush.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> #include <sys/socket.h> #include <sys/uio.h> @@ -104,7 +103,6 @@ int unixmessage_sender_flush (unixmessage_sender_t *b) do r = sendmsg(b->fd, &hdr, MSG_NOSIGNAL) ; while (r < 0 && errno == EINTR) ; if (r <= 0) return 0 ; -#ifndef SKALIBS_HASANCILAUTOCLOSE if (nfds) { size_t i = 0 ; @@ -114,7 +112,6 @@ int unixmessage_sender_flush (unixmessage_sender_t *b) if (fd < 0) (*b->closecb)(-(fd+1), b->closecbdata) ; } } -#endif if ((size_t)r < 6 + len) { b->shorty = 6 + len - r ; diff --git a/src/libunixonacid/unixmessage_sender_free.c b/src/libunixonacid/unixmessage_sender_free.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <skalibs/sysdeps.h> #include <sys/types.h> #include <skalibs/disize.h> #include <skalibs/stralloc.h> @@ -18,9 +17,6 @@ void unixmessage_sender_free (unixmessage_sender_t *b) { int fd = genalloc_s(int, &b->fds)[i] ; if (fd < 0) (*b->closecb)(-(fd+1), b->closecbdata) ; -#ifdef SKALIBS_HASANCILAUTOCLOSE - else (*b->closecb)(fd, b->closecbdata) ; -#endif } } genalloc_free(disize, &b->offsets) ; diff --git a/src/sysdeps/tryancilautoclose.c b/src/sysdeps/tryancilautoclose.c @@ -1,12 +0,0 @@ -/* ISC license. */ - - /* - * It's actually false everywhere. - * Not removing the test for now because it would mean editing all the - * places where the test happens. Will remove it later. - */ - -int main (void) -{ - return 1 ; -} diff --git a/src/sysdeps/trynbwaitall.c b/src/sysdeps/trynbwaitall.c @@ -1,121 +0,0 @@ -/* ISC license. */ - -#undef _POSIX_C_SOURCE -#undef _XOPEN_SOURCE - -#ifndef _XPG4_2 -#define _XPG4_2 -#endif - -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <signal.h> -#include <sys/socket.h> -#include <sys/select.h> -#include <sys/uio.h> - -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif - -#ifndef MSG_DONTWAIT -#define MSG_DONTWAIT 0 -#endif - - -static int ndelay_on (int fd) -{ - int got = fcntl(fd, F_GETFL) ; - return (got == -1) ? -1 : fcntl(fd, F_SETFL, got | O_NONBLOCK) ; -} - -static int child (int p, int fd) -{ - char buf[8] ; - struct iovec v = { .iov_base = buf, .iov_len = 8 } ; - struct msghdr msg = - { - .msg_name = 0, - .msg_namelen = 0, - .msg_iov = &v, - .msg_iovlen = 1, - .msg_control = 0, - .msg_controllen = 0 - } ; - fd_set rfds ; - if (ndelay_on(fd) < 0) return 111 ; - FD_ZERO(&rfds) ; - FD_SET(fd, &rfds) ; - if (write(p, "", 1) < 1) return 111 ; /* sync with the parent */ - if (select(fd+1, &rfds, 0, 0, 0) < 1) return 111 ; - - /* The following recvmsg may block, despite setting the fd - non-blocking. That is what we're testing. */ - - if (recvmsg(fd, &msg, MSG_WAITALL | MSG_DONTWAIT) < 1) return 111 ; - if (write(p, "", 1) < 1) return 111 ; - return 0 ; -} - -static int parent (pid_t pid, int p, int fd) -{ - char c ; - struct iovec v = { .iov_base = &c, .iov_len = 1 } ; - struct msghdr msg = - { - .msg_name = 0, - .msg_namelen = 0, - .msg_iov = &v, - .msg_iovlen = 1, - .msg_control = 0, - .msg_controllen = 0 - } ; - struct timeval tv = { .tv_sec = 2, .tv_usec = 0 } ; - fd_set rfds ; - unsigned int n = p > fd ? p : fd ; - int r ; - FD_ZERO(&rfds) ; - FD_SET(p, &rfds) ; - if (read(p, &c, 1) < 1) return 111 ; - if (sendmsg(fd, &msg, MSG_NOSIGNAL) < 1) return 111 ; - for (;;) - { - r = select(n+1, &rfds, 0, 0, &tv) ; - if (r >= 0 || errno != EINTR) break ; - } - if (!r) /* child is still blocking on recvmsg() after 2 seconds */ - { - kill(pid, SIGTERM) ; - return 1 ; - } - if (read(p, &c, 1) < 1) return 111 ; - return 0 ; -} - -int main (void) -{ - pid_t pid ; - int fd[2] ; - int p[2] ; - if (pipe(p) < 0) return 111 ; - if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) return 111 ; - pid = fork() ; - if (pid < 0) return 111 ; - if (!pid) - { - close(p[0]) ; - close(fd[0]) ; - return child(p[1], fd[1]) ; - } - close(p[1]) ; - close(fd[1]) ; - return parent(pid, p[0], fd[0]) ; -}