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/05 13:32:08 UTC

[commons-daemon] branch master updated: Log at Trace instead of Debug when a service reports its state from the prunsrv app.

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 b7259ff  Log at Trace instead of Debug when a service reports its state from the prunsrv app.
b7259ff is described below

commit b7259ff1e666019394716908a641f1b2b9e882db
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 5 09:32:06 2021 -0400

    Log at Trace instead of Debug when a service reports its state from the
    prunsrv app.
    
    This avoids the Debug log filling up as it adds two events per minute.
    You can then stay in Debug logging to capture register, start, stop, and
    unregister Debug events.
---
 src/changes/changes.xml                   |  5 +++++
 src/native/windows/apps/prunsrv/prunsrv.c | 18 +++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b89b6cf..abb4fbd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -51,6 +51,11 @@
         Procrun. Minor improvement that allows to have WINVER nmake variable
         directly defined at compile time as ABI version in hexadecimal format.
       </action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">
+        Log at Trace instead of Debug when a service reports its state from the prunsrv app.
+        This avoids the Debug log filling up as it adds two events per minute. 
+        You can then stay in Debug logging to capture register, start, stop, and unregister Debug events.
+      </action>      
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="John Patrick">
         Enable Dependabot #20.
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index 0cf3696..3452d1f 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -1056,7 +1056,8 @@ static const char* gSzCurrentState[] = {
  * SERVICE_STOP_PENDING      0x00000003 The service is stopping.
  * SERVICE_STOPPED           0x00000001 The service is not running.
  */
-static BOOL reportServiceStatusE(DWORD dwCurrentState,
+static BOOL reportServiceStatusE(DWORD dwLevel,
+                                 DWORD dwCurrentState,
                                  DWORD dwWin32ExitCode,
                                  DWORD dwWaitHint,
                                  DWORD dwServiceSpecificExitCode)
@@ -1065,8 +1066,9 @@ static BOOL reportServiceStatusE(DWORD dwCurrentState,
    BOOL fResult = TRUE;
 
    int gSzCurrentStateIdx = dwCurrentState < 0 ? 0 : dwCurrentState > _countof(gSzCurrentState) ? 0 : dwCurrentState;
-   apxLogWrite(APXLOG_MARK_DEBUG "reportServiceStatusE: dwCurrentState = %d (%s), dwWin32ExitCode = %d, dwWaitHint = %d milliseconds, dwServiceSpecificExitCode = %d.",
-               dwCurrentState, gSzCurrentState[gSzCurrentStateIdx], dwWin32ExitCode, dwWaitHint, dwServiceSpecificExitCode);
+   apxLogWrite(NULL, dwLevel, TRUE, __FILE__, __LINE__,
+       "reportServiceStatusE: dwCurrentState = %d (%s), dwWin32ExitCode = %d, dwWaitHint = %d milliseconds, dwServiceSpecificExitCode = %d.",
+       dwCurrentState, gSzCurrentState[gSzCurrentStateIdx], dwWin32ExitCode, dwWaitHint, dwServiceSpecificExitCode);
 
    if (_service_mode && _service_status_handle) {
        if (dwCurrentState == SERVICE_RUNNING)
@@ -1100,14 +1102,14 @@ static BOOL reportServiceStatus(DWORD dwCurrentState,
                                 DWORD dwWaitHint)
 {
     // exit code 0
-    return reportServiceStatusE(dwCurrentState, dwWin32ExitCode, dwWaitHint, 0);
+    return reportServiceStatusE(APXLOG_LEVEL_DEBUG, dwCurrentState, dwWin32ExitCode, dwWaitHint, 0);
 }
 
 /* Report SERVICE_STOPPED to the SCM.
  */
 static BOOL reportServiceStatusStopped(DWORD exitCode)
 {
-    return reportServiceStatusE(SERVICE_STOPPED, exitCode ? ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR, 0, exitCode);
+    return reportServiceStatusE(APXLOG_LEVEL_DEBUG, SERVICE_STOPPED, exitCode ? ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR, 0, exitCode);
 }
 
 BOOL child_callback(APXHANDLE hObject, UINT uMsg,
@@ -1561,9 +1563,11 @@ void WINAPI service_ctrl_handler(DWORD dwCtrlCode)
             CloseHandle(stopThread);
             return;
         case SERVICE_CONTROL_INTERROGATE:
-            reportServiceStatus(_service_status.dwCurrentState,
+            reportServiceStatusE(APXLOG_LEVEL_TRACE,
+                                _service_status.dwCurrentState,
                                 _service_status.dwWin32ExitCode,
-                                _service_status.dwWaitHint);
+                                _service_status.dwWaitHint,
+                                0);
             return;
         default:
             break;