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/10 13:34:37 UTC
[commons-daemon] branch master updated: Refactor getting a name for
a service status state into a function.
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 1535cfd Refactor getting a name for a service status state into a function.
1535cfd is described below
commit 1535cfd292d82dade9e0c4e2d1ad0715308cd547
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Nov 10 08:34:34 2021 -0500
Refactor getting a name for a service status state into a function.
Reuse is forthcoming.
---
src/native/windows/apps/prunsrv/prunsrv.c | 15 +--------------
src/native/windows/src/private.h | 1 +
src/native/windows/src/service.c | 16 ++++++++++++++++
3 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index 3452d1f..59077d1 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -1031,18 +1031,6 @@ static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
return rv;
}
-/** Maps dwCurrentState to the constant name described on https://docs.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_status */
-static const char* gSzCurrentState[] = {
- "",
- "SERVICE_STOPPED",
- "SERVICE_START_PENDING",
- "SERVICE_STOP_PENDING",
- "SERVICE_RUNNING",
- "SERVICE_CONTINUE_PENDING",
- "SERVICE_PAUSE_PENDING",
- "SERVICE_PAUSED"
-};
-
/* Report the service status to the SCM, including service specific exit code.
*
* dwCurrentState
@@ -1065,10 +1053,9 @@ static BOOL reportServiceStatusE(DWORD dwLevel,
static DWORD dwCheckPoint = 1;
BOOL fResult = TRUE;
- int gSzCurrentStateIdx = dwCurrentState < 0 ? 0 : dwCurrentState > _countof(gSzCurrentState) ? 0 : dwCurrentState;
apxLogWrite(NULL, dwLevel, TRUE, __FILE__, __LINE__,
"reportServiceStatusE: dwCurrentState = %d (%s), dwWin32ExitCode = %d, dwWaitHint = %d milliseconds, dwServiceSpecificExitCode = %d.",
- dwCurrentState, gSzCurrentState[gSzCurrentStateIdx], dwWin32ExitCode, dwWaitHint, dwServiceSpecificExitCode);
+ dwCurrentState, apxServiceGetCurrentStateName(dwCurrentState), dwWin32ExitCode, dwWaitHint, dwServiceSpecificExitCode);
if (_service_mode && _service_status_handle) {
if (dwCurrentState == SERVICE_RUNNING)
diff --git a/src/native/windows/src/private.h b/src/native/windows/src/private.h
index 175df9f..55d8072 100644
--- a/src/native/windows/src/private.h
+++ b/src/native/windows/src/private.h
@@ -240,6 +240,7 @@ BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
DWORD dwDescriptionLength);
BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
DWORD dwUserLength);
+const char* apxServiceGetCurrentStateName(DWORD dwCurrentState);
DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount);
DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount);
diff --git a/src/native/windows/src/service.c b/src/native/windows/src/service.c
index 8eece82..d59118b 100644
--- a/src/native/windows/src/service.c
+++ b/src/native/windows/src/service.c
@@ -34,6 +34,22 @@ typedef struct APXSERVICE {
} APXSERVICE, *LPAPXSERVICE;
+/** Maps dwCurrentState to the constant name described on https://docs.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-service_status */
+static const char* gSzCurrentState[] = {
+ "",
+ "SERVICE_STOPPED",
+ "SERVICE_START_PENDING",
+ "SERVICE_STOP_PENDING",
+ "SERVICE_RUNNING",
+ "SERVICE_CONTINUE_PENDING",
+ "SERVICE_PAUSE_PENDING",
+ "SERVICE_PAUSED"
+};
+
+const char* apxServiceGetCurrentStateName(DWORD dwCurrentState) {
+ return gSzCurrentState[dwCurrentState < 0 ? 0 : dwCurrentState > _countof(gSzCurrentState) ? 0 : dwCurrentState];
+}
+
static WCHAR __invalidPathChars[] = L"<>:\"/\\:|?*";
static BOOL __apxIsValidServiceName(LPCWSTR szServiceName)
{