LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    if (message == uiShutDownWindowMessage) {
        SetConsoleCtrlHandler(interruptHandler, FALSE);
        SetConsoleCtrlHandler(shutdownHandler, TRUE);
        GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
        PostQuitMessage(0);
        return 0;
    } else if (message == uiInterruptMessage) {
        SetConsoleCtrlHandler(interruptHandler, TRUE);
        SetConsoleCtrlHandler(shutdownHandler, FALSE);
        GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
        return 0;
    }

    switch (message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Example #2
0
static DWORD WINAPI
_ecore_exe_thread_procedure(LPVOID data __UNUSED__)
{
   GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
   GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0);
   return 1;
}
Example #3
0
void Drive::Umount(HWND)
{
	// check mounted
	CheckMounted();
//	if (GetDriveType(mnt) == DRIVE_NO_ROOT_DIR)
//		mounted = false;
	if (!mounted)
		throw truntime_error(_T("Cannot unmount a not mounted drive"));

	// unmount
	fuse_unmount(wchar_to_utf8_cstr(mnt).c_str(), NULL);

	if (subProcess) {
		// attach console to allow sending ctrl-c
		AttachConsole(subProcess->pid);

		// disable ctrl-c to not exit this process
		SetConsoleCtrlHandler(HandlerRoutine, TRUE);

		if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, subProcess->pid)
		    && !GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, subProcess->pid))
			TerminateProcess(subProcess->hProcess, 0);

		// force exit
		if (WaitForSingleObject(subProcess->hProcess, 2000) == WAIT_TIMEOUT)
			TerminateProcess(subProcess->hProcess, 0);
			
		// close the console
		FreeConsole();
		SetConsoleCtrlHandler(HandlerRoutine, FALSE);
	}
	CheckMounted();
}
Example #4
0
int kill(pid_t pid, int sig)
{
  HANDLE h;
  HANDLE h_thread;
  DWORD thread_id;
  PROCESSENTRY32 pe32;
  if (pid <= 0 || sig < 0) {
    errno = EINVAL;
    return -1;
  }
  if (sig == 0) { /* we just wanted to know if the process exists  */
    h = CreateToolhelp32Snapshot(0, pid);
    if (h == INVALID_HANDLE_VALUE) {
      errno = ESRCH;
      return -1;
    }
    pe32.dwSize = sizeof(PROCESSENTRY32);
    if (!Process32First( h, &pe32 ))
      return handle_kill_result(h);
    CloseHandle(h);
    return 0;
  }
  h = OpenProcess(
    sig == 0 ? PROCESS_QUERY_INFORMATION|PROCESS_VM_READ : PROCESS_ALL_ACCESS, 
    FALSE, (DWORD)pid);
  if (!h) {
    CloseHandle(h);
    errno = ESRCH;
    return -1;
  }
  switch (sig) {
  case SIGINT:
    if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, (DWORD)pid))
      return handle_kill_result(h);
    break;
  case SIGQUIT:
    if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, (DWORD)pid))
      return handle_kill_result(h);
    break;
  case SIGKILL:
    if (!TerminateProcess(h, sig))
      return handle_kill_result(h);
    break;
  default:
    h_thread = CreateRemoteThread(
      h, NULL, 0,
      (LPTHREAD_START_ROUTINE)(GetProcAddress(GetModuleHandleA("KERNEL32.DLL"), "ExitProcess")),
      0, 0, &thread_id);
    if (h_thread)
      WaitForSingleObject(h_thread, 5);
    else
      return handle_kill_result(h);
  }
  CloseHandle(h);
  return 0;
}
Example #5
0
/* send signal to a single process */
int virProcessKill(pid_t pid, int sig)
{
    if (pid <= 1) {
        errno = ESRCH;
        return -1;
    }

#ifdef WIN32
    /* Mingw / Windows don't have many signals (AFAIK) */
    switch (sig) {
    case SIGINT:
        /* This does a Ctrl+C equiv */
        if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid)) {
            errno = ESRCH;
            return -1;
        }
        break;

    case SIGTERM:
        /* Since TerminateProcess is closer to SIG_KILL, we do
         * a Ctrl+Break equiv which is more pleasant like the
         * good old unix SIGTERM/HUP
         */
        if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid)) {
            errno = ESRCH;
            return -1;
        }
        break;

    default:
    {
        HANDLE proc;
        proc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
        if (!proc) {
            errno = ESRCH; /* Not entirely accurate, but close enough */
            return -1;
        }

        /*
         * TerminateProcess is more or less equiv to SIG_KILL, in that
         * a process can't trap / block it
         */
        if (sig != 0 && !TerminateProcess(proc, sig)) {
            errno = ESRCH;
            return -1;
        }
        CloseHandle(proc);
    }
    }
    return 0;
