/* * The control handler. * CTRL-C: signal the current process group. * CTRL-BREAK: stop the current process group. * default: abort the foreground and stopped processes, and exit */ static BOOL WINAPI console_ctrl_handler(DWORD code) { BOOL rval; #ifdef OSH_DEBUG fprintf(stderr, "console_ctrl_handler\n"); fflush(stderr); #endif rval = TRUE; switch(code) { case CTRL_C_EVENT: if(state->current_pgrp != INIT_PID) { #ifdef OSH_DEBUG fprintf(stderr, "console_ctrl_handler: ctrl-c, pgrp=%d, state = 0x%08x\n", state->current_pgrp, (unsigned long) state); fflush(stderr); #endif process_group_map(suspend_process, state->current_pgrp); } break; case CTRL_BREAK_EVENT: /* Ignore CTRL+BREAK, but it will get passed to all children... */ if(state->current_pgrp != INIT_PID) process_group_map(suspend_process, state->current_pgrp); break; case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: fprintf(stderr, "Exiting\n"); fflush(stderr); terminate_processes(); /* Now we exit too */ ExitProcess(1); break; default: fprintf(stderr, "console_ctrl_handler: unknown code: %d\n", code); fflush(stderr); rval = FALSE; break; } #ifdef OSH_DEBUG fprintf(stderr, "console_ctrl_handler: returning %d\n", rval); fflush(stderr); #endif return rval; }
int wmain(int argc, WCHAR *argv[]) { int status_code = 0; if (!process_arguments(argc, argv)) { HeapFree(GetProcessHeap(), 0, task_list); return 1; } if (force_termination) status_code = terminate_processes(); else status_code = send_close_messages(); HeapFree(GetProcessHeap(), 0, task_list); return status_code; }
/* * Stop everything. */ value omake_shell_sys_close(value v_unit) { CAMLparam1(v_unit); terminate_processes(); CAMLreturn(Val_unit); }