From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id C871625EA0 for ; Mon, 19 Aug 2019 16:18:30 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zmayuoG6lX_h for ; Mon, 19 Aug 2019 16:18:30 -0400 (EDT) Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 72D3B25E72 for ; Mon, 19 Aug 2019 16:18:30 -0400 (EDT) Date: Mon, 19 Aug 2019 23:18:27 +0300 From: Konstantin Osipov Subject: [tarantool-patches] Re: [PATCH] Enable support for NOTIFY_SOCKET on macOS Message-ID: <20190819201827.GA21602@atlas> References: <20190819082813.38237-1-m.melentiev@corp.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190819082813.38237-1-m.melentiev@corp.mail.ru> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Max Melentiev * Max Melentiev [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 > #include > #include > @@ -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