#else
    return kill(pid, sig);
#endif
}
Example #6
0
int
main(int argc, char *argv[])
{
    BOOL bRet;
    bRet = GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);  Sleep(1000);  LINE_BARRIER
    return bRet ? 0 : 125;
}
Example #7
0
bool DbgGdb::Interrupt()
{
    if ( m_debuggeePid > 0 ) {
        m_observer->UpdateAddLine( wxString::Format( wxT( "Interrupting debugee process: %ld" ), m_debuggeePid ) );

#ifdef __WXMSW__
        if ( !GetIsRemoteDebugging() && DebugBreakProcessFunc ) {
            // we have DebugBreakProcess
            HANDLE process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ( DWORD )m_debuggeePid );
            BOOL res = DebugBreakProcessFunc( process );
            CloseHandle(process);
            return res == TRUE;
        }

        if ( GetIsRemoteDebugging() ) {
            // We need to send GDB a Ctrl-C event.  Using DebugBreakProcess just leaves
			// it unresponsive.
            return GenerateConsoleCtrlEvent( CTRL_C_EVENT, 0 );
        }
 
        // on Windows version < XP we need to find a solution for interrupting the
        // debuggee process
        return false;
#else
        kill( m_debuggeePid, SIGINT );
        return true;
#endif
    } else {
        ::wxMessageBox(_("Can't interrupt debuggee process: I don't know its PID!"), wxT("CodeLite"));
    }
    return false;
}
Example #8
0
// Asks child process to shutdown. If it is unable to shutdown after some time - kills it.
void TearDownChildProcess(Config* pconfig) {
    DWORD wfso_result;

    EnterCriticalSection(&g_tear_down_crit);
    if(g_pchild_proc_info) {
        // Post WM_CLOSE to all windows whose PID matches child process's.
        EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)g_pchild_proc_info->dwProcessId);
        // Send ctrl + break event to ask app to close.
        GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, g_pchild_proc_info->dwProcessId);
        // Wait for process to exit.
        wfso_result = WaitForSingleObject(g_pchild_proc_info->hProcess,
                                          pconfig->process_wait_timeout_msec_);

        if (!wfso_result == WAIT_OBJECT_0) {
            if(wfso_result == WAIT_TIMEOUT) {
                fprintf(stderr, "\n->Timeout.\n");
            }
            fprintf(stderr, "Waiting for child process failed. Terminating child process.");
            if(!TerminateProcess(g_pchild_proc_info->hProcess, 1)) {
                ErrorExit(TEXT("Unable to terminate child process."));
            }
        }
        WaitForSingleObject(g_hchild_tracking_thread, INFINITE);
    }
    g_pchild_proc_info = NULL;
    LeaveCriticalSection(&g_tear_down_crit);
}
Example #9
0
/*
 * Terminate the process.
 * Try to do this by sending the CTRL_C event.
 * If that fails, just terminate it.
 */
static int kill_process(Process *processp)
{
    /*
     * Set the killed flag.
     * For threads, this will generate an exception
     * then next time it calls check_thread.
     */
    processp->killed = 1;
    if(processp->is_thread)
        return 0;

    /* Get the process id */
    if(processp->wid == 0)
        return -1;

#if 0
    /* Resume it so it can handle the exception */
    GenerateConsoleCtrlEvent(CTRL_C_EVENT, processp->wid);
    resume_process(processp);
#endif

    /* A lot of processes ignore the CTRL_C_EVENT, so just temrinate it */
    TerminateProcess(processp->handle, 1);
    return 0;
}
Example #10
0
/* Send an interrupt request to the inferior process. */
static void
win32_request_interrupt (void)
{
  winapi_DebugBreakProcess DebugBreakProcess;
  winapi_GenerateConsoleCtrlEvent GenerateConsoleCtrlEvent;

#ifdef _WIN32_WCE
  HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
#else
  HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
#endif

  GenerateConsoleCtrlEvent = GETPROCADDRESS (dll, GenerateConsoleCtrlEvent);

  if (GenerateConsoleCtrlEvent != NULL
      && GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, current_process_id))
    return;

  /* GenerateConsoleCtrlEvent can fail if process id being debugged is
     not a process group id.
     Fallback to XP/Vista 'DebugBreakProcess', which generates a
     breakpoint exception in the interior process.  */

  DebugBreakProcess = GETPROCADDRESS (dll, DebugBreakProcess);

  if (DebugBreakProcess != NULL
      && DebugBreakProcess (current_process_handle))
    return;

  /* Last resort, suspend all threads manually.  */
  soft_interrupt_requested = 1;
}
BOOL WINAPI breakHdl(DWORD dwCtrlType) {
#ifdef CCTERMINATE
	GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId);
	/* if(!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId)) TerminateProcess(pi.hProcess, 1); */
