[tarantool-patches] Re: [PATCH] Enable support for NOTIFY_SOCKET on macOS
Konstantin Osipov
kostja at tarantool.org
Mon Aug 19 23:18:27 MSK 2019
* Max Melentiev <dmarc-noreply at freelists.org> [19/08/19 11:31]:
> To make it possible to develop and test related features on macOS.
>
> SOCK_CLOEXEC (not available on macOS) flag for socket()
> is replaced with `fcntl(fd, F_SETFD, FD_CLOEXEC)` which has the same effect.
>
> MSG_NOSIGNAL flag for sendmsg is also not available on macOS.
> However it has SO_NOSIGPIPE flag for setsockopt which disables SIGPIPE.
> So it requires different solution for different OS.
> Inspired by https://nwat.xyz/blog/2014/01/16/porting-msg_more-and-msg_nosigpipe-to-osx/
>
> `sendmsg()` is replaced with `sendto()` because `msg_namelen` was calculated incorrectly.
> New method builds message automatically without errors.
Just like Alexander, generally looks good, but a lot of nitpicks:
> -#if defined(WITH_SYSTEMD)
I don't think you should remove this ifdef at all. Simply enable
it on Mac OSX by default in cmake if it works there now.
> #include <errno.h>
> #include <stdio.h>
> #include <stdarg.h>
> @@ -68,11 +67,25 @@ int systemd_init() {
> say_error("systemd: NOTIFY_SOCKET is longer that MAX_UNIX_PATH");
> goto error;
> }
> - if ((systemd_fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == -1) {
> + if ((systemd_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
> say_syserror("systemd: failed to create unix socket");
> goto error;
> }
> - int sndbuf_sz = 8 * 1024 * 1024;
> + if (fcntl(systemd_fd, F_SETFD, FD_CLOEXEC) == -1) {
> + say_syserror("systemd: fcntl failed to set FD_CLOEXEC");
> + goto error;
> + }
This hunk is good, but I agree that the new buffer size choice
need a comment. Better right in the source code. The old choice
was inexplicable, the new one is just as confusing.
> +
> + #ifdef SYSTEMD_USE_SO_NOSIGPIPE
We prefer feature-test defines, not platform-specific
defines, which basically means you need to use
https://cmake.org/cmake/help/v3.0/module/CheckCSourceCompiles.html
for checking whether SO_NOSIGPIPE and MSG_NOSIGNAL exist,
define HAVE_SONOSIGPIPE and HAVE_MSG_NOSIGNAL in config.h.in, and
test them here.
A quick and hackish way is to look for TARGET_OS_DARWIN right
here. Inventing your own within-the-code define is ugly and not
acceptable.
Please keep in mind we also support FreeBSD - or at least pretend
we do.
--
Konstantin Osipov, Moscow, Russia
More information about the Tarantool-patches
mailing list