Try fixing sending intr to subprocess + fix indent
This commit is contained in:
parent
cba9536779
commit
cabdb0fc94
@ -299,6 +299,58 @@ public:
|
||||
bool tooBig();
|
||||
};
|
||||
|
||||
// Sending a break to a subprocess is only possible if we share the
|
||||
// same console We temporarily ignore breaks, attach to the Console,
|
||||
// send the break, and restore normal break processing
|
||||
static bool sendIntr(int pid)
|
||||
{
|
||||
LOGDEB(("execmd_w: sendIntr -> %d\n", pid));
|
||||
bool needDetach = false;
|
||||
if (GetConsoleWindow() == NULL) {
|
||||
needDetach = true;
|
||||
LOGDEB(("execmd_w: sendIntr attaching console\n"));
|
||||
if (!AttachConsole((unsigned int) pid)) {
|
||||
int err = GetLastError();
|
||||
LOGERR(("execmd_w: sendIntr: AttachConsole failed: %d\n", err));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Would need to do this for sending to all processes on this console
|
||||
// Disable Ctrl-C handling for our program
|
||||
if (!SetConsoleCtrlHandler(NULL, true)) {
|
||||
int err = GetLastError();
|
||||
LOGERR(("execmd_w:sendIntr:SetCons.Ctl.Hndlr.(NULL, true) failed: %d\n",
|
||||
err));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Note: things don't work with CTRL_C (process not advised, sometimes
|
||||
// stays apparently blocked), no idea why
|
||||
bool ret = GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid);
|
||||
if (!ret) {
|
||||
int err = GetLastError();
|
||||
LOGERR(("execmd_w:sendIntr:Gen.Cons.CtrlEvent failed: %d\n", err));
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Restore Ctrl-C handling for our program
|
||||
SetConsoleCtrlHandler(NULL, false);
|
||||
#endif
|
||||
|
||||
if (needDetach) {
|
||||
LOGDEB(("execmd_w: sendIntr detaching console\n"));
|
||||
if (!FreeConsole()) {
|
||||
int err = GetLastError();
|
||||
LOGERR(("execmd_w: sendIntr: FreeConsole failed: %d\n", err));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ExecCmd resource releaser class. Using a separate object makes it
|
||||
// easier that resources are released under all circumstances,
|
||||
// esp. exceptions
|
||||
@ -324,12 +376,7 @@ public:
|
||||
CloseHandle(m_parent->m_oInputWrite.hEvent);
|
||||
|
||||
if (m_parent->m_piProcInfo.hProcess) {
|
||||
LOGDEB(("ExecCmd: GenerateConsoleCtrlEvent -> %d\n",
|
||||
m_parent->m_piProcInfo.dwProcessId));
|
||||
|
||||
BOOL bSuccess =
|
||||
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
|
||||
m_parent->m_piProcInfo.dwProcessId);
|
||||
BOOL bSuccess = sendIntr(m_parent->m_piProcInfo.dwProcessId);
|
||||
if (bSuccess) {
|
||||
// Give it a chance, then terminate
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@ -457,10 +504,7 @@ void ExecCmd::zapChild()
|
||||
bool ExecCmd::requestChildExit()
|
||||
{
|
||||
if (m->m_piProcInfo.hProcess) {
|
||||
LOGDEB(("ExecCmd: GenerateConsoleCtrlEvent -> %d\n",
|
||||
m->m_piProcInfo.dwProcessId));
|
||||
return GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
|
||||
m->m_piProcInfo.dwProcessId);
|
||||
return sendIntr(m->m_piProcInfo.dwProcessId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user