#else
	TerminateProcess(pi.hProcess, 1);
#endif
        return TRUE;
}
void InterruptOcaml(void)
{
	if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId)) {
		char message[1024];
		sprintf(message, "GenerateConsole failed: %lu\n", GetLastError());
		MessageBox(NULL, message, "Ocaml", MB_OK);
	}
	WriteToPipe(" ");
}
Example #13
0
static VALUE rb_GenerateConsoleCtrlEvent(VALUE self, VALUE event, VALUE pgid)
{
   unsigned int e = NUM2UINT(event);
   if ( e != CTRL_C_EVENT && e != CTRL_BREAK_EVENT )
      rb_raise(rb_eArgError, "Wrong event: only CTRL_C_EVENT or "
	       "CTRL_BREAK_EVENT accepted.");
   if ( GenerateConsoleCtrlEvent(e, NUM2UINT(pgid)) )
      return INT2FIX(1);
   return rb_getWin32Error();
}
Example #14
0
void pass_control_to_child(DWORD control_type) {
    /*
     * distribute-issue207
     * passes the control event to child process (Python)
     */
    if (!child_pid) {
        return;
    }
    GenerateConsoleCtrlEvent(child_pid,0);
}
Example #15
0
void gpr_subprocess_interrupt(gpr_subprocess *p) {
    DWORD dwExitCode;
    if (GetExitCodeProcess(p->pi.hProcess, &dwExitCode)) {
        if (dwExitCode == STILL_ACTIVE) {
            gpr_log(GPR_INFO, "sending ctrl-break");
            GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, p->pi.dwProcessId);
            p->joined = 1;
            p->interrupted = 1;
        }
    }
    return;
}
Example #16
0
File: sexe.c Project: buzz26/toyBox
//
//	ćƒ†ć‚¹ćƒˆčµ·å‹•
//	in: exe_name .. ćƒ—ćƒ­ć‚°ćƒ©ćƒ ćƒ•ć‚”ć‚¤ćƒ«ćƒ‘ć‚¹
//	    option_name .. ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć‚³ćƒžćƒ³ćƒ‰ćƒ©ć‚¤ćƒ³ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³
//	    pattern .. ēµ‚äŗ†ćƒ‘ć‚æćƒ¼ćƒ³
//
void execute_program(HWND hDlg, TCHAR *exe_name, TCHAR *option_name, int pattern)
{
	PROCESS_INFORMATION pi;
	DWORD count;

	// ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć‚’čµ·å‹•ć™ć‚‹ć€‚
	if(execute_process(exe_name, option_name, &pi)) {
		WaitForInputIdle(pi.hProcess,INFINITE);
		SetForegroundWindow(hDlg);
		// ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć‚’čµ·å‹•ć—ć¾ć—ćŸć€‚\nļ¼Æļ¼«ć‚’ć‚ÆćƒŖ惃ć‚Æ恙悋ćØćƒ—ćƒ­ć‚°ćƒ©ćƒ ć‚’ēµ‚äŗ†ć—ć¾ć™ć€‚\nēµ‚äŗ†ć—ćŖć„å “åˆć€ę‰‹å‹•ć§ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć‚’ēµ‚äŗ†ć•ć›ć¦ćć ć•ć„怂\n\nā€»ć“ć‚ŒćÆ sexe ć‹ć‚‰ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć‚’ēµ‚äŗ†ć•ć‚Œć‚‰ć‚Œć‚‹ć‹ć©ć†ć‹ć®ćƒ†ć‚¹ćƒˆć§ć€\nć€€å®Ÿéš›ć«ć‚µćƒ¼ćƒ“ć‚¹ć§ć®ę­£åøøå‹•ä½œćŒäæčØ¼ć•ć‚Œć‚‹ć‚ć‘ć§ćÆć‚ć‚Šć¾ć›ć‚“\n怀恮恧恔ę³Øꄏ恏恠恕恄怂
		MessageBoxResourceText(hDlg, IDS_TEST_EXECUTE, NULL, HEADER, MB_OK);
		process_id = pi.dwProcessId;
// 2011/9/19 kimukou.buzz
		if(pattern == END_CTRL_BREAK) {
			GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, process_id);
		}else if(pattern == END_CTRL_C) {
			GenerateConsoleCtrlEvent(CTRL_BREAK_C, process_id);
// 2011/9/19 kimukou.buzz
		} else {
			EnumWindows(EnumWindowsProc, pattern);
		}
		count = GetTickCount() + 30 * 1000;
		// ćƒ—ćƒ­ć‚°ćƒ©ćƒ ēµ‚äŗ†ć‚‚ć—ćć‚æć‚¤ćƒ ć‚¢ć‚¦ćƒˆ(30s)恧ꊜ恑悋
		while(count > GetTickCount()) {
	    	if(WaitForSingleObject(pi.hProcess, 0) != WAIT_TIMEOUT) {
				break;
			}
			Sleep(100);
		}
		// 2001/11/9
		CloseHandle(pi.hThread);
		CloseHandle(pi.hProcess);
	}
