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 2026/02/25 12:26:54 UTC
(commons-daemon) branch master updated: [DAEMON-477] Detaches from console when the service stops (#307)
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 879c151 [DAEMON-477] Detaches from console when the service stops (#307)
879c151 is described below
commit 879c1518a6ae63afdce748be5fd3b59e721f05b0
Author: Alexander PinĨuk <al...@gmail.com>
AuthorDate: Wed Feb 25 15:26:50 2026 +0300
[DAEMON-477] Detaches from console when the service stops (#307)
---
src/native/windows/apps/prunsrv/prunsrv.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index a26ef06..186444a 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -1999,8 +1999,17 @@ void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
apxLogWrite(APXLOG_MARK_DEBUG "Waiting %d milliseconds for all threads to exit.", timeout);
reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE_AS_MILLIS);
if (!apxDestroyJvm(timeout)) {
- /* if we are not using JAVA apxDestroyJvm does nothing, check the chid processes in case they hang */
+ /* if we are not using JAVA apxDestroyJvm does nothing */
apxLogWrite(APXLOG_MARK_DEBUG "apxDestroyJvm did nothing or failed");
+ /* detach service process from console */
+ if (GetConsoleWindow() != NULL) {
+ apxLogWrite(APXLOG_MARK_DEBUG "Detaching service from console");
+ if (FreeConsole())
+ apxLogWrite(APXLOG_MARK_DEBUG "Service detached from console");
+ else
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to detach service from console");
+ }
+ /* check the chid processes in case they hang */
for (;;) {
if (!apxProcessTerminateChild( GetCurrentProcessId(), TRUE)) {
/* Just print the children processes once for debugging */