From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E5D8A469719 for ; Wed, 11 Mar 2020 10:55:46 +0300 (MSK) Received: by mail-lj1-f195.google.com with SMTP id o10so1184914ljc.8 for ; Wed, 11 Mar 2020 00:55:46 -0700 (PDT) Date: Wed, 11 Mar 2020 10:55:44 +0300 From: Cyrill Gorcunov Message-ID: <20200311075544.GI27301@uranus> References: <20200302201227.31785-1-gorcunov@gmail.com> <20200302201227.31785-7-gorcunov@gmail.com> <20200303113853.2gmoaph7zet7rzwo@tkn_work_nb> <20200303114537.GF22649@uranus> <20200310154949.5zdpc4pcpc7evczz@tkn_work_nb> <20200310163646.3yngdlq6wzutzmri@tkn_work_nb> <20200310164100.GF27301@uranus> <20200310171252.nxim2zgghvdqkmei@tkn_work_nb> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200310171252.nxim2zgghvdqkmei@tkn_work_nb> Subject: [Tarantool-patches] [PATCH v5 6/7] popen: handle sid on macos List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Turenko Cc: tml Due to os specifics we can't call setsid after vfork on macos (vfork is not longer a part of posix btw). Instead we can use ioctl to clear the session, then initiate a new process group. Signed-off-by: Cyrill Gorcunov --- branch gorcunov/gh-4031-popen-fixup-4 src/lib/core/popen.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c index 6e5ca21bd..a0630e3d9 100644 --- a/src/lib/core/popen.c +++ b/src/lib/core/popen.c @@ -16,6 +16,10 @@ #include "coio.h" #include "say.h" +#ifdef TARGET_OS_DARWIN +# include +#endif + /* A mapping to find popens by their pids in a signal handler */ static struct mh_i32ptr_t *popen_pids_map = NULL; @@ -833,15 +837,29 @@ popen_new(struct popen_opts *opts) if (opts->flags & POPEN_FLAG_RESTORE_SIGNALS) signal_reset(); - /* - * We have to be a session leader otherwise - * won't be able to kill a group of children. - */ if (opts->flags & POPEN_FLAG_SETSID) { +#ifndef TARGET_OS_DARWIN if (setsid() == -1) { say_syserror("child: setsid failed"); goto exit_child; } +#else + /* + * Note that on MacOS we're not allowed to + * set sid after vfork (it is OS specific) + * thus use ioctl instead. + */ + int ttyfd = open("/dev/tty", O_RDWR, 0); + if (ttyfd >= 0) { + ioctl(ttyfd, TIOCNOTTY, 0); + close(ttyfd); + } + + if (setpgrp() == -1) { + say_syserror("child: setpgrp failed"); + goto exit_child; + } +#endif } if (opts->flags & POPEN_FLAG_CLOSE_FDS) { -- 2.20.1