// 2011/9/19 kimukou.buzz
	//if(pattern == END_CTRL_BREAK) {
	if(pattern == END_CTRL_BREAK || pattern == END_CTRL_C) {
// 2011/9/19 kimukou.buzz
		FreeConsole();
	}
}
void CServiceModule::BreakChildren()
{
	debugf("intentionally stopping any games...\n");
	for (int i = 0; i < 98; i++) {
		DWORD pid = this->m_dwPIDs[i];
		if (pid) {
			FreeConsole();
			AttachConsole(pid);
			GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid);
			debugf("bye bye %d...\n", pid);
		}
	}
}
Example #18
0
void
__gnat_kill (int pid, int sig, int close)
{
  HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
  if (h == NULL)
    return;
  if (sig == 9)
    {
      TerminateProcess (h, 0);
      __gnat_win32_remove_handle (NULL, pid);
    }
  else if (sig == SIGINT)
    GenerateConsoleCtrlEvent (CTRL_C_EVENT, pid);
  else if (sig == SIGBREAK)
    GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid);
  /* ??? The last two alternatives don't really work. SIGBREAK requires setting
     up process groups at start time which we don't do; treating SIGINT is just
     not possible apparently. So we really only support signal 9. Fortunately
     that's all we use in GNAT.Expect */

  CloseHandle (h);
}
Example #19
0
// soft-break for processes like "more"
void CConsolePipe::SendCtrlBrk() {
	if(IsChildRunning()) {
		//GenerateConsoleCtrlEvent(CTRL_C_EVENT, m_dwProcessGroupId); // extra prodding for 9x
		// unfortunately, this has no effect for 9x, period. What crap OS this is!

		//TCHAR ctrlC[] = {3, 0};
		//SendChildInput(ctrlC); no effect, perhaps translated by pipework?

		// this is why we had to allocate a console even for NT
		if(GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, m_dwProcessGroupId))
			OnReceivedOutput(_T("<CtrlBreak>")); // visual reassurance
	}
}
Example #20
0
File: sexe.c Project: buzz26/toyBox
//
//	ć‚µćƒ¼ćƒ“ć‚¹åˆ¶å¾”č¦ę±‚å‡¦ē†
//	in: control .. SERVICE_CONTROL_STOP, SERVICE_CONTROL_SHUTDOWN 恧ēµ‚äŗ†å‡¦ē†
//
void service_control_handler(int control)
{
	switch(control) {
		case SERVICE_CONTROL_STOP:
		case SERVICE_CONTROL_SHUTDOWN:
			// 2009/3/26
			shutdown_flag = 1;

			send_status_to_scm(SERVICE_STOP_PENDING, 0, 1);
			if(end_pattern == END_CTRL_BREAK) {
				GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, process_id);
// 2011/9/1 kimukou.buzz
			}else if(end_pattern == END_CTRL_C) {
				GenerateConsoleCtrlEvent(CTRL_C_EVENT, process_id);
// 2011/9/1 kimukou.buzz
			} else {
				EnumWindows(EnumWindowsProc, end_pattern);
			}
			send_status_to_scm(SERVICE_STOPPED, 0, 0);
			break;
	}
}
Example #21
0
CAMLprim value win32_interrupt(value pseudopid) {
  CAMLparam1(pseudopid);
  HANDLE h;
  DWORD pid;
  FreeConsole(); /* Normally unnecessary, just to be sure... */
  h = (HANDLE)(Long_val(pseudopid));
  pid = GetProcessId(h);
  AttachConsole(pid);
  /* We want to survive the Ctrl-C that will also concerns us */
  SetConsoleCtrlHandler(NULL,TRUE); /* NULL + TRUE means ignore */
  GenerateConsoleCtrlEvent(CTRL_C_EVENT,0); /* signal our co-console */
  FreeConsole();
  CAMLreturn(Val_unit);
}
Example #22
0
/**
 * Process a signal based on current command handler settings.
 *
 * @param dwCtrlType The type of exception.
 *
 * @return true if we handled the signal, false if it should be
 *         passed up the handler chain.
 */
