From: Cyrill Gorcunov <gorcunov@gmail.com> To: tml <tarantool-patches@dev.tarantool.org>, Alexander Turenko <alexander.turenko@tarantool.org> Subject: [Tarantool-patches] [PATCH v3 6/7] popen: use ioctl on macos Date: Tue, 10 Mar 2020 11:02:09 +0300 [thread overview] Message-ID: <20200310080209.GE27301@uranus> (raw) In-Reply-To: <20200306143047.GA27301@uranus> 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. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- branch gorcunov/gh-4031-popen-fixup-3 Sasha, I do not send the whole series since the only this particular patch is changed. Thus if needed we can merge from the branch above. src/lib/core/popen.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c index 6e5ca21bd..cc3d2d946 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 <sys/ioctl.h> +#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,24 @@ 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); + } +#endif } if (opts->flags & POPEN_FLAG_CLOSE_FDS) { -- 2.20.1
next prev parent reply other threads:[~2020-03-10 8:02 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-02 20:12 [Tarantool-patches] [PATCH 0/7] popen: various fixes and a test Cyrill Gorcunov 2020-03-02 20:12 ` [Tarantool-patches] [PATCH 1/7] core/say: Export logger fd Cyrill Gorcunov 2020-03-02 20:12 ` [Tarantool-patches] [PATCH 2/7] popen: allow accessing environ variable Cyrill Gorcunov 2020-03-02 20:12 ` [Tarantool-patches] [PATCH 3/7] popen: close_inherited_fds - add support for macos/freebsd Cyrill Gorcunov 2020-03-02 20:12 ` [Tarantool-patches] [PATCH 4/7] popen: log errors if popen creation failed Cyrill Gorcunov 2020-03-02 20:12 ` [Tarantool-patches] [PATCH 5/7] popen: add logging in child process Cyrill Gorcunov 2020-03-02 20:12 ` [Tarantool-patches] [PATCH 6/7] popen: handle setsid os specifics Cyrill Gorcunov 2020-03-03 11:38 ` Alexander Turenko 2020-03-03 11:45 ` Cyrill Gorcunov 2020-03-10 15:49 ` Alexander Turenko 2020-03-10 16:36 ` Alexander Turenko 2020-03-10 16:41 ` Cyrill Gorcunov 2020-03-10 17:12 ` Alexander Turenko 2020-03-10 17:40 ` Cyrill Gorcunov 2020-03-11 7:55 ` [Tarantool-patches] [PATCH v5 6/7] popen: handle sid on macos Cyrill Gorcunov 2020-03-06 14:30 ` [Tarantool-patches] [PATCH v2 6/7] popen: handle setsid os specifics Cyrill Gorcunov 2020-03-10 8:02 ` Cyrill Gorcunov [this message] 2020-03-02 20:12 ` [Tarantool-patches] [PATCH 7/7] test/unit: add popen test Cyrill Gorcunov 2020-03-11 20:22 ` Alexander Turenko 2020-03-12 10:38 ` [Tarantool-patches] [PATCH v5 " Cyrill Gorcunov 2020-03-12 11:58 ` [Tarantool-patches] [PATCH 0/7] popen: various fixes and a test Alexander Turenko 2020-03-12 12:18 ` Cyrill Gorcunov 2020-03-16 15:58 ` 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=20200310080209.GE27301@uranus \ --to=gorcunov@gmail.com \ --cc=alexander.turenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v3 6/7] popen: use ioctl 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