diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index bdbf443c9b..ca86b36438 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -1203,8 +1203,8 @@ ctrl_c_handler (DWORD type) if (!pinfo (cygwin_pid (GetCurrentProcessId ()))) return TRUE; - if (type == CTRL_C_EVENT && ::cygheap->ctty - && !cygheap->ctty->need_console_handler ()) + if (type == CTRL_C_EVENT && !myself->is_cygwin_inferior_being_debugged () + && ::cygheap->ctty && !cygheap->ctty->need_console_handler ()) /* Ctrl-C is handled in fhandler_console::cons_master_thread(). */ return TRUE; @@ -1500,6 +1500,23 @@ _cygtls::handle_SIGCONT () InterlockedAnd ((LONG *) &myself->process_state, ~PID_STOPPED); } +inline static bool +is_stop_or_cont (int sig) +{ + switch (sig) + { + case SIGSTOP: + case SIGTSTP: + case SIGTTIN: + case SIGTTOU: + case SIGCONT: + return true; + default: + break; + } + return false; +} + int sigpacket::process () { @@ -1653,7 +1670,7 @@ sigpacket::process () thissig.sa_flags &= ~SA_ONSTACK; dosig: - if (have_execed) + if (have_execed && (ch_spawn.iscygwin () || !is_stop_or_cont (si.si_signo))) { switch (si.si_signo) { diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc index b8cc154f5f..6f6164a859 100644 --- a/winsup/cygwin/fhandler/pty.cc +++ b/winsup/cygwin/fhandler/pty.cc @@ -219,6 +219,7 @@ atexit_func (void) break; } CloseHandle (h_gdb_inferior); + myself->wpid_debuggee_maybe = 0; } } @@ -255,6 +256,7 @@ CreateProcessA_Hooked DuplicateHandle (GetCurrentProcess (), h_gdb_inferior, GetCurrentProcess (), &h_gdb_inferior, 0, 0, DUPLICATE_SAME_ACCESS); + myself->wpid_debuggee_maybe = pi->dwProcessId; debug_process = !!(f & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)); if (debug_process) mutex_timeout = 0; /* to avoid deadlock in GDB */ @@ -294,6 +296,7 @@ CreateProcessW_Hooked DuplicateHandle (GetCurrentProcess (), h_gdb_inferior, GetCurrentProcess (), &h_gdb_inferior, 0, 0, DUPLICATE_SAME_ACCESS); + myself->wpid_debuggee_maybe = pi->dwProcessId; debug_process = !!(f & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)); if (debug_process) mutex_timeout = 0; /* to avoid deadlock in GDB */ @@ -1075,9 +1078,6 @@ fhandler_pty_slave::set_switch_to_nat_pipe (void) { isHybrid = true; setup_locale (); - myself->exec_dwProcessId = myself->dwProcessId; /* Set this as a marker - for tty::nat_fg() - and process_sigs() */ bool stdin_is_ptys = GetStdHandle (STD_INPUT_HANDLE) == get_handle (); setup_for_non_cygwin_app (false, NULL, stdin_is_ptys); } @@ -1109,6 +1109,7 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void) { CloseHandle (h_gdb_inferior); h_gdb_inferior = NULL; + myself->wpid_debuggee_maybe = 0; mutex_timeout = INFINITE; if (isHybrid) { @@ -1137,6 +1138,8 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void) else hand_over_only (get_ttyp ()); ReleaseMutex (pipe_sw_mutex); + + HANDLE input_handle_nat, output_handle_nat; if (need_restore_handles) { pinfo p (get_ttyp ()->master_pid); @@ -1144,16 +1147,15 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void) OpenProcess (PROCESS_DUP_HANDLE, FALSE, p->dwProcessId); if (pty_owner) { - CloseHandle (get_handle_nat ()); DuplicateHandle (pty_owner, get_ttyp ()->from_master_nat (), - GetCurrentProcess (), &get_handle_nat (), + GetCurrentProcess (), + &input_handle_nat, 0, TRUE, DUPLICATE_SAME_ACCESS); - CloseHandle (get_output_handle_nat ()); DuplicateHandle (pty_owner, get_ttyp ()->to_master_nat (), GetCurrentProcess (), - &get_output_handle_nat (), + &output_handle_nat, 0, TRUE, DUPLICATE_SAME_ACCESS); CloseHandle (pty_owner); } @@ -1177,11 +1179,12 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void) CloseHandle (repl.to_master); /* not used. */ CloseHandle (repl.to_slave_nat); /* not used. */ CloseHandle (repl.to_slave); /* not used. */ - CloseHandle (get_handle_nat ()); - set_handle_nat (repl.from_master_nat); - CloseHandle (get_output_handle_nat ()); - set_output_handle_nat (repl.to_master_nat); + input_handle_nat = repl.from_master_nat; + output_handle_nat = repl.to_master_nat; } + + /* Restore nat handles in all pty slave instances */ + replace_nat_handles (input_handle_nat, output_handle_nat); } myself->exec_dwProcessId = 0; isHybrid = false; @@ -2183,6 +2186,8 @@ fhandler_pty_master::close (int flag) ssize_t fhandler_pty_master::write (const void *ptr, size_t len) { + size_t orig_len = len; + ssize_t ret; char *p = (char *) ptr; termios &ti = tc ()->ti; @@ -2193,6 +2198,8 @@ fhandler_pty_master::write (const void *ptr, size_t len) push_process_state process_state (PID_TTYOU); + get_ttyp ()->discard_input = false; + if (get_ttyp ()->pcon_start) { /* Reaches here when pseudo console initialization is on going. */ /* Pseudo condole support uses "CSI6n" to get cursor position. @@ -2203,10 +2210,12 @@ fhandler_pty_master::write (const void *ptr, size_t len) static char wpbuf[wpbuf_len]; static int ixput = 0; static int state = 0; + static DWORD wp_tid = 0; DWORD n; WaitForSingleObject (input_mutex, mutex_timeout); - for (size_t i = 0; i < len; i++) + len = 0; + for (size_t i = 0; i < orig_len; i++) { if (p[i] == '\033') { @@ -2214,8 +2223,9 @@ fhandler_pty_master::write (const void *ptr, size_t len) line_edit (wpbuf, ixput, ti, &ret); ixput = 0; state = 1; + wp_tid = _my_tls.thread_id; } - if (state == 1) + if (state == 1 && wp_tid == _my_tls.thread_id) { if (ixput < wpbuf_len) wpbuf[ixput++] = p[i]; @@ -2229,20 +2239,24 @@ fhandler_pty_master::write (const void *ptr, size_t len) } else line_edit (p + i, 1, ti, &ret); - if (state == 1 && p[i] == 'R') + len = orig_len - i - 1; + ptr = p + i + 1; + if (state == 1 && wp_tid == _my_tls.thread_id && p[i] == 'R') state = 2; - } - if (state == 2) - { - /* req_xfer_input is true if "ESC[6n" was sent just for - triggering transfer_input() in master. In this case, - the responce sequence should not be written. */ - if (!get_ttyp ()->req_xfer_input) - WriteFile (to_slave_nat, wpbuf, ixput, &n, NULL); - ixput = 0; - state = 0; - get_ttyp ()->req_xfer_input = false; - get_ttyp ()->pcon_start = false; + if (state == 2) + { + /* req_xfer_input is true if "ESC[6n" was sent just for + triggering transfer_input() in master. In this case, + the response sequence should not be written. */ + if (!get_ttyp ()->req_xfer_input) + WriteFile (to_slave_nat, wpbuf, ixput, &n, NULL); + ixput = 0; + state = 0; + wp_tid = 0; + get_ttyp ()->req_xfer_input = false; + get_ttyp ()->pcon_start = false; + break; + } } ReleaseMutex (input_mutex); @@ -2250,6 +2264,7 @@ fhandler_pty_master::write (const void *ptr, size_t len) { /* Pseudo console initialization has been done in above code. */ pinfo pp (get_ttyp ()->pcon_start_pid); if (get_ttyp ()->switch_to_nat_pipe + && pp && pp->pgid == get_ttyp ()->getpgid () && get_ttyp ()->pty_input_state_eq (tty::to_cyg)) { /* This accept_input() call is needed in order to transfer input @@ -2267,8 +2282,8 @@ fhandler_pty_master::write (const void *ptr, size_t len) } get_ttyp ()->pcon_start_pid = 0; } - - return len; + if (len == 0) + return orig_len; } /* Write terminal input to to_slave_nat pipe instead of output_handle @@ -2353,10 +2368,11 @@ fhandler_pty_master::write (const void *ptr, size_t len) } DWORD n; - WriteFile (to_slave_nat, buf, nlen, &n, NULL); + if (nlen) + WriteFile (to_slave_nat, buf, nlen, &n, NULL); ReleaseMutex (input_mutex); - return len; + return orig_len; } /* The code path reaches here when pseudo console is not activated @@ -2380,8 +2396,8 @@ fhandler_pty_master::write (const void *ptr, size_t len) ReleaseMutex (input_mutex); if (status > line_edit_signalled && status != line_edit_pipe_full) - ret = -1; - return ret; + return -1; + return orig_len - len + ret; } void @@ -2885,6 +2901,39 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p) else state = 0; + /* Remove CSI ? 9001 h/l (win32-input-mode) */ + /* Remove CSI ? 1004 h/l (focus report) */ + int arg = 0; + state = 0; + for (DWORD i = 0; i < rlen; i++) + if (outbuf[i] == '\033') + { + start_at = i; + state = 1; + continue; + } + else if ((state == 1 && outbuf[i] == '[') + || (state == 2 && outbuf[i] == '?')) + { + state ++; + continue; + } + else if (state == 3 && isdigit (outbuf[i])) + arg = arg * 10 + (outbuf[i] - '0'); + else if (state == 3 && outbuf[i] == ';') + arg = 0; + else if (state == 3 && (arg == 9001 || arg == 1004) + && (outbuf[i] == 'h' || outbuf[i] == 'l')) + { + memmove (&outbuf[start_at], &outbuf[i+1], rlen-i-1); + rlen = wlen = start_at + rlen - i - 1; + state = 0; + i = start_at - 1; + continue; + } + else + state = 0; + /* Remove OSC Ps ; ? BEL/ST */ state = 0; for (DWORD i = 0; i < rlen; i++) @@ -3504,7 +3553,7 @@ fhandler_pty_slave::setup_pseudoconsole () PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, hpcon, sizeof (hpcon), NULL, NULL)) - goto cleanup_heap; + goto cleanup_proc_thread_attr; hello = CreateEvent (&sec_none, true, false, NULL); goodbye = CreateEvent (&sec_none, true, false, NULL); @@ -3595,26 +3644,8 @@ fhandler_pty_slave::setup_pseudoconsole () while (false); skip_create: - do - { - /* Fixup handles */ - HANDLE orig_input_handle_nat = get_handle_nat (); - HANDLE orig_output_handle_nat = get_output_handle_nat (); - cygheap_fdenum cfd (false); - while (cfd.next () >= 0) - if (cfd->get_device () == get_device ()) - { - fhandler_base *fh = cfd; - fhandler_pty_slave *ptys = (fhandler_pty_slave *) fh; - if (ptys->get_handle_nat () == orig_input_handle_nat) - ptys->set_handle_nat (hpConIn); - if (ptys->get_output_handle_nat () == orig_output_handle_nat) - ptys->set_output_handle_nat (hpConOut); - } - CloseHandle (orig_input_handle_nat); - CloseHandle (orig_output_handle_nat); - } - while (false); + /* Fixup handles in all PTY-slave instances */ + replace_nat_handles (hpConIn, hpConOut); if (!process_alive (get_ttyp ()->nat_pipe_owner_pid)) get_ttyp ()->nat_pipe_owner_pid = myself->exec_dwProcessId; @@ -3691,6 +3722,8 @@ fhandler_pty_slave::setup_pseudoconsole () CloseHandle (goodbye); CloseHandle (hr); CloseHandle (hw); +cleanup_proc_thread_attr: + DeleteProcThreadAttributeList (si.lpAttributeList); cleanup_heap: HeapFree (GetProcessHeap (), 0, si.lpAttributeList); cleanup_pseudo_console: @@ -4453,3 +4486,31 @@ fhandler_pty_common::resume_from_temporarily_attach (DWORD resume_pid) } release_attach_mutex (); } + +void +fhandler_pty_slave::replace_nat_handles (HANDLE new_input, HANDLE new_output) +{ + HANDLE orig_input_handle_nat = get_handle_nat(); + HANDLE orig_output_handle_nat = get_output_handle_nat(); + cygheap_fdenum cfd (false); + while (cfd.next () >= 0) + if (cfd->get_device () == get_device ()) + { + fhandler_base *fh = cfd; + fhandler_pty_slave *ptys = (fhandler_pty_slave *) fh; + if (ptys->get_handle_nat () == orig_input_handle_nat) + ptys->set_handle_nat (new_input); + if (ptys->get_output_handle_nat () == orig_output_handle_nat) + ptys->set_output_handle_nat (new_output); + } + if (cygheap->ctty->get_device () == get_device ()) + { + fhandler_pty_slave *ptys = (fhandler_pty_slave *) cygheap->ctty; + if (ptys->get_handle_nat () == orig_input_handle_nat) + ptys->set_handle_nat (new_input); + if (ptys->get_output_handle_nat () == orig_output_handle_nat) + ptys->set_output_handle_nat (new_output); + } + CloseHandle (orig_input_handle_nat); + CloseHandle (orig_output_handle_nat); +} diff --git a/winsup/cygwin/fhandler/termios.cc b/winsup/cygwin/fhandler/termios.cc index 01d00daed5..e2822c3ee9 100644 --- a/winsup/cygwin/fhandler/termios.cc +++ b/winsup/cygwin/fhandler/termios.cc @@ -338,19 +338,9 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh) for (unsigned i = 0; i < pids.npids; i++) { _pinfo *p = pids[i]; - /* PID_NOTCYGWIN: check this for non-cygwin process. - exec_dwProcessId == dwProcessId: - check this for GDB with non-cygwin inferior in pty - without pcon enabled. In this case, the inferior is not - cygwin process list. This condition is set true as - a marker for GDB with non-cygwin inferior in pty code. - !PID_CYGPARENT: check this for GDB with cygwin inferior or - cygwin apps started from non-cygwin shell. */ - if (c == '\003' && p && p->ctty == ttyp->ntty && p->pgid == pgid - && ((p->process_state & PID_NOTCYGWIN) - || ((p->exec_dwProcessId == p->dwProcessId) - && ttyp->pty_input_state_eq (tty::to_nat)) - || !(p->process_state & PID_CYGPARENT))) + if (c == '\003' && p && p->ctty == ttyp->ntty + && (p->is_foreground_special_process (pgid) + || p->is_gdb_with_foreground_non_cygwin_inferior (pgid))) { /* Ctrl-C event will be sent only to the processes attaching to the same console. Therefore, attach to the console to @@ -372,7 +362,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh) if (p->process_state & PID_NEW_PG) GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, p->dwProcessId); else if ((!fh || fh->need_send_ctrl_c_event () - || p->exec_dwProcessId == p->dwProcessId) + || p->is_gdb_with_foreground_non_cygwin_inferior (pgid)) && !ctrl_c_event_sent) { GenerateConsoleCtrlEvent (CTRL_C_EVENT, 0); @@ -390,24 +380,23 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh) } need_discard_input = true; } - if (p && p->ctty == ttyp->ntty && p->pgid == pgid) + if (p && p->ctty == ttyp->ntty) { - if (p->process_state & PID_NOTCYGWIN) - pg_with_nat = true; /* The process group has non-cygwin process */ - if (!(p->process_state & PID_NOTCYGWIN)) - need_send_sig = true; /* Process which needs signal exists */ - if (!p->cygstarted) - nat_shell = true; /* The shell seems to a non-cygwin shell */ - if (p->process_state & PID_TTYIN) - cyg_reader = true; /* Theh process is reading the tty */ - if (!p->cygstarted && !(p->process_state & PID_NOTCYGWIN) - && (p->process_state & PID_DEBUGGED)) - with_debugger = true; /* inferior is cygwin app */ - if (!(p->process_state & PID_NOTCYGWIN) - && (p->exec_dwProcessId == p->dwProcessId) /* Check marker */ - && ttyp->pty_input_state_eq (tty::to_nat) - && p->pid == pgid) - with_debugger_nat = true; /* inferior is non-cygwin app */ + if (p->pgid == pgid) + { + if (p->process_state & PID_NOTCYGWIN) + pg_with_nat = true; /* The process group has non-cygwin app */ + if (!(p->process_state & PID_NOTCYGWIN)) + need_send_sig = true; /* Process which needs signal exists */ + if (!p->cygstarted) + nat_shell = true; /* The shell seems to a non-cygwin shell */ + if (p->process_state & PID_TTYIN) + cyg_reader = true; /* Theh process is reading the tty */ + if (p->is_cygwin_inferior_being_debugged ()) + with_debugger = true; + } + if (p->is_gdb_with_foreground_non_cygwin_inferior (pgid)) + with_debugger_nat = true; } } if ((with_debugger || with_debugger_nat) && need_discard_input) @@ -536,10 +525,9 @@ fhandler_termios::line_edit (const char *rptr, size_t nread, termios& ti, switch (process_sigs (c, get_ttyp (), this)) { case signalled: - sawsig = true; - fallthrough; case not_signalled_but_done: case done_with_debugger: + sawsig = true; get_ttyp ()->output_stopped = false; continue; case not_signalled_with_nat_reader: diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index 9e20cbaf3b..4d41d6f4b0 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -11,7 +11,7 @@ details. */ changes to the DLL and is mainly informative in nature. */ #define CYGWIN_VERSION_DLL_MAJOR 3006 -#define CYGWIN_VERSION_DLL_MINOR 7 +#define CYGWIN_VERSION_DLL_MINOR 9 /* CYGWIN_VERSION_DLL_COMBINED gives us a single number representing the combined DLL major and minor numbers. */ diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h index 95423ed0c0..09e04c14f4 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -2526,6 +2526,7 @@ class fhandler_pty_slave: public fhandler_pty_common DWORD force_switch_to = 0); void setpgid_aux (pid_t pid); static void release_ownership_of_nat_pipe (tty *ttyp, fhandler_termios *fh); + void replace_nat_handles (HANDLE new_input, HANDLE new_output); }; #define __ptsname(buf, unit) __small_sprintf ((buf), "/dev/pty%d", (unit)) diff --git a/winsup/cygwin/local_includes/pinfo.h b/winsup/cygwin/local_includes/pinfo.h index d1c9b001b4..6f817de6bb 100644 --- a/winsup/cygwin/local_includes/pinfo.h +++ b/winsup/cygwin/local_includes/pinfo.h @@ -46,6 +46,9 @@ enum picom class fhandler_pipe; +pid_t create_cygwin_pid (); +pid_t cygwin_pid (DWORD); + class _pinfo { public: @@ -126,10 +129,46 @@ class _pinfo bool exists (); const char *_ctty (char *); + /* "Special" here means a non-cygwin process or a process whose parent + is not a cygwin process */ + inline bool is_foreground_special_process (pid_t tty_pgid) + { + if (pgid != tty_pgid) /* The process is background */ + return false; + if (!(process_state & PID_CYGPARENT)) + return true; + return !!(process_state & PID_NOTCYGWIN); + } + inline bool is_foreground_non_cygwin_process (pid_t tty_pgid) + { + if (pgid != tty_pgid) + return false; + return !!(process_state & PID_NOTCYGWIN); + } + inline bool is_gdb_with_foreground_non_cygwin_inferior (pid_t tty_pgid) + { + if (pgid == tty_pgid) /* GDB is the foreground process */ + return false; + if (wpid_debuggee_maybe == 0) + return false; + /* Below is true for GDB with non-cygwin inferior */ + return !cygwin_pid (wpid_debuggee_maybe); + } + inline bool is_cygwin_inferior_being_debugged () + { + if (cygstarted) + return false; + if (process_state & PID_NOTCYGWIN) + return false; + return !!(process_state & PID_DEBUGGED); + } + /* signals */ HANDLE sendsig; HANDLE exec_sendsig; DWORD exec_dwProcessId; + + DWORD wpid_debuggee_maybe; public: friend class pinfo_minimal; }; @@ -254,9 +293,6 @@ class winpids void release (); }; -pid_t create_cygwin_pid (); -pid_t cygwin_pid (DWORD); - void pinfo_init (char **, int); extern pinfo myself; diff --git a/winsup/cygwin/release/3.6.8 b/winsup/cygwin/release/3.6.8 new file mode 100644 index 0000000000..5199ad86ba --- /dev/null +++ b/winsup/cygwin/release/3.6.8 @@ -0,0 +1,28 @@ +Fixes: +------ + +- Fix conhost.exe crash in pseudo console. + +- Drop CSI?9001h (win32-input-mode) sequence from pseudo console + output so that Ctrl-C correctly works. + +- Fix the problem that Ctrl-C does not work for foregrounded + 'cat | sleep 100 &' command in tcsh. + +- Fix the problem that Ctrl-C does not work for foregrounded + 'cat | cmd &' command. + +- Drop CSI?1004h (enable focus event report) sequence from pseudo + console output so that CSI I/O are not sent to the foreground + process. + +- Fix inheriting typeahead input after Ctrl-C. + +- Apply 7 separate patches that fix out-of-order key input. + Addresses: https://github.com/git-for-windows/git/issues/5632 + +- Fix pty bugs regarding GDB with pty. + +- Add missing errno setting on error that poll() is called for closed + file descriptor. + Addresses: https://cygwin.com/pipermail/cygwin/2026-April/259602.html diff --git a/winsup/cygwin/scripts/gendef b/winsup/cygwin/scripts/gendef index 861a2405b2..6328fe2fbd 100755 --- a/winsup/cygwin/scripts/gendef +++ b/winsup/cygwin/scripts/gendef @@ -233,6 +233,8 @@ sigdelayed: xorl %ecx,%ecx cpuid # get necessary space for xsave movq %rbx,%rcx + addq \$63, %rbx + andq \$-64, %rbx # align to next 64-byte multiple addq \$0x48,%rbx # 0x18 for alignment, 0x30 for additional space subq %rbx,%rsp movl %ebx,0x24(%rsp) diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 8a94ac0761..523c46ee64 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -561,7 +561,10 @@ select_stuff::poll (fd_set *readfds, fd_set *writefds, fd_set *exceptfds) { int ret = s->peek ? s->peek (s, true) : 1; if (ret < 0) - return -1; + { + set_errno (s->thread_errno); + return -1; + } n += (ret > 0) ? set_bits (s, readfds, writefds, exceptfds) : 0; } return n; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 5caf97e7a6..dda1a71da9 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -646,8 +646,12 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) { HANDLE dupsig; DWORD dwProcessId; - for (int i = 0; !p->sendsig && i < 10000; i++) - yield (); + if (!ISSTATE (p, PID_NOTCYGWIN)) + { + DWORD t0 = GetTickCount (); + while (GetTickCount () - t0 < 100 && !p->sendsig) + yield (); + } if (p->sendsig) { dupsig = p->sendsig; diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index b3f17a1302..9408903659 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -907,7 +907,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, if (term_spawn_worker.need_cleanup ()) { LONG prev_sigExeced = sigExeced; - while (WaitForSingleObject (pi.hProcess, 100) == WAIT_TIMEOUT) + while (cygwait (pi.hProcess, 100) != WAIT_OBJECT_0) /* If child process does not exit in predetermined time period, the process does not seem to be terminated by the signal sigExeced. Therefore, clear sigExeced here. */ diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index 0c49dc2bdf..c8730e81c5 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -340,10 +340,9 @@ tty::nat_fg (pid_t pgid) for (unsigned i = 0; i < pids.npids; i++) { _pinfo *p = pids[i]; - if (p->ctty == ntty && p->pgid == pgid - && ((p->process_state & PID_NOTCYGWIN) - /* Below is true for GDB with non-cygwin inferior */ - || p->exec_dwProcessId == p->dwProcessId)) + if (p->ctty == ntty + && (p->is_foreground_non_cygwin_process (pgid) + || p->is_gdb_with_foreground_non_cygwin_inferior (pgid))) return true; } if (pgid > MAX_PID)