bool SystemInterpreter::processSignal(DWORD dwCtrlType)
{
    /* Ignore Ctrl+C if console is running in console */
    if (exceptionConsole)
    {
        GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, exceptionHostProcessId);
        return true;   /* ignore signal */
    }

    if (exceptionHostProcess)
    {
        GenerateConsoleCtrlEvent(CTRL_C_EVENT, exceptionHostProcessId);
        TerminateProcess(exceptionHostProcess, -1);
    }
    // if this is a ctrl_C, try to halt all of the activities.  If we hit this
    // in a situation where we still have one pending, then we'll allow the system
    // to kill the process.
    if (dwCtrlType == CTRL_C_EVENT)
    {
        return Interpreter::haltAllActivities(OREF_NULL);
    }
    return true;      /* ignore signal */
}
Example #23
0
bool SDLVideo::processOneFrame(Data data) {
	SDL_Event event;
	while (SDL_PollEvent(&event)) {
		switch (event.type) {
		case SDL_WINDOWEVENT:
			if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
				SDL_RenderSetViewport(renderer, nullptr);
				displayrect->w = event.window.data1;
				displayrect->h = event.window.data2;
			}
			break;
		case SDL_QUIT:
#ifdef _MSC_VER
			GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
#else
			std::raise(SIGTERM);
#endif
			return false;
		}
	}

	auto pic = safe_cast<const DataPicture>(data);
	if (pic->getFormat() != pictureFormat) {
		pictureFormat = pic->getFormat();
		createTexture();
	}

	auto const now = m_clock->now();
	auto const timestamp = pic->getTime() + PREROLL_DELAY; // assume timestamps start at zero
	auto const delay = std::max<int64_t>(0, timestamp - now);
	auto const delayInMs = clockToTimescale(delay, 1000);
	SDL_Delay((Uint32)delayInMs);

	if (pictureFormat.format == YUV420P) {
		SDL_UpdateYUVTexture(texture, nullptr,
		                     pic->getPlane(0), (int)pic->getPitch(0),
		                     pic->getPlane(1), (int)pic->getPitch(1),
		                     pic->getPlane(2), (int)pic->getPitch(2));
	} else {
		SDL_UpdateTexture(texture, nullptr, pic->getPlane(0), (int)pic->getPitch(0));
	}
	SDL_RenderCopy(renderer, texture, nullptr, displayrect.get());
	SDL_RenderPresent(renderer);

	m_NumFrames++;

	return true;
}
    virtual unsigned ThreadHandlerProc(void)
    {
	CHAR boxName[50];
	DWORD err, dwWritten;
	IPCMsg msg;

	wsprintf(boxName, "ExpectInjector_pid%d", GetCurrentProcessId());

	// Create the shared memory IPC transfer mechanism by name
	// (a mailbox).
	ConsoleDebuggerIPC = 
		new CMclMailbox(IPC_NUMSLOTS, IPC_SLOTSIZE, boxName);

	// Check status.
	err = ConsoleDebuggerIPC->Status();
	if (err != NO_ERROR && err != ERROR_ALREADY_EXISTS) {
	    OutputDebugString(GetSysMsg(err));
	    delete ConsoleDebuggerIPC;
	    return 0x666;
	}

	OutputDebugString("Expect's injector DLL loaded and ready.\n");

	// forever loop receiving messages over IPC.
	while (ConsoleDebuggerIPC->GetAlertable(&msg, interrupt)) {
	    switch (msg.type) {
	    case CTRL_EVENT:
		// Generate a Ctrl+C or Ctrl+Break to cause the equivalent
		// of a SIGINT into this process.
		GenerateConsoleCtrlEvent(msg.event, 0);
		break;
	    case IRECORD:
		// Stuff it into this console as if it had been entered
		// by the user.
#ifdef IPC_MAXRECORDS
		// If IPC_MAXRECORDS is defined, we have grouped key events.
		WriteConsoleInput(console, msg.irecord, msg.event,
				  &dwWritten);
#else
		WriteConsoleInput(console, &msg.irecord, 1, &dwWritten);
#endif
		break;
	    }
	}
	delete ConsoleDebuggerIPC;
	return 0;
    }
