| 1037 | } |
| 1038 | |
| 1039 | bool Process::DoEvents() |
| 1040 | { |
| 1041 | bool is_timeout = false; |
| 1042 | #ifndef _WIN32 |
| 1043 | bool could_not_kill = false; |
| 1044 | #endif /* _WIN32 */ |
| 1045 | |
| 1046 | if (m_Timeout != 0) { |
| 1047 | auto now (Utility::GetTime()); |
| 1048 | |
| 1049 | #ifndef _WIN32 |
| 1050 | { |
| 1051 | auto timeout (GetNextTimeout()); |
| 1052 | auto deadline (m_Result.ExecutionStart + timeout); |
| 1053 | |
| 1054 | if (deadline < now && !m_SentSigterm) { |
| 1055 | Log(LogWarning, "Process") |
| 1056 | << "Terminating process " << m_PID << " (" << PrettyPrintArguments(m_Arguments) |
| 1057 | << ") after timeout of " << timeout << " seconds"; |
| 1058 | |
| 1059 | m_OutputStream << "<Timeout exceeded.>"; |
| 1060 | |
| 1061 | int error = ProcessKill(m_Process, SIGTERM); |
| 1062 | if (error) { |
| 1063 | Log(LogWarning, "Process") |
| 1064 | << "Couldn't terminate the process " << m_PID << " (" << PrettyPrintArguments(m_Arguments) |
| 1065 | << "): [errno " << error << "] " << strerror(error); |
| 1066 | } |
| 1067 | |
| 1068 | m_SentSigterm = true; |
| 1069 | } |
| 1070 | } |
| 1071 | #endif /* _WIN32 */ |
| 1072 | |
| 1073 | auto timeout (GetNextTimeout()); |
| 1074 | auto deadline (m_Result.ExecutionStart + timeout); |
| 1075 | |
| 1076 | if (deadline < now) { |
| 1077 | Log(LogWarning, "Process") |
| 1078 | << "Killing process group " << m_PID << " (" << PrettyPrintArguments(m_Arguments) |
| 1079 | << ") after timeout of " << timeout << " seconds"; |
| 1080 | |
| 1081 | #ifdef _WIN32 |
| 1082 | m_OutputStream << "<Timeout exceeded.>"; |
| 1083 | TerminateProcess(m_Process, 3); |
| 1084 | #else /* _WIN32 */ |
| 1085 | int error = ProcessKill(-m_Process, SIGKILL); |
| 1086 | if (error) { |
| 1087 | Log(LogWarning, "Process") |
| 1088 | << "Couldn't kill the process group " << m_PID << " (" << PrettyPrintArguments(m_Arguments) |
| 1089 | << "): [errno " << error << "] " << strerror(error); |
| 1090 | if (error != ESRCH) { |
| 1091 | could_not_kill = true; |
| 1092 | } |
| 1093 | } |
| 1094 | #endif /* _WIN32 */ |
| 1095 | |
| 1096 | is_timeout = true; |
no test coverage detected