@@ -85,7 +85,7 @@ fhandler_console::attach_console (DWORD owner, bool *err)
8585 if (!attached)
8686 {
8787 resume_pid =
88- get_console_process_id (myself-> dwProcessId , false , false , false );
88+ get_console_process_id (GetCurrentProcessId () , false , false , false );
8989 FreeConsole ();
9090 BOOL r = AttachConsole (owner);
9191 if (!r)
@@ -110,7 +110,7 @@ fhandler_console::detach_console (DWORD resume_pid, DWORD owner)
110110 FreeConsole ();
111111 AttachConsole (resume_pid);
112112 }
113- else if (myself-> dwProcessId != owner)
113+ else if (GetCurrentProcessId () != owner)
114114 FreeConsole ();
115115}
116116
@@ -395,7 +395,7 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
395395 }
396396 };
397397 termios &ti = ttyp->ti ;
398- while (con.owner == myself-> dwProcessId )
398+ while (con.owner == GetCurrentProcessId () )
399399 {
400400 DWORD total_read, n, i;
401401
@@ -709,7 +709,7 @@ fhandler_console::set_unit ()
709709 unit = device::minor (cs->tty_min_state .ntty );
710710 shared_console_info[unit] = cs;
711711 if (created)
712- con.owner = myself-> dwProcessId ;
712+ con.owner = GetCurrentProcessId () ;
713713 }
714714 }
715715 }
@@ -917,10 +917,10 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_set_t *p)
917917 /* conmode can be tty::restore when non-cygwin app is
918918 exec'ed from login shell. */
919919 tty::cons_mode conmode =
920- (con.owner == myself-> dwProcessId ) ? tty::restore : tty::cygwin;
920+ (con.owner == GetCurrentProcessId () ) ? tty::restore : tty::cygwin;
921921 set_output_mode (conmode, ti, p);
922922 set_input_mode (conmode, ti, p);
923- set_disable_master_thread (con.owner == myself-> dwProcessId );
923+ set_disable_master_thread (con.owner == GetCurrentProcessId () );
924924}
925925
926926/* Return the tty structure associated with a given tty number. If the
@@ -1774,7 +1774,7 @@ fhandler_console::open (int flags, mode_t)
17741774 acquire_output_mutex (mutex_timeout);
17751775
17761776 if (!process_alive (con.owner ))
1777- con.owner = myself-> dwProcessId ;
1777+ con.owner = GetCurrentProcessId () ;
17781778
17791779 /* Open the input handle as handle_ */
17801780 bool err = false ;
@@ -1838,7 +1838,7 @@ fhandler_console::open (int flags, mode_t)
18381838
18391839 set_open_status ();
18401840
1841- if (myself-> dwProcessId == con.owner && wincap.has_con_24bit_colors ())
1841+ if (GetCurrentProcessId () == con.owner && wincap.has_con_24bit_colors ())
18421842 {
18431843 bool is_legacy = false ;
18441844 DWORD dwMode;
@@ -1869,7 +1869,7 @@ fhandler_console::open (int flags, mode_t)
18691869 debug_printf (" opened conin$ %p, conout$ %p" , get_handle (),
18701870 get_output_handle ());
18711871
1872- if (myself-> dwProcessId == con.owner )
1872+ if (GetCurrentProcessId () == con.owner )
18731873 {
18741874 if (GetModuleHandle (" ConEmuHk64.dll" ))
18751875 hook_conemu_cygwin_connector ();
@@ -1983,9 +1983,9 @@ fhandler_console::close ()
19831983 NTSTATUS status;
19841984 status = NtQueryObject (get_handle (), ObjectBasicInformation,
19851985 &obi, sizeof obi, NULL );
1986- if (( NT_SUCCESS (status) && obi. HandleCount == 1
1987- && ( dev_t ) myself->ctty == get_device () )
1988- || myself->dwProcessId == con. owner )
1986+ if (NT_SUCCESS (status)
1987+ && obi. HandleCount <= ( myself->cygstarted ? 2 : 3 )
1988+ && ( dev_t ) myself->ctty == get_device () )
19891989 {
19901990 /* Cleaning-up console mode for cygwin apps. */
19911991 set_output_mode (tty::restore, &get_ttyp ()->ti , &handle_set);
@@ -1994,7 +1994,7 @@ fhandler_console::close ()
19941994 }
19951995 }
19961996
1997- if (shared_console_info[unit] && con.owner == myself-> dwProcessId )
1997+ if (shared_console_info[unit] && con.owner == GetCurrentProcessId () )
19981998 {
19991999 if (master_thread_started)
20002000 {
0 commit comments