Subject: | Win32::Daemon-20131206 does not support stop/pause or any other callbacks except timer and continue under Windows 10/2016 Server - patch included |
Date: | Wed, 5 Sep 2018 12:58:08 +0200 |
To: | bug-Win32-Daemon [...] rt.cpan.org |
From: | Łukasz Wrzesiński <lukasz.wrzesinski [...] gmail.com> |
GetVersionEx() function on Windows8 and newer could return dwMajorVersion
value which IS NOT covered by switch in Daemon.xs (in case of missing
manifest file it return 6, which is maximum supported version.
The following patch cure the issue (at least for me).
Tested on 20131206 version of Win32::Daemon and StrawberryPerl 5.28.1 on
Windows 10 and Windows 2016 Server.
I replaced switch with if/else, removed resetting of gdwControlsAccepted
(default value from header file will not be reset) and updated default set
to ONLY list of supported on ALL Windows versions.
diff --git a/Daemon.xs b/Daemon.xs
index 1ca5543..c8232cb 100644
--- a/Daemon.xs
+++ b/Daemon.xs
@@ -956,40 +956,29 @@ BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD
fdwReason, LPVOID lpvReserved )
gdwLastControlMessage = SERVICE_CONTROL_NONE;
gdwTimeoutState = SERVICE_START_PENDING;
- gdwControlsAccepted = 0;
- switch( gsOSVerInfo.dwMajorVersion )
+ if ( gsOSVerInfo.dwMajorVersion >= 6 )
{
- case 6:
- // We have Windows Vista
- // The following constants only work on Vista and
higher:
- // SERVICE_ACCEPT_PRESHUTDOWN
- //
+ // We have at least Windows Vista
+ // The following constants only work on Vista and higher:
+ // SERVICE_ACCEPT_PRESHUTDOWN
+ //
#ifdef SERVICE_CONTROL_PRESHUTDOWN
- gdwControlsAccepted |= SERVICE_ACCEPT_PRESHUTDOWN;
+ gdwControlsAccepted |= SERVICE_ACCEPT_PRESHUTDOWN;
#endif // SERVICE_CONTROL_PRESHUTDOWN
- case 5:
- // We have Windows 2000 or XP
- // The following constants only work on Win2k and
higher:
- // SERVICE_ACCEPT_PARAMCHANGE
- // SERVICE_ACCEPT_NETBINDCHANGE
- //
- gdwControlsAccepted |= SERVICE_ACCEPT_PARAMCHANGE
- | SERVICE_ACCEPT_NETBINDCHANGE;
-
- case 4:
- case 3:
- case 2:
- case 1:
- case 0:
- // NT 4.0
- gdwControlsAccepted |= SERVICE_ACCEPT_STOP
- | SERVICE_ACCEPT_PAUSE_CONTINUE
- | SERVICE_ACCEPT_SHUTDOWN;
-
}
- gdwServiceType = SERVICE_WIN32_OWN_PROCESS
- | SERVICE_INTERACTIVE_PROCESS;
+
+ if ( gsOSVerInfo.dwMajorVersion >= 5 )
+ {
+ // We have Windows 2000 or XP
+ // The following constants only work on Win2k and higher:
+ // SERVICE_ACCEPT_PARAMCHANGE
+ // SERVICE_ACCEPT_NETBINDCHANGE
+ //
+ gdwControlsAccepted |= SERVICE_ACCEPT_PARAMCHANGE
+ | SERVICE_ACCEPT_NETBINDCHANGE;
+ }
+
gdwServiceBits = 0;
gdwLastError = 0;
gpSid = NULL;
@@ -2246,7 +2235,7 @@ AcceptedControls( ... )
if( 0 < items )
{
- gdwControlsAccepted = (DWORD)SvIV( ST( 0 ) );
+ gdwControlsAccepted = (DWORD)SvIV( ST( 0 ) );
}
RETVAL = gdwControlsAccepted;
}
diff --git a/Daemon.h b/Daemon.h
index a4a7a2e..5e2ad2a 100644
--- a/Daemon.h
+++ b/Daemon.h
@@ -189,11 +189,10 @@ DWORD gdwLastError;
DWORD gdwServiceErrorState = NO_ERROR;
DWORD gdwState = 0;
DWORD gdwTimeoutState = SERVICE_START_PENDING;
+// These controls should be accessible on all Windows versions
DWORD gdwControlsAccepted = SERVICE_ACCEPT_STOP
| SERVICE_ACCEPT_PAUSE_CONTINUE
- | SERVICE_ACCEPT_SHUTDOWN
- | SERVICE_ACCEPT_PARAMCHANGE
- | SERVICE_ACCEPT_NETBINDCHANGE;
+
<https://dialpad.com/launch?phone=%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20>
| SERVICE_ACCEPT_SHUTDOWN;
DWORD gdwServiceType = SERVICE_WIN32_OWN_PROCESS
| SERVICE_INTERACTIVE_PROCESS;