You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/11/11 16:09:05 UTC
[commons-daemon] branch master updated: Add logging when failing to
obtain a service's description from the registry.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
The following commit(s) were added to refs/heads/master by this push:
new 29b7fa0 Add logging when failing to obtain a service's description from the registry.
29b7fa0 is described below
commit 29b7fa061c5b2f01207a49e1591fe47a8f45750e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Nov 11 11:09:02 2021 -0500
Add logging when failing to obtain a service's description from the
registry.
---
src/changes/changes.xml | 3 +++
src/native/windows/src/registry.c | 10 ++++++++--
src/native/windows/src/service.c | 4 ++--
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1f69f9c..8007c57 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -75,6 +75,9 @@
<action type="add" dev="ggregory" due-to="Gary Gregory">
Add support for a new log level called Trace, lower-level than Debug.
</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">
+ Add logging when failing to obtain a service's description from the registry.
+ </action>
<!-- -UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">
Bump actions/cache from v2 to v2.1.6 #24, #30.
diff --git a/src/native/windows/src/registry.c b/src/native/windows/src/registry.c
index 02a2cd2..f4bead5 100644
--- a/src/native/windows/src/registry.c
+++ b/src/native/windows/src/registry.c
@@ -856,13 +856,17 @@ BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
WCHAR wcName[SIZ_RESLEN];
DWORD rc, l = dwDescriptionLength * sizeof(WCHAR);
DWORD t = REG_SZ;
- if (lstrlenW(szServiceName) > SIZ_RESMAX)
+ int iServiceNameLen = lstrlenW(szServiceName);
+ if (iServiceNameLen > SIZ_RESMAX) {
+ apxLogWrite(APXLOG_MARK_WARN "Can't read service description because registry key '%s' length %d > %d", szServiceName, iServiceNameLen, SIZ_RESMAX);
return FALSE;
+ }
lstrcpyW(wcName, REGSERVICE_ROOT);
lstrcatW(wcName, szServiceName);
rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
if (rc != ERROR_SUCCESS) {
+ apxLogWrite(APXLOG_MARK_WARN "Can't read service description because registry key '%s' cannot be opened (rc = %d)", wcName, rc);
return FALSE;
}
rc = RegQueryValueExW(hKey, REGDESCRIPTION, NULL, &t, (BYTE *)szDescription,
@@ -870,8 +874,10 @@ BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
SAFE_CLOSE_KEY(hKey);
if (rc == ERROR_SUCCESS && t == REG_SZ)
return TRUE;
- else
+ else {
+ apxLogWrite(APXLOG_MARK_WARN "Can't read service description because registry key '%s' cannot query value at '%s' (rc = %d)", wcName, REGDESCRIPTION, rc);
return FALSE;
+ }
}
BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
diff --git a/src/native/windows/src/service.c b/src/native/windows/src/service.c
index a2fa79e..9602825 100644
--- a/src/native/windows/src/service.c
+++ b/src/native/windows/src/service.c
@@ -156,13 +156,13 @@ apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions)
if (!apxGetServiceDescriptionW(szServiceName,
lpService->stServiceEntry.szServiceDescription,
SIZ_DESLEN)) {
- apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service description");
+ apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service description for '%s'", szServiceName);
lpService->stServiceEntry.szServiceDescription[0] = L'\0';
}
if (!apxGetServiceUserW(szServiceName,
lpService->stServiceEntry.szObjectName,
SIZ_RESLEN)) {
- apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service user name");
+ apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service user name for '%s'", szServiceName);
lpService->stServiceEntry.szObjectName[0] = L'\0';
}
if (!QueryServiceConfigW(lpService->hService, NULL, 0, &dwNeeded)) {