[Tarantool-patches] [PATCH 6/7] popen: handle setsid os specifics

Alexander Turenko alexander.turenko at tarantool.org
Tue Mar 3 14:38:53 MSK 2020


On Mon, Mar 02, 2020 at 11:12:26PM +0300, Cyrill Gorcunov wrote:
> On linux it is fine to call setsid right after
> the vfork, in turn on bsd pgrp should be used.

Can you refer a source of this information?

I tried the following snippet on Mac OS and FreeBSD and it at least does
not report an error:

 | #include <unistd.h>
 | #include <stdio.h>
 | 
 | int
 | main()
 | {
 | 	if (setsid() == -1) {
 | 		perror("setsid");
 | 		return 1;
 | 	}
 | 	return 0;
 | }

$ cc setsid.c -o setsid
$ echo 1 | ./setsid

(Pipeline is to not be a session leader already, this will lead to EPERM.)

> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
> ---
>  src/lib/core/popen.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c
> index 6e5ca21bd..d41e9cfce 100644
> --- a/src/lib/core/popen.c
> +++ b/src/lib/core/popen.c
> @@ -839,8 +839,15 @@ popen_new(struct popen_opts *opts)
>  		 */
>  		if (opts->flags & POPEN_FLAG_SETSID) {
>  			if (setsid() == -1) {
> +#ifndef TARGET_OS_DARWIN
>  				say_syserror("child: setsid failed");
>  				goto exit_child;
> +#else
> +				if (setpgrp() == -1) {
> +					say_syserror("child: setpgrp failed");
> +					goto exit_child;
> +				}
> +#endif
>  			}
>  		}
>  
> -- 
> 2.20.1
> 


More information about the Tarantool-patches mailing list