Skip to content

Commit dfa0973

Browse files
committed
Cygwin: spawn: apply PID_NEW_PG flag to spawned child
Previously, it was always applied to "myself", which is only appropriate in the case of _P_OVERLAY (aka exec). Apply the flag to "myself" only in that case, and apply it to the new child instead in other cases. Also, clear the flag from "myself" in the case of a failed exec. Fixes: 8d8724e ("Cygwin: pty: Fix Ctrl-C handling further for non-cygwin apps.") Signed-off-by: Jeremy Drake <[email protected]>
1 parent 3ca80d1 commit dfa0973

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

winsup/cygwin/spawn.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,6 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
544544
c_flags |= CREATE_NEW_PROCESS_GROUP;
545545
refresh_cygheap ();
546546

547-
if (c_flags & CREATE_NEW_PROCESS_GROUP)
548-
InterlockedOr ((LONG *) &myself->process_state, PID_NEW_PG);
549-
550547
if (mode == _P_DETACH)
551548
/* all set */;
552549
else if (mode != _P_OVERLAY || !my_wr_proc_pipe)
@@ -605,7 +602,12 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
605602
::cygheap->user.deimpersonate ();
606603

607604
if (!real_path.iscygexec () && mode == _P_OVERLAY)
608-
InterlockedOr ((LONG *) &myself->process_state, PID_NOTCYGWIN);
605+
{
606+
LONG pidflags = PID_NOTCYGWIN;
607+
if (c_flags & CREATE_NEW_PROCESS_GROUP)
608+
pidflags |= PID_NEW_PG;
609+
InterlockedOr ((LONG *) &myself->process_state, pidflags);
610+
}
609611

610612
cygpid = (mode != _P_OVERLAY) ? create_cygwin_pid () : myself->pid;
611613

@@ -707,7 +709,8 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
707709
myself->sendsig = myself->exec_sendsig;
708710
myself->exec_sendsig = NULL;
709711
}
710-
InterlockedAnd ((LONG *) &myself->process_state, ~PID_NOTCYGWIN);
712+
InterlockedAnd ((LONG *) &myself->process_state,
713+
~(PID_NOTCYGWIN|PID_NEW_PG));
711714
/* Reset handle inheritance to default when the execution of a'
712715
non-Cygwin process fails. Only need to do this for _P_OVERLAY
713716
since the handle will be closed otherwise. Don't need to do
@@ -769,7 +772,9 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
769772
myself->set_has_pgid_children ();
770773
ProtectHandle (pi.hThread);
771774
pinfo child (cygpid,
772-
PID_IN_USE | (real_path.iscygexec () ? 0 : PID_NOTCYGWIN));
775+
PID_IN_USE |
776+
(real_path.iscygexec () ? 0 : PID_NOTCYGWIN) |
777+
((c_flags & CREATE_NEW_PROCESS_GROUP) ? PID_NEW_PG : 0));
773778
if (!child)
774779
{
775780
syscall_printf ("pinfo failed");

0 commit comments

Comments
 (0)