Try fixing sending intr to subprocess + fix indent

This commit is contained in:
Jean-Francois Dockes 2015-10-31 15:55:13 +01:00
parent cba9536779
commit cabdb0fc94

View File

@ -299,6 +299,58 @@ public:
bool tooBig(); 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 // ExecCmd resource releaser class. Using a separate object makes it
// easier that resources are released under all circumstances, // easier that resources are released under all circumstances,
// esp. exceptions // esp. exceptions
@ -324,12 +376,7 @@ public:
CloseHandle(m_parent->m_oInputWrite.hEvent); CloseHandle(m_parent->m_oInputWrite.hEvent);
if (m_parent->m_piProcInfo.hProcess) { if (m_parent->m_piProcInfo.hProcess) {
LOGDEB(("ExecCmd: GenerateConsoleCtrlEvent -> %d\n", BOOL bSuccess = sendIntr(m_parent->m_piProcInfo.dwProcessId);
m_parent->m_piProcInfo.dwProcessId));
BOOL bSuccess =
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
m_parent->m_piProcInfo.dwProcessId);
if (bSuccess) { if (bSuccess) {
// Give it a chance, then terminate // Give it a chance, then terminate
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@ -457,10 +504,7 @@ void ExecCmd::zapChild()
bool ExecCmd::requestChildExit() bool ExecCmd::requestChildExit()
{ {
if (m->m_piProcInfo.hProcess) { if (m->m_piProcInfo.hProcess) {
LOGDEB(("ExecCmd: GenerateConsoleCtrlEvent -> %d\n", return sendIntr(m->m_piProcInfo.dwProcessId);
m->m_piProcInfo.dwProcessId));
return GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
m->m_piProcInfo.dwProcessId);
} }
return false; return false;
} }