Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Max Melentiev <m.melentiev@corp.mail.ru>
Subject: [tarantool-patches] Re: [PATCH] Enable support for NOTIFY_SOCKET on macOS
Date: Mon, 19 Aug 2019 23:18:27 +0300	[thread overview]
Message-ID: <20190819201827.GA21602@atlas> (raw)
In-Reply-To: <20190819082813.38237-1-m.melentiev@corp.mail.ru>

* Max Melentiev <dmarc-noreply@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

  parent reply	other threads:[~2019-08-19 20:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19  8:28 [tarantool-patches] " Max Melentiev
2019-08-19 19:33 ` [tarantool-patches] " Alexander Turenko
2019-08-21  8:31   ` Maxim Melentiev
2019-08-21 15:52     ` Konstantin Osipov
2019-08-22  8:59       ` Maxim Melentiev
2019-08-22 10:06         ` Konstantin Osipov
2019-08-22 12:44           ` Maxim Melentiev
2019-08-22 13:03             ` Konstantin Osipov
2019-08-22 14:27               ` Maxim Melentiev
2019-08-23 12:11                 ` Alexander Turenko
2019-08-27 23:51                 ` Kirill Yukhin
2019-08-21 22:45     ` Alexander Turenko
2019-08-19 20:18 ` Konstantin Osipov [this message]
2019-08-20 15:26   ` Maxim Melentiev
2019-08-20 16:22     ` Konstantin Osipov
2019-08-27 23:54 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190819201827.GA21602@atlas \
    --to=kostja@tarantool.org \
    --cc=m.melentiev@corp.mail.ru \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH] Enable support for NOTIFY_SOCKET on macOS' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox