api: revise logging
RegistryQueryString() may produce one or more "File not found" errors when called from RegistryQueryStringWait() - which is expected while waiting. Those errors were annoying and awkward to read in the log. Furthermore, should RegistryQueryString() fail, it already displays detailed Windows error message and the parent's logging was simplified to prevent repetitions in the log. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
faf7d3771c
commit
84c066fa79
@ -391,10 +391,10 @@ GetNetCfgInstanceId(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData, _O
|
|||||||
if (Key == INVALID_HANDLE_VALUE)
|
if (Key == INVALID_HANDLE_VALUE)
|
||||||
return LOG_LAST_ERROR(L"Opening device registry key failed");
|
return LOG_LAST_ERROR(L"Opening device registry key failed");
|
||||||
WCHAR *ValueStr;
|
WCHAR *ValueStr;
|
||||||
DWORD Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr);
|
DWORD Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr, TRUE);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG_ERROR(L"Failed to query NetCfgInstanceId value", Result);
|
LOG(WINTUN_LOG_ERR, L"Failed to query NetCfgInstanceId value");
|
||||||
goto cleanupKey;
|
goto cleanupKey;
|
||||||
}
|
}
|
||||||
if (FAILED(CLSIDFromString(ValueStr, CfgInstanceID)))
|
if (FAILED(CLSIDFromString(ValueStr, CfgInstanceID)))
|
||||||
@ -532,10 +532,10 @@ CreateAdapterData(
|
|||||||
|
|
||||||
/* Read the NetCfgInstanceId value and convert to GUID. */
|
/* Read the NetCfgInstanceId value and convert to GUID. */
|
||||||
WCHAR *ValueStr;
|
WCHAR *ValueStr;
|
||||||
Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr);
|
Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr, TRUE);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG_ERROR(L"Failed to query NetCfgInstanceId value", Result);
|
LOG(WINTUN_LOG_ERR, L"Failed to query NetCfgInstanceId value");
|
||||||
goto cleanupAdapter;
|
goto cleanupAdapter;
|
||||||
}
|
}
|
||||||
if (FAILED(CLSIDFromString(ValueStr, &(*Adapter)->CfgInstanceID)))
|
if (FAILED(CLSIDFromString(ValueStr, &(*Adapter)->CfgInstanceID)))
|
||||||
@ -928,10 +928,10 @@ GetTcpipInterfaceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_REG
|
|||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
return LOG_ERROR(L"Failed to open registry key", Result);
|
return LOG_ERROR(L"Failed to open registry key", Result);
|
||||||
WCHAR *Paths;
|
WCHAR *Paths;
|
||||||
Result = RegistryQueryString(TcpipAdapterRegKey, L"IpConfig", &Paths);
|
Result = RegistryQueryString(TcpipAdapterRegKey, L"IpConfig", &Paths, TRUE);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG_ERROR(L"Failed to query IpConfig value", Result);
|
LOG(WINTUN_LOG_ERR, L"Failed to query IpConfig value");
|
||||||
goto cleanupTcpipAdapterRegKey;
|
goto cleanupTcpipAdapterRegKey;
|
||||||
}
|
}
|
||||||
if (!Paths[0])
|
if (!Paths[0])
|
||||||
|
@ -180,7 +180,8 @@ RegistryQuery(
|
|||||||
_In_opt_z_ const WCHAR *Name,
|
_In_opt_z_ const WCHAR *Name,
|
||||||
_Out_opt_ DWORD *ValueType,
|
_Out_opt_ DWORD *ValueType,
|
||||||
_Out_ void **Buf,
|
_Out_ void **Buf,
|
||||||
_Inout_ DWORD *BufLen)
|
_Inout_ DWORD *BufLen,
|
||||||
|
_In_ BOOL Log)
|
||||||
{
|
{
|
||||||
HANDLE Heap = GetProcessHeap();
|
HANDLE Heap = GetProcessHeap();
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -193,15 +194,15 @@ RegistryQuery(
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
HeapFree(Heap, 0, *Buf);
|
HeapFree(Heap, 0, *Buf);
|
||||||
if (Result != ERROR_MORE_DATA)
|
if (Result != ERROR_MORE_DATA)
|
||||||
return LOG_ERROR(L"Querying value failed", Result);
|
return Log ? LOG_ERROR(L"Querying value failed", Result) : Result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WINTUN_STATUS
|
WINTUN_STATUS
|
||||||
RegistryQueryString(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ WCHAR **Value)
|
RegistryQueryString(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ WCHAR **Value, _In_ BOOL Log)
|
||||||
{
|
{
|
||||||
DWORD ValueType, Size = 256 * sizeof(WCHAR);
|
DWORD ValueType, Size = 256 * sizeof(WCHAR);
|
||||||
DWORD Result = RegistryQuery(Key, Name, &ValueType, Value, &Size);
|
DWORD Result = RegistryQuery(Key, Name, &ValueType, Value, &Size, Log);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
return Result;
|
return Result;
|
||||||
switch (ValueType)
|
switch (ValueType)
|
||||||
@ -236,7 +237,7 @@ RegistryQueryStringWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD
|
|||||||
LOG_ERROR(L"Failed to setup notification", Result);
|
LOG_ERROR(L"Failed to setup notification", Result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Result = RegistryQueryString(Key, Name, Value);
|
Result = RegistryQueryString(Key, Name, Value, FALSE);
|
||||||
if (Result != ERROR_FILE_NOT_FOUND && Result != ERROR_PATH_NOT_FOUND)
|
if (Result != ERROR_FILE_NOT_FOUND && Result != ERROR_PATH_NOT_FOUND)
|
||||||
break;
|
break;
|
||||||
LONGLONG TimeLeft = Deadline - GetTickCount64();
|
LONGLONG TimeLeft = Deadline - GetTickCount64();
|
||||||
|
@ -81,11 +81,15 @@ RegistryGetMultiString(_Inout_ WCHAR **Buf, _In_ DWORD Len, _In_ DWORD ValueType
|
|||||||
* string from the multi-string is returned. The string must be released with
|
* string from the multi-string is returned. The string must be released with
|
||||||
* HeapFree(GetProcessHeap(), 0, Value) after use.
|
* HeapFree(GetProcessHeap(), 0, Value) after use.
|
||||||
*
|
*
|
||||||
|
* @Log Set to TRUE to log all failures; FALSE to skip logging the innermost errors. Skipping innermost
|
||||||
|
* errors reduces log clutter when we are using RegistryQueryString() from
|
||||||
|
* RegistryQueryStringWait() and some errors are expected to occur.
|
||||||
|
*
|
||||||
* @return ERROR_SUCCESS on success; ERROR_INVALID_DATATYPE when the registry value is not a string; Win32 error code
|
* @return ERROR_SUCCESS on success; ERROR_INVALID_DATATYPE when the registry value is not a string; Win32 error code
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
WINTUN_STATUS
|
WINTUN_STATUS
|
||||||
RegistryQueryString(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ WCHAR **Value);
|
RegistryQueryString(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ WCHAR **Value, _In_ BOOL Log);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads string value from registry key. It waits for the registry value to become available.
|
* Reads string value from registry key. It waits for the registry value to become available.
|
||||||
|
Loading…
Reference in New Issue
Block a user