Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
4.4 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. FatalEngine.cpp
  5. Abstract:
  6. This module encapsulates the routines that are needed only for
  7. fatal error retrieval.
  8. Author:
  9. Abdullah Ustuner (AUstuner) 28-August-2002
  10. --*/
  11. #include "mca.h"
  12. extern IWbemServices *gPIWbemServices;
  13. extern IWbemLocator *gPIWbemLocator;
  14. BOOL
  15. MCAGetFatalError(
  16. VOID
  17. )
  18. /*++
  19. Routine Description:
  20. This function queries WMI for a fatal error upon successful completion
  21. of required initialization tasks. By using the enumerator provided by
  22. WMI as a response to the query, the object list is parsed and for each
  23. object the MCA Error Record is extracted. But in reality, there should be
  24. just one MCA Error Record present.
  25. Arguments:
  26. none
  27. Return Value:
  28. TRUE - Successful.
  29. FALSE - Unsuccessful.
  30. --*/
  31. {
  32. BOOL isSuccess = TRUE;
  33. HRESULT hResult = 0;
  34. PUCHAR pErrorRecordBuffer = NULL;
  35. INT errorRecordCount = 0;
  36. IEnumWbemClassObject *pObjectEnumerator = NULL;
  37. IWbemClassObject *apObjects[10];
  38. ULONG uReturned = 0;
  39. ULONG objectIndex = 0;
  40. LPWSTR pQueryLanguage = L"WQL";
  41. LPWSTR pQueryStatement = L"select * from MSMCAInfo_RawMCAData";
  42. //
  43. // Complete the required initialization tasks.
  44. //
  45. if (!MCAInitialize()) {
  46. isSuccess = FALSE;
  47. wprintf(L"ERROR: Initialization failed!\n");
  48. goto CleanUp;
  49. }
  50. BSTR bQueryLanguage = SysAllocString(pQueryLanguage);
  51. BSTR bQueryStatement = SysAllocString(pQueryStatement);
  52. if (bQueryLanguage == NULL || bQueryStatement == NULL) {
  53. isSuccess = FALSE;
  54. wprintf(L"ERROR: Memory allocation for string failed!\n");
  55. goto CleanUp;
  56. }
  57. //
  58. // Query WMI for the fatal error record.
  59. //
  60. hResult = gPIWbemServices->ExecQuery(bQueryLanguage,
  61. bQueryStatement,
  62. 0,
  63. 0,
  64. &pObjectEnumerator
  65. );
  66. if (FAILED(hResult)) {
  67. isSuccess = FALSE;
  68. wprintf(L"ERROR: Fatal error querying failed!\n");
  69. wprintf(L"ERROR: Result: 0x%x\n", hResult);
  70. goto CleanUp;
  71. }
  72. //
  73. // Now we will retrieve objects of type IWbemClassOject from this enumeration.
  74. //
  75. do {
  76. //
  77. // Retrieve objects until none is left in which case the final Next()
  78. // will return WBEM_S_FALSE.
  79. //
  80. hResult = pObjectEnumerator->Next(WBEM_INFINITE,
  81. 10,
  82. apObjects,
  83. &uReturned
  84. );
  85. if (SUCCEEDED(hResult)) {
  86. //
  87. // Now extract the actual MCA error record from the objects.
  88. //
  89. for (objectIndex = 0; objectIndex < uReturned; objectIndex++) {
  90. if (!MCAExtractErrorRecord(apObjects[objectIndex], &pErrorRecordBuffer)) {
  91. isSuccess = FALSE;
  92. wprintf(L"ERROR: Failed to get fatal error record data!\n");
  93. goto CleanUp;
  94. }
  95. if (pErrorRecordBuffer) {
  96. errorRecordCount++;
  97. wprintf(L"INFO: Succesfully retrieved fatal cache error data.\n");
  98. MCAPrintErrorRecord(pErrorRecordBuffer);
  99. }
  100. apObjects[objectIndex]->Release();
  101. }
  102. } else {
  103. wprintf(L"ERROR: Couldn't retrieve WMI objects!\n");
  104. goto CleanUp;
  105. }
  106. } while (hResult == WBEM_S_NO_ERROR);
  107. if (errorRecordCount == 0) {
  108. wprintf(L"INFO: No fatal error record was found!\n");
  109. }
  110. CleanUp:
  111. //
  112. // Release all WMI related objects.
  113. //
  114. if (pObjectEnumerator) {
  115. pObjectEnumerator->Release();
  116. }
  117. if (gPIWbemLocator) {
  118. gPIWbemLocator->Release();
  119. }
  120. if (gPIWbemServices) {
  121. gPIWbemServices->Release();
  122. }
  123. if (bQueryLanguage != NULL) {
  124. SysFreeString(bQueryLanguage);
  125. }
  126. if (bQueryStatement != NULL) {
  127. SysFreeString(bQueryStatement);
  128. }
  129. return isSuccess;
  130. }