[PATCH v4] Cygwin: pipe: Avoid deadlock for non-cygwin writer.

Jeremy Drake cygwin@jdrake.com
Tue Mar 29 15:21:11 GMT 2022


On Tue, 29 Mar 2022, Takashi Yano wrote:

> diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
> index fb3d09d84..cd2d3a7ef 100644
> --- a/winsup/cygwin/spawn.cc
> +++ b/winsup/cygwin/spawn.cc
> @@ -645,8 +646,18 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
>  		     && (fd == fileno_stdout || fd == fileno_stderr))
>  	      {
>  		fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd;
> -		pipe->close_query_handle ();
>  		pipe->set_pipe_non_blocking (false);
> +		pipe->request_close_query_hdl ();
> +
> +		tty_min dummy_tty;
> +		dummy_tty.ntty = (fh_devices) myself->ctty;
> +		dummy_tty.pgid = myself->pgid;
> +		tty_min *t = cygwin_shared->tty.get_cttyp ();
> +		if (!t) /* If tty is not allocated, use dummy_tty instead. */
> +		  t = &dummy_tty;
> +		/* Emit __SIGNONCYGCHLD to let all processes in the
> +		   process group close query_hdl. */
> +		t->kill_pgrp (__SIGNONCYGCHLD);
>  	      }
>  	    else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin)
>  	      {
>

This block seems to be inside a loop over handles.  Would it make sense to
move the `tty_min dummy_tty` through `t->kill_pgrp` lines outside the
loop, and set a flag in the loop instead, so the pgrp only needs to be
signaled (killed) once rather than for each handle that needs closing?


More information about the Cygwin-patches mailing list