Changeset 37312 in vbox
- Timestamp:
- Jun 3, 2011 9:00:49 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r37311 r37312 1174 1174 * opening the specified process. 1175 1175 */ 1176 HANDLE hOpenedProc = NULL; 1176 1177 HANDLE hProcess = rtProcWinFindPid(Process); 1177 1178 if (hProcess == NULL) 1178 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, Process); 1179 if (hProcess != NULL) 1179 { 1180 hProcess = hOpenedProc = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, Process); 1181 if (hProcess == NULL) 1182 { 1183 DWORD dwErr = GetLastError(); 1184 if (dwErr == ERROR_INVALID_PARAMETER) 1185 return VERR_PROCESS_NOT_FOUND; 1186 return RTErrConvertFromWin32(dwErr); 1187 } 1188 } 1189 1190 /* 1191 * Wait for it to terminate. 1192 */ 1193 int rc; 1194 DWORD Millies = fFlags == RTPROCWAIT_FLAGS_BLOCK ? INFINITE : 0; 1195 DWORD WaitRc = WaitForSingleObjectEx(hProcess, Millies, TRUE); 1196 while (WaitRc == WAIT_IO_COMPLETION) 1197 WaitRc = WaitForSingleObjectEx(hProcess, Millies, TRUE); 1198 switch (WaitRc) 1180 1199 { 1181 1200 /* 1182 * Wait for it to terminate.1201 * It has terminated. 1183 1202 */ 1184 DWORD Millies = fFlags == RTPROCWAIT_FLAGS_BLOCK ? INFINITE : 0; 1185 DWORD WaitRc = WaitForSingleObjectEx(hProcess, Millies, TRUE); 1186 while (WaitRc == WAIT_IO_COMPLETION) 1187 WaitRc = WaitForSingleObjectEx(hProcess, Millies, TRUE); 1188 switch (WaitRc) 1189 { 1190 /* 1191 * It has terminated. 1192 */ 1193 case WAIT_OBJECT_0: 1203 case WAIT_OBJECT_0: 1204 { 1205 DWORD dwExitCode; 1206 if (GetExitCodeProcess(hProcess, &dwExitCode)) 1194 1207 { 1195 DWORD dwExitCode;1196 if ( GetExitCodeProcess(hProcess, &dwExitCode))1208 /** @todo the exit code can be special statuses. */ 1209 if (pProcStatus) 1197 1210 { 1198 /** @todo the exit code can be special statuses. */ 1199 if (pProcStatus) 1200 { 1201 pProcStatus->enmReason = RTPROCEXITREASON_NORMAL; 1202 pProcStatus->iStatus = (int)dwExitCode; 1203 } 1211 pProcStatus->enmReason = RTPROCEXITREASON_NORMAL; 1212 pProcStatus->iStatus = (int)dwExitCode; 1213 } 1214 if (hOpenedProc == NULL) 1204 1215 rtProcWinRemovePid(Process); 1205 return VINF_SUCCESS; 1206 } 1207 break; 1216 rc = VINF_SUCCESS; 1208 1217 } 1209 1210 /* 1211 * It hasn't terminated just yet. 1212 */ 1213 case WAIT_TIMEOUT: 1214 return VERR_PROCESS_RUNNING; 1215 1216 /* 1217 * Something went wrong... 1218 */ 1219 case WAIT_FAILED: 1220 break; 1221 case WAIT_ABANDONED: 1222 AssertFailed(); 1223 return VERR_GENERAL_FAILURE; 1224 default: 1225 AssertMsgFailed(("WaitRc=%RU32\n", WaitRc)); 1226 return VERR_GENERAL_FAILURE; 1227 } 1228 } 1229 DWORD dwErr = GetLastError(); 1230 if (dwErr == ERROR_INVALID_PARAMETER) 1231 return VERR_PROCESS_NOT_FOUND; 1232 return RTErrConvertFromWin32(dwErr); 1218 else 1219 rc = RTErrConvertFromWin32(GetLastError()); 1220 break; 1221 } 1222 1223 /* 1224 * It hasn't terminated just yet. 1225 */ 1226 case WAIT_TIMEOUT: 1227 rc = VERR_PROCESS_RUNNING; 1228 break; 1229 1230 /* 1231 * Something went wrong... 1232 */ 1233 case WAIT_FAILED: 1234 rc = RTErrConvertFromWin32(GetLastError()); 1235 break; 1236 1237 case WAIT_ABANDONED: 1238 AssertFailed(); 1239 rc = VERR_GENERAL_FAILURE; 1240 break; 1241 1242 default: 1243 AssertMsgFailed(("WaitRc=%RU32\n", WaitRc)); 1244 rc = VERR_GENERAL_FAILURE; 1245 break; 1246 } 1247 1248 if (hOpenedProc != NULL) 1249 CloseHandle(hOpenedProc); 1250 return rc; 1233 1251 } 1234 1252
Note:
See TracChangeset
for help on using the changeset viewer.