Skip to content

Commit bb4e8e0

Browse files
committed
Merge branch 'msys2/msys2-3.6.1'
There are now two mildly important bug fixes that I also want to be in Git for Windows. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 754b26f + 0cfedd4 commit bb4e8e0

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

winsup/cygwin/fhandler/console.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_set_t *p)
932932
/* Cleaning-up console mode for non-cygwin app. */
933933
/* conmode can be tty::restore when non-cygwin app is
934934
exec'ed from login shell. */
935-
tty::cons_mode conmode = cons_mode_on_close ();
935+
tty::cons_mode conmode = cons_mode_on_close (p);
936936
set_output_mode (conmode, ti, p);
937937
set_input_mode (conmode, ti, p);
938938
set_disable_master_thread (con.owner == GetCurrentProcessId ());
@@ -1991,8 +1991,9 @@ fhandler_console::close (int flag)
19911991

19921992
acquire_output_mutex (mutex_timeout);
19931993

1994-
if (shared_console_info[unit] && myself->ppid == 1
1995-
&& (dev_t) myself->ctty == get_device ())
1994+
if (shared_console_info[unit] && con.curr_input_mode != tty::restore
1995+
&& (dev_t) myself->ctty == get_device ()
1996+
&& cons_mode_on_close (&handle_set) == tty::restore)
19961997
{
19971998
set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
19981999
set_input_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
@@ -4704,10 +4705,25 @@ fhandler_console::fstat (struct stat *st)
47044705
}
47054706

47064707
tty::cons_mode
4707-
fhandler_console::cons_mode_on_close ()
4708+
fhandler_console::cons_mode_on_close (handle_set_t *p)
47084709
{
4710+
int unit = p->unit;
47094711
if (myself->ppid != 1) /* Execed from normal cygwin process. */
47104712
return tty::cygwin;
47114713

4714+
if (!process_alive (con.owner)) /* The Master process already died. */
4715+
return tty::restore;
4716+
if (con.owner == GetCurrentProcessId ()) /* Master process */
4717+
return tty::restore;
4718+
4719+
PROCESS_BASIC_INFORMATION pbi;
4720+
NTSTATUS status =
4721+
NtQueryInformationProcess (GetCurrentProcess (), ProcessBasicInformation,
4722+
&pbi, sizeof (pbi), NULL);
4723+
if (NT_SUCCESS (status)
4724+
&& !process_alive ((DWORD) pbi.InheritedFromUniqueProcessId))
4725+
/* Execed from normal cygwin process and the parent has been exited. */
4726+
return tty::cygwin;
4727+
47124728
return tty::restore; /* otherwise, restore */
47134729
}

winsup/cygwin/local_includes/fhandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ class fhandler_console: public fhandler_termios
23682368

23692369
void setup_pcon_hand_over ();
23702370
static void pcon_hand_over_proc ();
2371-
static tty::cons_mode cons_mode_on_close ();
2371+
static tty::cons_mode cons_mode_on_close (handle_set_t *);
23722372

23732373
friend tty_min * tty_list::get_cttyp ();
23742374
};

winsup/cygwin/path.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,9 @@ recursiveCopy (PUNICODE_STRING src, PUNICODE_STRING dst, USHORT origsrclen,
18561856
/* Recurse into the child directory */
18571857
/* avoids endless recursion */
18581858
if (src->Length <= origsrclen ||
1859-
!wcsncmp (src->Buffer, dst->Buffer, origdstlen / sizeof (WCHAR)))
1859+
(!wcsncmp (src->Buffer, dst->Buffer, origdstlen / sizeof (WCHAR)) &&
1860+
(!src->Buffer[origdstlen / sizeof (WCHAR)] ||
1861+
iswdirsep(src->Buffer[origdstlen / sizeof (WCHAR)]))))
18601862
{
18611863
set_errno (ELOOP);
18621864
goto done;

0 commit comments

Comments
 (0)