From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4DC6A469719 for ; Tue, 10 Mar 2020 20:12:50 +0300 (MSK) Date: Tue, 10 Mar 2020 20:12:52 +0300 From: Alexander Turenko Message-ID: <20200310171252.nxim2zgghvdqkmei@tkn_work_nb> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200310164100.GF27301@uranus> Subject: Re: [Tarantool-patches] [PATCH 6/7] popen: handle setsid os specifics List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov Cc: tml On Tue, Mar 10, 2020 at 07:41:00PM +0300, Cyrill Gorcunov wrote: > On Tue, Mar 10, 2020 at 07:36:46PM +0300, Alexander Turenko wrote: > > > It seems that setsid() is used mainly to disassociate from a controlling > > > terminal (to don't be hit by SIGHUP if it'll die). In this context > > > setpgrp() would not be sufficient. > > > > I just realized that there is another reason to use setsid(), where > > setpgrp() is applicable too: move the child into its own process group > > and kill the whole group (child and its childs if any) then. I mean, use > > the corresponding flag (which I proposed to add in [1]), which will > > change :kill() behaviour. > > > > [1]: https://lists.tarantool.org/pipermail/tarantool-patches/2020-March/014608.html > > > > So, it seems, we should do ioctl() + setpgrp() on Mac OS? > > The child may generate subchildren with own groups. If I'm not missing > something obvious we should provide only basic functionality whic would > be enough to spawn new processes. The child may generate subchildren > with own group, serisouly without pid namespace we simply do not control > much. Thus I propose to leave it in the state it is right now. We don't intend to offer some kind of guaranteed isolation. A child may spawn a daemon, yep. But we usually know what we're run and whether it will do something like this. We should provide a tool to do the following: * Allow to spawn a background process, which will not die even if a controlling terminal died (setsid() or ioctl() solve it). * Allow to set a new process group for a process and its childs (say, for a non-inveractive shell) in order to be able to kill the entire group if we're going to free resources (setsid() or setpgrp() solve it). Usual case for the latter bullet: spawn a pipeline using "sh -c 'foo | bar'" and be able to kill it entirely. A non-interactive shell does not perform job control, so even "bash -c 'foo & bar'" will be killed entirely in the case. After looking around discussions re other popen implementations, I guess that we'll be asked for those abilities sooner or later. It seems logical to implement it, since we know it is expected from a popen implementation. WBR, Alexander Turenko.