mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-15 13:39:26 +08:00
Cygwin: console: Use GetCurrentProcessId() instead of myself->dwProcessId
The commit 90ddab98780d uses myself->dwProcessId to get windows pid. However, it will be overridden in stub process if exec() is called. With this patch, GetCurrentProcessId() instead of myself->dwProcessId. Fixes: 90ddab98780d ("Cygwin: console: Re-fix open() failure on exec() by console owner") Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> (cherry picked from commit 8ee8b0c974d723d618182fbbdeb1e9186b69c6f3)
This commit is contained in:
parent
f307544150
commit
92f4e103d1
@ -85,7 +85,7 @@ fhandler_console::attach_console (DWORD owner, bool *err)
|
|||||||
if (!attached)
|
if (!attached)
|
||||||
{
|
{
|
||||||
resume_pid =
|
resume_pid =
|
||||||
get_console_process_id (myself->dwProcessId, false, false, false);
|
get_console_process_id (GetCurrentProcessId (), false, false, false);
|
||||||
FreeConsole ();
|
FreeConsole ();
|
||||||
BOOL r = AttachConsole (owner);
|
BOOL r = AttachConsole (owner);
|
||||||
if (!r)
|
if (!r)
|
||||||
@ -110,7 +110,7 @@ fhandler_console::detach_console (DWORD resume_pid, DWORD owner)
|
|||||||
FreeConsole ();
|
FreeConsole ();
|
||||||
AttachConsole (resume_pid);
|
AttachConsole (resume_pid);
|
||||||
}
|
}
|
||||||
else if (myself->dwProcessId != owner)
|
else if (GetCurrentProcessId () != owner)
|
||||||
FreeConsole ();
|
FreeConsole ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
termios &ti = ttyp->ti;
|
termios &ti = ttyp->ti;
|
||||||
while (con.owner == myself->dwProcessId)
|
while (con.owner == GetCurrentProcessId ())
|
||||||
{
|
{
|
||||||
DWORD total_read, n, i;
|
DWORD total_read, n, i;
|
||||||
|
|
||||||
@ -709,7 +709,7 @@ fhandler_console::set_unit ()
|
|||||||
unit = device::minor (cs->tty_min_state.ntty);
|
unit = device::minor (cs->tty_min_state.ntty);
|
||||||
shared_console_info[unit] = cs;
|
shared_console_info[unit] = cs;
|
||||||
if (created)
|
if (created)
|
||||||
con.owner = myself->dwProcessId;
|
con.owner = GetCurrentProcessId ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -917,10 +917,10 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_set_t *p)
|
|||||||
/* conmode can be tty::restore when non-cygwin app is
|
/* conmode can be tty::restore when non-cygwin app is
|
||||||
exec'ed from login shell. */
|
exec'ed from login shell. */
|
||||||
tty::cons_mode conmode =
|
tty::cons_mode conmode =
|
||||||
(con.owner == myself->dwProcessId) ? tty::restore : tty::cygwin;
|
(con.owner == GetCurrentProcessId ()) ? tty::restore : tty::cygwin;
|
||||||
set_output_mode (conmode, ti, p);
|
set_output_mode (conmode, ti, p);
|
||||||
set_input_mode (conmode, ti, p);
|
set_input_mode (conmode, ti, p);
|
||||||
set_disable_master_thread (con.owner == myself->dwProcessId);
|
set_disable_master_thread (con.owner == GetCurrentProcessId ());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the tty structure associated with a given tty number. If the
|
/* Return the tty structure associated with a given tty number. If the
|
||||||
@ -1774,7 +1774,7 @@ fhandler_console::open (int flags, mode_t)
|
|||||||
acquire_output_mutex (mutex_timeout);
|
acquire_output_mutex (mutex_timeout);
|
||||||
|
|
||||||
if (!process_alive (con.owner))
|
if (!process_alive (con.owner))
|
||||||
con.owner = myself->dwProcessId;
|
con.owner = GetCurrentProcessId ();
|
||||||
|
|
||||||
/* Open the input handle as handle_ */
|
/* Open the input handle as handle_ */
|
||||||
bool err = false;
|
bool err = false;
|
||||||
@ -1838,7 +1838,7 @@ fhandler_console::open (int flags, mode_t)
|
|||||||
|
|
||||||
set_open_status ();
|
set_open_status ();
|
||||||
|
|
||||||
if (myself->dwProcessId == con.owner && wincap.has_con_24bit_colors ())
|
if (GetCurrentProcessId () == con.owner && wincap.has_con_24bit_colors ())
|
||||||
{
|
{
|
||||||
bool is_legacy = false;
|
bool is_legacy = false;
|
||||||
DWORD dwMode;
|
DWORD dwMode;
|
||||||
@ -1869,7 +1869,7 @@ fhandler_console::open (int flags, mode_t)
|
|||||||
debug_printf ("opened conin$ %p, conout$ %p", get_handle (),
|
debug_printf ("opened conin$ %p, conout$ %p", get_handle (),
|
||||||
get_output_handle ());
|
get_output_handle ());
|
||||||
|
|
||||||
if (myself->dwProcessId == con.owner)
|
if (GetCurrentProcessId () == con.owner)
|
||||||
{
|
{
|
||||||
if (GetModuleHandle ("ConEmuHk64.dll"))
|
if (GetModuleHandle ("ConEmuHk64.dll"))
|
||||||
hook_conemu_cygwin_connector ();
|
hook_conemu_cygwin_connector ();
|
||||||
@ -1983,9 +1983,9 @@ fhandler_console::close ()
|
|||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
status = NtQueryObject (get_handle (), ObjectBasicInformation,
|
status = NtQueryObject (get_handle (), ObjectBasicInformation,
|
||||||
&obi, sizeof obi, NULL);
|
&obi, sizeof obi, NULL);
|
||||||
if ((NT_SUCCESS (status) && obi.HandleCount == 1
|
if (NT_SUCCESS (status)
|
||||||
|
&& obi.HandleCount <= (myself->cygstarted ? 2 : 3)
|
||||||
&& (dev_t) myself->ctty == get_device ())
|
&& (dev_t) myself->ctty == get_device ())
|
||||||
|| myself->dwProcessId == con.owner)
|
|
||||||
{
|
{
|
||||||
/* Cleaning-up console mode for cygwin apps. */
|
/* Cleaning-up console mode for cygwin apps. */
|
||||||
set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
|
set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
|
||||||
@ -1994,7 +1994,7 @@ fhandler_console::close ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shared_console_info[unit] && con.owner == myself->dwProcessId)
|
if (shared_console_info[unit] && con.owner == GetCurrentProcessId ())
|
||||||
{
|
{
|
||||||
if (master_thread_started)
|
if (master_thread_started)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user