Make sure all results from WMI queries are consumed.

If there are unconsumed results left from a WMI query an error is
generated in the event log.
This commit is contained in:
Ramon Novoa 2023-04-25 19:03:41 +02:00
parent ca7e1777e5
commit 7e829dd03c

View File

@ -99,7 +99,7 @@ Pandora_Wmi::isServiceRunning (string service_name) {
string query; string query;
char *state; char *state;
string str_state; string str_state;
int retval; int retval = -1;
query = "SELECT * FROM Win32_Service WHERE Name = \"" + service_name + "\""; query = "SELECT * FROM Win32_Service WHERE Name = \"" + service_name + "\"";
@ -112,23 +112,27 @@ Pandora_Wmi::isServiceRunning (string service_name) {
FOR_EACH (quickfix, quickfixes, NULL) { FOR_EACH (quickfix, quickfixes, NULL) {
dhGetValue (L"%s", &state, quickfix, dhGetValue (L"%s", &state, quickfix,
L".State"); L".State");
str_state = state; if (retval == -1) {
if (str_state == "Running") { str_state = state;
retval = 1; if (str_state == "Running") {
} retval = 1;
else { }
retval = 0; else {
retval = 0;
}
} }
dhFreeString (state); dhFreeString (state);
return retval;
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
pandoraLog ("isServiceRunning error. %s", errstr.c_str ()); pandoraLog ("isServiceRunning error. %s", errstr.c_str ());
} }
pandoraDebug ("Service %s not found.", service_name.c_str ()); if (retval == -1) {
return 0; pandoraDebug ("Service %s not found.", service_name.c_str ());
return 0;
}
return retval;
} }
/** /**
@ -1261,7 +1265,7 @@ Pandora_Wmi::getSystemAddress () {
CDispPtr wmi_svc = NULL, nic_info = NULL; CDispPtr wmi_svc = NULL, nic_info = NULL;
VARIANT ip_addresses; VARIANT ip_addresses;
char *caption = NULL, *mac_address = NULL; char *caption = NULL, *mac_address = NULL;
string ret = ""; string str_addr, ret = "";
try { try {
@ -1274,12 +1278,12 @@ Pandora_Wmi::getSystemAddress () {
dhGetValue (L"%v", &ip_addresses, nic_info_item, dhGetValue (L"%v", &ip_addresses, nic_info_item,
L".IPAddress"); L".IPAddress");
if (&ip_addresses != NULL) if (&ip_addresses != NULL && ret == "")
{ {
ret = getIPs(&ip_addresses); str_addr = getIPs(&ip_addresses);
if(ret != "0.0.0.0") { if (str_addr != "0.0.0.0") {
break; ret = str_addr;
} }
} }
} NEXT_THROW (nic_info_item); } NEXT_THROW (nic_info_item);
} catch (string errstr) { } catch (string errstr) {