Example #25
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    if (message == uiShutDownWindowMessage) {
        GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
        PostQuitMessage(0);
        return 0;
    }

    switch (message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Example #26
0
/**
 * Check whether a valid handle has been returned. If not, then terminate.
 **/
void checkHandle(
    void *handle,
    char *info )
{
     if (!handle) {
        fprintf(stderr, "Error in %s: Creation failed: invalid handle\n", info);
        /* Generate Ctrl-C event to terminate process */
        GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);

        /* Wait in infinite loop as process will be terminated,
         * This is needed on windows as calling exit() or ExitProcess()
         * will fail to cleanup resources properly.
         */
        for (;;) {
            Sleep(300000); /* 5 minutes */
        }
     }
}
Example #27
0
void close_external(External_Process ** epp)
{
	External_Process *ep = *epp;
	BOOL rc;

	rc = GenerateConsoleCtrlEvent(CTRL_C_EVENT, ep->pid);
	if (!rc) {
		/* The console control event will fail for the winamp 
		   plugin.  Therefore, no choice but to kill 
		   the process using TerminateProcess()... */
		debug_print_error();
		debug_printf("rc = %d, gle = %d\n", rc, GetLastError());
		rc = TerminateProcess(ep->hproc, 0);
		debug_printf("Terminated process: %d\n", rc);
	}
	CloseHandle(ep->hproc);

	free(ep);
	*epp = 0;
}
Example #28
0
RETVAL GetCtrlRoutineAddress(void) {
    RETVAL rv = EXIT_OK;
    
    // must be cleaned up
    g_hAddrFoundEvent = NULL;
    
    // create an event so we know when the async callback has completed
    g_hAddrFoundEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // no security, manual reset, initially unsignaled, no name
    if (g_hAddrFoundEvent == NULL) {
        _HandleLastError(rv, __T("CreateEvent"));
    }
    
    // request that we be called on system signals
    if (!SetConsoleCtrlHandler(MyHandler, TRUE)) {
        _HandleLastError(rv, __T("SetConsoleCtrlHandler"));
    }
    
    // generate a signal
    if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) {
        _HandleLastError(rv, __T("GenerateConsoleCtrlEvent"));
    }
    
    // wait for our handler to be called
    {   DWORD dwWaitResult = WaitForSingleObject(g_hAddrFoundEvent, INFINITE);
        if (dwWaitResult == WAIT_FAILED) {
            _HandleLastError(rv, __T("WaitForSingleObject"));
        }
    }
    
    _Verify(g_dwCtrlRoutineAddr != NULL, rv, error);
    
error:
    if (g_hAddrFoundEvent != NULL) {
        if (!CloseHandle(g_hAddrFoundEvent)) {
            RETVAL rv2 = GetLastError();
            _TeardownIfError(rv, rv2, __T("CloseHandle"));
        }
    }
    
    return rv;
}
Example #29
0
void JohnProcess::terminate()
{
#ifdef Q_OS_UNIX
    if (pid() != 0) {
        /* Send sigterm to all processes of the group
         * created previously with setsid()
         * This is done in Johnny because of a bug in john <= 1.8.0
         * where it didn't forward signals to children and we want to keep
         * compatibility with those versions of John for now */
        ::kill(-pid(), SIGTERM);
    }
#elif defined(Q_OS_WIN)
    Q_PID pid = this->pid();
    FreeConsole();
    AttachConsole(pid->dwProcessId);
    GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
    FreeConsole();
#else
    QProcess::terminate();
#endif
}
Example #30
0
bool ScriptController::Break()
{
	debug("Sending break signal to %s", *m_infoName);

#ifdef WIN32
	BOOL ok = GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, m_dwProcessId);
#else
	bool ok = kill(m_processId, SIGINT) == 0;
#endif

	if (ok)
	{
		debug("Sent break signal to %s", *m_infoName);
	}
	else
	{
		warn("Could not send break signal to %s", *m_infoName);
	}

	return ok;
}