Patch win32service.tfmGracefulExit_php5.5.patch for win32service Bug #69170
Patch version 2015-03-03 15:20 UTC
Return to Bug #69170 |
Download this patch
Patch Revisions:
Developer: tfm-phpnet@earth.li
Only in win32service-0.1.0: .win32service.c.swp
Only in win32service-0.1.0_orig/: package.xml
diff -u win32service-0.1.0_orig/php_win32service_int.h win32service-0.1.0/php_win32service_int.h
--- win32service-0.1.0_orig/php_win32service_int.h 2011-03-15 16:55:42.000000000 +0000
+++ win32service-0.1.0/php_win32service_int.h 2015-03-02 17:10:09.863032700 +0000
@@ -33,6 +33,7 @@
DWORD svc_thread_id;
HANDLE event;
DWORD code;
+ zend_bool gracefulExit;
SERVICE_STATUS st;
SERVICE_STATUS_HANDLE sh;
SERVICE_TABLE_ENTRY te[2];
diff -u win32service-0.1.0_orig/win32service.c win32service-0.1.0/win32service.c
--- win32service-0.1.0_orig/win32service.c 2011-03-15 16:55:42.000000000 +0000
+++ win32service-0.1.0/win32service.c 2015-03-02 17:10:09.917035800 +0000
@@ -99,6 +99,7 @@
g->sh = RegisterServiceCtrlHandlerEx(g->service_name, service_handler, g);
+ g->gracefulExit = 1;
if (g->sh == (SERVICE_STATUS_HANDLE)0) {
g->code = GetLastError();
SetEvent(g->event);
@@ -131,18 +132,20 @@
{
char *name;
int name_len;
+ zend_bool gracefulExitParam=SVCG(gracefulExit);
if (SVCG(svc_thread)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "service ctrl dispatcher already running");
RETURN_FALSE;
}
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len)) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &name, &name_len, &gracefulExitParam)) {
RETURN_FALSE;
}
SVCG(service_name) = estrdup(name);
+ SVCG(gracefulExit)=gracefulExitParam;
SVCG(te)[0].lpServiceName = SVCG(service_name);
SVCG(te)[0].lpServiceProc = service_main;
SVCG(event) = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -166,6 +169,26 @@
}
/* }}} */
+/* {{{ proto bool win32_set_service_exit_mode(bool gracefulExit)
+ Set (and get) the exit mode of the service, when set to true the service
+ will shut down gracefuly when PHP exits, when set to false it will not shut
+ down gracefuly, this will mean that the service will count as having failed
+ and the recovery action will be run */
+static PHP_FUNCTION(win32_set_service_exit_mode)
+{
+ zend_bool gracefulExitParam=SVCG(gracefulExit);
+ zend_bool old_gracefulExitParam=SVCG(gracefulExit);
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &gracefulExitParam)) {
+ RETURN_FALSE;
+ }
+
+ SVCG(gracefulExit)=gracefulExitParam;
+
+ RETURN_BOOL(old_gracefulExitParam);
+}
+/* }}} */
+
/* {{{ proto bool win32_set_service_status(int status, [int checkpoint])
Update the service status */
static PHP_FUNCTION(win32_set_service_status)
@@ -549,6 +572,7 @@
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_win32_start_service_ctrl_dispatcher, 0, 0, 1)
ZEND_ARG_INFO(0, name)
+ ZEND_ARG_INFO(0, gracefulExit)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_win32_set_service_status, 0, 0, 1)
@@ -593,6 +617,10 @@
ZEND_ARG_INFO(0, servicename)
ZEND_ARG_INFO(0, machine)
ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_win32_set_service_exit_mode, 0, 0, 1)
+ ZEND_ARG_INFO(0, mode)
+ZEND_END_ARG_INFO()
/* }}} */
static zend_function_entry functions[] = {
@@ -606,6 +634,7 @@
PHP_FE(win32_stop_service, arginfo_win32_stop_service)
PHP_FE(win32_pause_service, arginfo_win32_pause_service)
PHP_FE(win32_continue_service, arginfo_win32_continue_service)
+ PHP_FE(win32_set_service_exit_mode, arginfo_win32_set_service_exit_mode)
{NULL, NULL, NULL}
};
@@ -759,7 +788,7 @@
static PHP_RSHUTDOWN_FUNCTION(win32service)
{
- if (SVCG(sh)) {
+ if (SVCG(sh) && SVCG(gracefulExit)) {
SVCG(st).dwCurrentState = SERVICE_STOPPED;
SetServiceStatus(SVCG(sh), &SVCG(st));
/* PostThreadMessage(SVCG(svc_thread_id), WM_QUIT, 0, 0); */
|