JBoss Native SVN: r2695 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2010-07-30 12:21:39 -0400 (Fri, 30 Jul 2010)
New Revision: 2695
Modified:
trunk/build/unix/package.list
Log:
Build trunk again.
Modified: trunk/build/unix/package.list
===================================================================
--- trunk/build/unix/package.list 2010-07-28 16:33:46 UTC (rev 2694)
+++ trunk/build/unix/package.list 2010-07-30 16:21:39 UTC (rev 2695)
@@ -43,9 +43,9 @@
mod_cluster|1.1.0.CR1|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR1
mod_cluster|1.1.0.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:trunk
mod_cluster|1.1.0.CR2|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR2
-mod_cluster|1.1.0.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:trunk
mod_cluster|1.1.0.CR3|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR3
mod_cluster|1.0.4.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:branches/1.0.x
mod_cluster|1.0.4.GA|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.0.4.GA
+mod_cluster|1.1.0.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:trunk
traffic_server|TS_Trunk|trunk
TC7|TC7_Trunk|trunk
14 years, 4 months
JBoss Native SVN: r2694 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2010-07-28 12:33:46 -0400 (Wed, 28 Jul 2010)
New Revision: 2694
Modified:
trunk/build/unix/package.list
Log:
Oops it needs to be .GA otherwise it doesn't guess the mod_cluster.jar filename...
Modified: trunk/build/unix/package.list
===================================================================
--- trunk/build/unix/package.list 2010-07-28 15:50:16 UTC (rev 2693)
+++ trunk/build/unix/package.list 2010-07-28 16:33:46 UTC (rev 2694)
@@ -46,6 +46,6 @@
mod_cluster|1.1.0.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:trunk
mod_cluster|1.1.0.CR3|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR3
mod_cluster|1.0.4.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:branches/1.0.x
-mod_cluster|1.0.4|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.0.4.GA
+mod_cluster|1.0.4.GA|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.0.4.GA
traffic_server|TS_Trunk|trunk
TC7|TC7_Trunk|trunk
14 years, 4 months
JBoss Native SVN: r2693 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2010-07-28 11:50:16 -0400 (Wed, 28 Jul 2010)
New Revision: 2693
Modified:
trunk/build/unix/package.list
Log:
Build for 1.0.4
Modified: trunk/build/unix/package.list
===================================================================
--- trunk/build/unix/package.list 2010-07-28 07:35:10 UTC (rev 2692)
+++ trunk/build/unix/package.list 2010-07-28 15:50:16 UTC (rev 2693)
@@ -46,5 +46,6 @@
mod_cluster|1.1.0.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:trunk
mod_cluster|1.1.0.CR3|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR3
mod_cluster|1.0.4.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:branches/1.0.x
+mod_cluster|1.0.4|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.0.4.GA
traffic_server|TS_Trunk|trunk
TC7|TC7_Trunk|trunk
14 years, 4 months
JBoss Native SVN: r2692 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2010-07-28 03:35:10 -0400 (Wed, 28 Jul 2010)
New Revision: 2692
Modified:
trunk/build/unix/buildbin.mod_cluster.sh
Log:
Don't add the conf for 1.0.x
Modified: trunk/build/unix/buildbin.mod_cluster.sh
===================================================================
--- trunk/build/unix/buildbin.mod_cluster.sh 2010-07-27 13:21:23 UTC (rev 2691)
+++ trunk/build/unix/buildbin.mod_cluster.sh 2010-07-28 07:35:10 UTC (rev 2692)
@@ -226,7 +226,11 @@
fi
# Add default mod_cluster conf in httpd.conf
-cat >> "${RPM_BUILD_ROOT}/opt/jboss/httpd/httpd/conf/httpd.conf" <<EOF
+case $build_version in
+ 1.0.*)
+ ;;
+ 1.1.*)
+ cat >> "${RPM_BUILD_ROOT}/opt/jboss/httpd/httpd/conf/httpd.conf" <<EOF
# MOD_CLUSTER_ADDS
# Adjust to you hostname and subnet.
<IfModule manager_module>
@@ -256,6 +260,8 @@
</VirtualHost>
</IfModule>
EOF
+ ;;
+esac
# Copy the install_home scripts
BASEHTTPD=/opt/jboss/httpd/
14 years, 4 months
JBoss Native SVN: r2691 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2010-07-27 09:21:23 -0400 (Tue, 27 Jul 2010)
New Revision: 2691
Modified:
trunk/build/unix/package.list
Log:
Test for 1.0.4
Modified: trunk/build/unix/package.list
===================================================================
--- trunk/build/unix/package.list 2010-07-21 20:14:05 UTC (rev 2690)
+++ trunk/build/unix/package.list 2010-07-27 13:21:23 UTC (rev 2691)
@@ -42,9 +42,9 @@
mod_cluster|1.0.3.GA|2.2.13|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.27|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.0.3.GA
mod_cluster|1.1.0.CR1|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR1
mod_cluster|1.1.0.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:trunk
-mod_cluster|1.0.4.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:branches/1.0.x
mod_cluster|1.1.0.CR2|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR2
mod_cluster|1.1.0.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:trunk
mod_cluster|1.1.0.CR3|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:1.1.0.CR3
+mod_cluster|1.0.4.dev|2.2.15|ssl:v:0.9.8k|zlib:v:1.2.3|jk:v:1.2.30|iconv:v:1.11|expat:v:1.95.8|cluster:t:branches/1.0.x
traffic_server|TS_Trunk|trunk
TC7|TC7_Trunk|trunk
14 years, 4 months
JBoss Native SVN: r2690 - in tags/jbosssvc: 2.0.8/procrun/apps/prunmgr and 2 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2010-07-21 16:14:05 -0400 (Wed, 21 Jul 2010)
New Revision: 2690
Added:
tags/jbosssvc/2.0.8/
tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.c
tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.h
tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.rc
tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.c
tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.h
tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.rc
tags/jbosssvc/2.0.8/procrun/src/cmdline.c
tags/jbosssvc/2.0.8/procrun/src/handles.c
tags/jbosssvc/2.0.8/procrun/src/javajni.c
tags/jbosssvc/2.0.8/procrun/src/log.c
tags/jbosssvc/2.0.8/procrun/src/mclib.c
tags/jbosssvc/2.0.8/procrun/src/private.h
tags/jbosssvc/2.0.8/procrun/src/registry.c
tags/jbosssvc/2.0.8/procrun/src/rprocess.c
tags/jbosssvc/2.0.8/procrun/src/service.c
tags/jbosssvc/2.0.8/procrun/src/utils.c
Removed:
tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.c
tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.h
tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.rc
tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.c
tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.h
tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.rc
tags/jbosssvc/2.0.8/procrun/src/cmdline.c
tags/jbosssvc/2.0.8/procrun/src/handles.c
tags/jbosssvc/2.0.8/procrun/src/javajni.c
tags/jbosssvc/2.0.8/procrun/src/log.c
tags/jbosssvc/2.0.8/procrun/src/mclib.c
tags/jbosssvc/2.0.8/procrun/src/private.h
tags/jbosssvc/2.0.8/procrun/src/registry.c
tags/jbosssvc/2.0.8/procrun/src/rprocess.c
tags/jbosssvc/2.0.8/procrun/src/service.c
tags/jbosssvc/2.0.8/procrun/src/utils.c
Log:
Tag 2.0.8
Copied: tags/jbosssvc/2.0.8 (from rev 2688, trunk/utils/windows/native/service)
Deleted: tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.c
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,1740 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* ====================================================================
- * prunsrv -- Service Runner.
- * Contributed by Mladen Turk <mturk(a)apache.org>
- * 05 Aug 2003
- * ====================================================================
- */
-
-/* Force the JNI vprintf functions */
-#define _DEBUG_JNI 1
-#include "apxwin.h"
-#include "prunmgr.h"
-
-LPAPXGUISTORE _gui_store = NULL;
-#define PRUNMGR_CLASS TEXT("PRUNMGR")
-#define TMNU_CONF TEXT("Configure...")
-#define TMNU_START TEXT("Start service")
-#define TMNU_STOP TEXT("Stop service")
-#define TMNU_EXIT TEXT("Exit")
-#define TMNU_ABOUT TEXT("About")
-#define TMNU_DUMP TEXT("Thread Dump")
-
-/* Display only Started/Paused status */
-#define STAT_STARTED TEXT("Started")
-#define STAT_PAUSED TEXT("Paused")
-#define STAT_STOPPED TEXT("Stopped")
-#define STAT_DISABLED TEXT("Disabled")
-#define STAT_NONE TEXT("")
-#define STAT_SYSTEM L"LocalSystem"
-
-#define LOGL_ERROR L"Error"
-#define LOGL_DEBUG L"Debug"
-#define LOGL_INFO L"Info"
-#define LOGL_WARN L"Warning"
-
-
-#define START_AUTO L"Automatic"
-#define START_MANUAL L"Manual"
-#define START_DISABLED L"Disabled"
-#define START_BOOT L"Boot"
-#define START_SYSTEM L"SystemInit"
-#define EMPTY_PASSWORD L" "
-
-#ifdef WIN64
-#define KREG_WOW6432 KEY_WOW64_32KEY
-#else
-#define KREG_WOW6432 0
-#endif
-
-/* Main application pool */
-APXHANDLE hPool = NULL;
-APXHANDLE hService = NULL;
-APXHANDLE hRegistry = NULL;
-APXHANDLE hRegserv = NULL;
-HICON hIcoRun = NULL;
-HICON hIcoStop = NULL;
-
-LPAPXSERVENTRY _currentEntry = NULL;
-
-BOOL bEnableTry = FALSE;
-DWORD startPage = 0;
-
-static LPCWSTR _s_log = L"Log";
-static LPCWSTR _s_java = L"Java";
-static LPCWSTR _s_start = L"Start";
-static LPCWSTR _s_stop = L"Stop";
-
-/* Allowed procrun commands */
-static LPCWSTR _commands[] = {
- L"ES", /* 1 Manage Service (default)*/
- L"MS", /* 2 Monitor Service */
- L"MR", /* 3 Monitor Service and start if not runing */
- L"MQ", /* 4 Quit all running Monitor applications */
- NULL
-};
-
-/* Allowed procrun parameters */
-static APXCMDLINEOPT _options[] = {
-/* 0 */ { L"AllowMultiInstances", NULL, NULL, APXCMDOPT_INT, NULL, 0},
- /* NULL terminate the array */
- { NULL }
-};
-
-/* Create RBUTTON try menu
- * Configure... (default, or lbutton dblclick)
- * Start <service name>
- * Stop <service name>
- * Exit
- * Logo
- */
-static void createRbuttonTryMenu(HWND hWnd)
-{
- HMENU hMnu;
- POINT pt;
- BOOL canStop = FALSE;
- BOOL canStart = FALSE;
- hMnu = CreatePopupMenu();
-
- if (_currentEntry) {
- if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING) {
- if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP)
- canStop = TRUE;
- }
- else if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_STOPPED) {
- if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED)
- canStart = TRUE;
- }
- }
- apxAppendMenuItem(hMnu, IDM_TM_CONFIG, TMNU_CONF, TRUE, TRUE);
- apxAppendMenuItem(hMnu, IDM_TM_START, TMNU_START, FALSE, canStart);
- apxAppendMenuItem(hMnu, IDM_TM_STOP, TMNU_STOP, FALSE, canStop);
- apxAppendMenuItem(hMnu, IDM_TM_DUMP, TMNU_DUMP, FALSE, canStop);
- apxAppendMenuItem(hMnu, IDM_TM_EXIT, TMNU_EXIT, FALSE, TRUE);
- apxAppendMenuItem(hMnu, -1, NULL, FALSE, FALSE);
- apxAppendMenuItem(hMnu, IDM_TM_ABOUT, TMNU_ABOUT, FALSE, TRUE);
-
- /* Ensure we have a focus */
- if (!SetForegroundWindow(hWnd))
- SetForegroundWindow(NULL);
- GetCursorPos(&pt);
- /* Display the try menu */
- TrackPopupMenu(hMnu, TPM_LEFTALIGN | TPM_RIGHTBUTTON,
- pt.x, pt.y, 0, hWnd, NULL);
- DestroyMenu(hMnu);
-}
-
-/* wParam progress dialog handle
- */
-static BOOL __startServiceCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- HWND hDlg = (HWND)hObject;
-
- switch (uMsg) {
- case WM_USER+1:
- hDlg = (HWND)lParam;
- if (IS_INVALID_HANDLE(hService)) {
- EndDialog(hDlg, IDOK);
- PostMessage(_gui_store->hMainWnd, WM_COMMAND,
- MAKEWPARAM(IDMS_REFRESH, 0), 0);
- return FALSE;
- }
- if (apxServiceControl(hService, SERVICE_CONTROL_CONTINUE, WM_USER+2,
- __startServiceCallback, hDlg)) {
- _currentEntry->stServiceStatus.dwCurrentState = SERVICE_RUNNING;
- _currentEntry->stStatusProcess.dwCurrentState = SERVICE_RUNNING;
-
- }
- EndDialog(hDlg, IDOK);
- PostMessage(_gui_store->hMainWnd, WM_COMMAND,
- MAKEWPARAM(IDMS_REFRESH, 0), 0);
- break;
- case WM_USER+2:
- SendMessage(hDlg, WM_USER+1, 0, 0);
- Sleep(500);
- break;
- }
- return TRUE;
-}
-
-static BOOL __stopServiceCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- HWND hDlg = (HWND)hObject;
-
- switch (uMsg) {
- case WM_USER+1:
- hDlg = (HWND)lParam;
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
- if (apxServiceControl(hService, SERVICE_CONTROL_STOP, WM_USER+2,
- __stopServiceCallback, hDlg)) {
- }
- EndDialog(hDlg, IDOK);
- PostMessage(_gui_store->hMainWnd, WM_COMMAND,
- MAKEWPARAM(IDMS_REFRESH, 0), 0);
- break;
- case WM_USER+2:
- if (wParam == 4)
- AplCopyMemory(&_currentEntry->stServiceStatus,
- (LPVOID)lParam, sizeof(SERVICE_STATUS));
- SendMessage(hDlg, WM_USER+1, 0, 0);
- Sleep(100);
- break;
- }
- return TRUE;
-}
-
-static BOOL __restartServiceCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- HWND hDlg = (HWND)hObject;
- switch (uMsg) {
- case WM_USER+1:
- hDlg = (HWND)lParam;
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
- /* TODO: use 128 as controll code */
- if (apxServiceControl(hService, 128, WM_USER+2,
- __restartServiceCallback, hDlg)) {
-
- }
- EndDialog(hDlg, IDOK);
- PostMessage(_gui_store->hMainWnd, WM_COMMAND,
- MAKEWPARAM(IDMS_REFRESH, 0), 0);
- break;
- case WM_USER+2:
- if (wParam == 4)
- AplCopyMemory(&_currentEntry->stServiceStatus,
- (LPVOID)lParam, sizeof(SERVICE_STATUS));
-
- SendMessage(hDlg, WM_USER+1, 0, 0);
- Sleep(100);
- break;
- }
- return TRUE;
-}
-
-static BOOL __pauseServiceCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- HWND hDlg = (HWND)hObject;
- switch (uMsg) {
- case WM_USER+1:
- hDlg = (HWND)lParam;
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
- if (apxServiceControl(hService, SERVICE_CONTROL_PAUSE, WM_USER+2,
- __pauseServiceCallback, hDlg)) {
- }
- EndDialog(hDlg, IDOK);
- PostMessage(_gui_store->hMainWnd, WM_COMMAND,
- MAKEWPARAM(IDMS_REFRESH, 0), 0);
- break;
- case WM_USER+2:
- if (wParam == 4)
- AplCopyMemory(&_currentEntry->stServiceStatus,
- (LPVOID)lParam, sizeof(SERVICE_STATUS));
- SendMessage(hDlg, WM_USER+1, 0, 0);
- Sleep(100);
- break;
- }
- return TRUE;
-}
-
-static DWORD _propertyChanged;
-static BOOL _propertyOpened = FALSE;
-static HWND _propertyHwnd = NULL;
-/* Service property pages */
-int CALLBACK __propertyCallback(HWND hwndPropSheet, UINT uMsg, LPARAM lParam)
-{
- switch(uMsg) {
- case PSCB_PRECREATE:
- {
- LPDLGTEMPLATE lpTemplate = (LPDLGTEMPLATE)lParam;
- if (!(lpTemplate->style & WS_SYSMENU))
- lpTemplate->style |= WS_SYSMENU;
- _propertyHwnd = hwndPropSheet;
-
- _propertyChanged = 0;
- _propertyOpened = TRUE;
- return TRUE;
- }
- break;
- case PSCB_INITIALIZED:
- break;
- }
- return TRUE;
-}
-
-BOOL __generalPropertySave(HWND hDlg)
-{
- WCHAR szN[256];
- WCHAR szD[256];
- DWORD dwStartType = SERVICE_NO_CHANGE;
- int i;
-
- if (!(TST_BIT_FLAG(_propertyChanged, 1)))
- return TRUE;
- CLR_BIT_FLAG(_propertyChanged, 1);
-
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
- GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, 255);
- GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, 1023);
- i = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST));
- if (i == 0)
- dwStartType = SERVICE_AUTO_START;
- else if (i == 1)
- dwStartType = SERVICE_DEMAND_START;
- else if (i == 2)
- dwStartType = SERVICE_DISABLED;
- apxServiceSetNames(hService, NULL, szN, szD, NULL, NULL);
- apxServiceSetOptions(hService, SERVICE_NO_CHANGE, dwStartType, SERVICE_NO_CHANGE);
-
- if (!(TST_BIT_FLAG(_propertyChanged, 2)))
- PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
-
- return TRUE;
-}
-
-BOOL __generalLogonSave(HWND hDlg)
-{
- WCHAR szU[64];
- WCHAR szP[64];
- WCHAR szC[64];
- DWORD dwStartType = SERVICE_NO_CHANGE;
-
- if (!(TST_BIT_FLAG(_propertyChanged, 2)))
- return TRUE;
- CLR_BIT_FLAG(_propertyChanged, 2);
-
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
- GetDlgItemTextW(hDlg, IDC_PPSLUSER, szU, 63);
- GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
- GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
-
- if (lstrlenW(szU) && lstrcmpiW(szU, STAT_SYSTEM)) {
- if (szP[0] != L' ' && szC[0] != L' ' && !lstrcmpW(szP, szC))
- apxServiceSetNames(hService, NULL, NULL, NULL, szU, szP);
- else {
- MessageBoxW(hDlg, apxLoadResourceW(IDS_VALIDPASS, 0),
- apxLoadResourceW(IDS_APPLICATION, 1),
- MB_OK | MB_ICONSTOP);
- return FALSE;
- }
- }
- else {
- apxServiceSetNames(hService, NULL, NULL, NULL, STAT_SYSTEM, L"");
- if (IsDlgButtonChecked(hDlg, IDC_PPSLID) == BST_CHECKED)
- apxServiceSetOptions(hService,
- _currentEntry->stServiceStatus.dwServiceType | SERVICE_INTERACTIVE_PROCESS,
- SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
- else
- apxServiceSetOptions(hService,
- _currentEntry->stServiceStatus.dwServiceType & ~SERVICE_INTERACTIVE_PROCESS,
- SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
- }
- if (!(TST_BIT_FLAG(_propertyChanged, 1)))
- PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
- return TRUE;
-}
-
-BOOL __generalLoggingSave(HWND hDlg)
-{
- WCHAR szB[SIZ_DESLEN];
-
- if (!(TST_BIT_FLAG(_propertyChanged, 3)))
- return TRUE;
- CLR_BIT_FLAG(_propertyChanged, 3);
-
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
-
- GetDlgItemTextW(hDlg, IDC_PPLGLEVEL, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Level", szB);
- GetDlgItemTextW(hDlg, IDC_PPLGPATH, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Path", szB);
- GetDlgItemTextW(hDlg, IDC_PPLGPREFIX, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Prefix", szB);
- GetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdOutput", szB);
- GetDlgItemTextW(hDlg, IDC_PPLGSTDERR, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdError", szB);
-
- if (!(TST_BIT_FLAG(_propertyChanged, 1)))
- PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
- return TRUE;
-}
-
-BOOL __generalJvmSave(HWND hDlg)
-{
- WCHAR szB[SIZ_DESLEN];
- LPWSTR p, s;
- DWORD l;
- if (!(TST_BIT_FLAG(_propertyChanged, 4)))
- return TRUE;
- CLR_BIT_FLAG(_propertyChanged, 4);
-
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
- if (!IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
- GetDlgItemTextW(hDlg, IDC_PPJJVM, szB, SIZ_DESMAX);
- }
- else
- lstrcpyW(szB, L"auto");
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Jvm", szB);
- GetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Classpath", szB);
-
- l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPJOPTIONS));
- p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
- GetDlgItemTextW(hDlg, IDC_PPJOPTIONS, p, l + 1);
- s = apxCRLFToMszW(hPool, p, &l);
- apxFree(p);
- apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_java, L"Options", s, l);
- if (!GetDlgItemTextW(hDlg, IDC_PPJMS, szB, SIZ_DESMAX))
- szB[0] = L'\0';
-
- apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMs",
- apxAtoulW(szB));
- if (!GetDlgItemTextW(hDlg, IDC_PPJMX, szB, SIZ_DESMAX))
- szB[0] = L'\0';
- apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMx",
- apxAtoulW(szB));
- if (!GetDlgItemTextW(hDlg, IDC_PPJSS, szB, SIZ_DESMAX))
- szB[0] = L'\0';
- apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmSs",
- apxAtoulW(szB));
- apxFree(s);
- if (!(TST_BIT_FLAG(_propertyChanged, 1)))
- PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
- return TRUE;
-}
-
-BOOL __generalStartSave(HWND hDlg)
-{
- WCHAR szB[SIZ_DESLEN];
- LPWSTR p, s;
- DWORD l;
-
- if (!(TST_BIT_FLAG(_propertyChanged, 5)))
- return TRUE;
- CLR_BIT_FLAG(_propertyChanged, 5);
-
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
-
- GetDlgItemTextW(hDlg, IDC_PPRCLASS, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Class", szB);
- GetDlgItemTextW(hDlg, IDC_PPRIMAGE, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Image", szB);
- GetDlgItemTextW(hDlg, IDC_PPRWPATH, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"WorkingPath", szB);
- GetDlgItemTextW(hDlg, IDC_PPRMETHOD, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Method", szB);
- GetDlgItemTextW(hDlg, IDC_PPRMODE, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Mode", szB);
-
- l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPRARGS));
- p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
- GetDlgItemTextW(hDlg, IDC_PPRARGS, p, l + 1);
- s = apxCRLFToMszW(hPool, p, &l);
- apxFree(p);
- apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_start, L"Params", s, l);
- apxFree(s);
-
- if (!(TST_BIT_FLAG(_propertyChanged, 1)))
- PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
- return TRUE;
-}
-
-BOOL __generalStopSave(HWND hDlg)
-{
- WCHAR szB[SIZ_DESLEN];
- LPWSTR p, s;
- DWORD l;
-
- if (!(TST_BIT_FLAG(_propertyChanged, 6)))
- return TRUE;
- CLR_BIT_FLAG(_propertyChanged, 6);
-
- if (IS_INVALID_HANDLE(hService))
- return FALSE;
-
- GetDlgItemTextW(hDlg, IDC_PPSCLASS, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Class", szB);
- GetDlgItemTextW(hDlg, IDC_PPSIMAGE, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Image", szB);
- GetDlgItemTextW(hDlg, IDC_PPSWPATH, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"WorkingPath", szB);
- GetDlgItemTextW(hDlg, IDC_PPSMETHOD, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Method", szB);
- GetDlgItemTextW(hDlg, IDC_PPSTIMEOUT, szB, SIZ_DESMAX);
- apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Timeout", apxAtoulW(szB));
- GetDlgItemTextW(hDlg, IDC_PPSMODE, szB, SIZ_DESMAX);
- apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Mode", szB);
-
- l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPSARGS));
- p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
- GetDlgItemTextW(hDlg, IDC_PPSARGS, p, l + 1);
- s = apxCRLFToMszW(hPool, p, &l);
- apxFree(p);
- apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"Params", s, l);
- apxFree(s);
-
- if (!(TST_BIT_FLAG(_propertyChanged, 1)))
- PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
- return TRUE;
-}
-
-void __generalPropertyRefresh(HWND hDlg)
-{
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), FALSE);
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), FALSE);
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), FALSE);
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), FALSE);
- switch (_currentEntry->stServiceStatus.dwCurrentState) {
- case SERVICE_RUNNING:
- if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP ||
- _currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), TRUE);
- SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STARTED);
- }
- else
- SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
- if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) {
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), TRUE);
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
- }
- break;
- case SERVICE_PAUSED:
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
- SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_PAUSED);
- break;
- case SERVICE_STOPPED:
- if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
- Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
- SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STOPPED);
- }
- else
- SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
- break;
- default:
- break;
- }
-}
-
-static BOOL bpropCentered = FALSE;
-LRESULT CALLBACK __generalProperty(HWND hDlg,
- UINT uMessage,
- WPARAM wParam,
- LPARAM lParam)
-{
- LPPSHNOTIFY lpShn;
- WCHAR szBuf[1024];
-
- switch (uMessage) {
- case WM_INITDIALOG:
- {
- if (!bEnableTry)
- apxCenterWindow(GetParent(hDlg), NULL);
- else if (!bpropCentered)
- apxCenterWindow(GetParent(hDlg), NULL);
- bpropCentered = TRUE;
- startPage = 0;
- if (!bEnableTry)
- apxCenterWindow(GetParent(hDlg), NULL);
- SendMessage(GetDlgItem(hDlg, IDC_PPSGDISP), EM_LIMITTEXT, 255, 0);
- SendMessage(GetDlgItem(hDlg, IDC_PPSGDESC), EM_LIMITTEXT, 1023, 0);
-
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_AUTO);
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_MANUAL);
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_DISABLED);
- if (_currentEntry->lpConfig->dwStartType == SERVICE_AUTO_START)
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 0);
- else if (_currentEntry->lpConfig->dwStartType == SERVICE_DEMAND_START)
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 1);
- else if (_currentEntry->lpConfig->dwStartType == SERVICE_DISABLED)
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 2);
-
- SetDlgItemTextW(hDlg, IDC_PPSGNAME, _currentEntry->szServiceName);
- SetDlgItemTextW(hDlg, IDC_PPSGDISP, _currentEntry->lpConfig->lpDisplayName);
- SetDlgItemTextW(hDlg, IDC_PPSGDESC, _currentEntry->szServiceDescription);
- SetDlgItemTextW(hDlg, IDC_PPSGDEXE, _currentEntry->lpConfig->lpBinaryPathName);
- __generalPropertyRefresh(hDlg);
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_PPSGCMBST:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 1);
- }
- break;
- case IDC_PPSGDISP:
- if (HIWORD(wParam) == EN_CHANGE) {
- GetDlgItemTextW(hDlg, IDC_PPSGDISP, szBuf, 255);
- if (!lstrcmpW(szBuf, _currentEntry->lpConfig->lpDisplayName)) {
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- CLR_BIT_FLAG(_propertyChanged, 1);
- }
- else {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 1);
- }
- }
- break;
- case IDC_PPSGDESC:
- if (HIWORD(wParam) == EN_CHANGE) {
- GetDlgItemTextW(hDlg, IDC_PPSGDESC, szBuf, 1023);
- if (!lstrcmpW(szBuf, _currentEntry->szServiceDescription)) {
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- CLR_BIT_FLAG(_propertyChanged, 1);
- }
- else {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 1);
- }
- }
- break;
- case IDC_PPSGSTART:
- apxProgressBox(hDlg, apxLoadResource(IDS_HSSTART, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __startServiceCallback, NULL);
- __generalPropertyRefresh(hDlg);
- break;
- case IDC_PPSGSTOP:
- apxProgressBox(hDlg, apxLoadResource(IDS_HSSTOP, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __stopServiceCallback, NULL);
- __generalPropertyRefresh(hDlg);
- break;
- case IDC_PPSGPAUSE:
- apxProgressBox(hDlg, apxLoadResource(IDS_HSPAUSE, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __pauseServiceCallback, NULL);
- __generalPropertyRefresh(hDlg);
- break;
- case IDC_PPSGRESTART:
- apxProgressBox(hDlg, apxLoadResource(IDS_HSRESTART, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __restartServiceCallback, NULL);
- __generalPropertyRefresh(hDlg);
- break;
- }
- break;
- case WM_NOTIFY:
- lpShn = (LPPSHNOTIFY )lParam;
- switch (lpShn->hdr.code) {
- case PSN_APPLY: /* sent when OK or Apply button pressed */
- if (__generalPropertySave(hDlg)) {
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- }
- else {
- SET_BIT_FLAG(_propertyChanged, 1);
- SetWindowLong(hDlg, DWLP_MSGRESULT,
- PSNRET_INVALID_NOCHANGEPAGE);
- return TRUE;
- }
-
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-
- return FALSE;
-}
-
-LRESULT CALLBACK __logonProperty(HWND hDlg,
- UINT uMessage,
- WPARAM wParam,
- LPARAM lParam)
-{
- LPPSHNOTIFY lpShn;
- WCHAR szBuf[1024];
- switch (uMessage) {
- case WM_INITDIALOG:
- {
- BOOL bAccount = FALSE;
- startPage = 1;
- if (!bpropCentered)
- apxCenterWindow(GetParent(hDlg), NULL);
- bpropCentered = TRUE;
-
- SendMessage(GetDlgItem(hDlg, IDC_PPSLUSER), EM_LIMITTEXT, 63, 0);
- SendMessage(GetDlgItem(hDlg, IDC_PPSLPASS), EM_LIMITTEXT, 63, 0);
- SendMessage(GetDlgItem(hDlg, IDC_PPSLCPASS), EM_LIMITTEXT, 63, 0);
- /* Check if we use LocalSystem or user defined account */
- if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
- bAccount = TRUE;
- CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLUA);
- SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
- SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
- SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
- }
- else {
- CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLLS);
- if (_currentEntry->lpConfig->dwServiceType &
- SERVICE_INTERACTIVE_PROCESS)
- CheckDlgButton(hDlg, IDC_PPSLID, BST_CHECKED);
- }
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), !bAccount);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), bAccount);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), bAccount);
- EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), bAccount);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), bAccount);
- EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), bAccount);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), bAccount);
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_PPSLLS:
- SetDlgItemTextW(hDlg, IDC_PPSLUSER, L"");
- SetDlgItemTextW(hDlg, IDC_PPSLPASS, L"");
- SetDlgItemTextW(hDlg, IDC_PPSLCPASS, L"");
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), FALSE);
- CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);
- if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 2);
- }
- else {
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- CLR_BIT_FLAG(_propertyChanged, 2);
- }
- break;
- case IDC_PPSLUA:
- SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
- SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
- SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), TRUE);
- CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);
- if (lstrcmpW(_currentEntry->szObjectName, STAT_SYSTEM)) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 2);
- }
- else {
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- CLR_BIT_FLAG(_propertyChanged, 2);
- }
- break;
- case IDC_PPSLID:
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 2);
- break;
- case IDC_PPSLUSER:
- if (HIWORD(wParam) == EN_CHANGE) {
- GetDlgItemTextW(hDlg, IDC_PPSLUSER, szBuf, 63);
- if (!lstrcmpiW(szBuf, _currentEntry->szObjectName)) {
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- CLR_BIT_FLAG(_propertyChanged, 2);
- }
- else {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 2);
- }
- }
- break;
- case IDC_PPSLPASS:
- case IDC_PPSLCPASS:
- if (HIWORD(wParam) == EN_CHANGE) {
- WCHAR szP[64];
- WCHAR szC[64];
- GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
- GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
- /* check for valid password match */
- if (szP[0] == L' ' && szC[0] == L' ') {
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- CLR_BIT_FLAG(_propertyChanged, 2);
- }
- else if (!lstrcmpW(szP, szC)) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 2);
- }
- }
- break;
- case IDC_PPSLBROWSE:
- {
- WCHAR szUser[SIZ_RESLEN];
- if (apxDlgSelectUser(hDlg, szUser))
- SetDlgItemTextW(hDlg, IDC_PPSLUSER, szUser);
- }
- break;
- }
- break;
- case WM_NOTIFY:
- lpShn = (LPPSHNOTIFY )lParam;
- switch (lpShn->hdr.code) {
- case PSN_APPLY: /* sent when OK or Apply button pressed */
- if (__generalLogonSave(hDlg))
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- else {
- SET_BIT_FLAG(_propertyChanged, 2);
- SetWindowLong(hDlg, DWLP_MSGRESULT,
- PSNRET_INVALID_NOCHANGEPAGE);
- return TRUE;
- }
-
- break;
- }
- break;
-
- default:
- break;
- }
- return FALSE;
-}
-
-LRESULT CALLBACK __loggingProperty(HWND hDlg,
- UINT uMessage,
- WPARAM wParam,
- LPARAM lParam)
-{
- LPPSHNOTIFY lpShn;
- LPWSTR lpBuf;
-
- switch (uMessage) {
- case WM_INITDIALOG:
- {
- LPWSTR b;
- startPage = 2;
- if (!bpropCentered)
- apxCenterWindow(GetParent(hDlg), NULL);
- bpropCentered = TRUE;
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_ERROR);
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_INFO);
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_WARN);
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_DEBUG);
- if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_log, L"Level")) != NULL) {
- if (!lstrcmpiW(b, LOGL_ERROR))
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
- else if (!lstrcmpiW(b, LOGL_INFO))
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 1);
- else if (!lstrcmpiW(b, LOGL_WARN))
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 2);
- else
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 3);
- apxFree(b);
- }
- else
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
- if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_log, L"Path")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPLGPATH, b);
- apxFree(b);
- }
- if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_log, L"StdOutput")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, b);
- apxFree(b);
- }
- if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_log, L"StdError")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, b);
- apxFree(b);
- }
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_PPLGLEVEL:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- case IDC_PPLGPATH:
- if (HIWORD(wParam) == EN_CHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- case IDC_PPLGPREFIX:
- if (HIWORD(wParam) == EN_CHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- case IDC_PPLGSTDERR:
- if (HIWORD(wParam) == EN_CHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- case IDC_PPLGSTDOUT:
- if (HIWORD(wParam) == EN_CHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- case IDC_PPLGBPATH:
- lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_LGPATHTITLE, 0),
- NULL);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPLGPATH, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- case IDC_PPLGBSTDOUT:
- lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDOUT, 0),
- apxLoadResourceW(IDS_ALLFILES, 1), NULL,
- NULL, FALSE, NULL);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- case IDC_PPLGBSTDERR:
- lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDERR, 0),
- apxLoadResourceW(IDS_ALLFILES, 1), NULL,
- NULL, FALSE, NULL);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 3);
- }
- break;
- }
- break;
- case WM_NOTIFY:
- lpShn = (LPPSHNOTIFY )lParam;
- switch (lpShn->hdr.code) {
- case PSN_APPLY: /* sent when OK or Apply button pressed */
- if (__generalLoggingSave(hDlg))
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- else {
- SET_BIT_FLAG(_propertyChanged, 3);
- SetWindowLong(hDlg, DWLP_MSGRESULT,
- PSNRET_INVALID_NOCHANGEPAGE);
- return TRUE;
- }
-
- break;
- }
- break;
-
- default:
- break;
- }
- return FALSE;
-}
-
-LRESULT CALLBACK __jvmProperty(HWND hDlg,
- UINT uMessage,
- WPARAM wParam,
- LPARAM lParam)
-{
- LPPSHNOTIFY lpShn;
- LPWSTR lpBuf, b;
- DWORD v;
- CHAR bn[32];
-
- switch (uMessage) {
- case WM_INITDIALOG:
- {
- startPage = 3;
- if (!bpropCentered)
- apxCenterWindow(GetParent(hDlg), NULL);
- bpropCentered = TRUE;
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_java, L"Jvm")) != NULL) {
- if (!lstrcmpiW(lpBuf, L"auto")) {
- CheckDlgButton(hDlg, IDC_PPJAUTO, BST_CHECKED);
- apxFree(lpBuf);
- lpBuf = apxGetJavaSoftRuntimeLib(hPool);
- EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
- }
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
- apxFree(lpBuf);
- }
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_java, L"Classpath")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_java, L"Options", NULL, NULL)) != NULL) {
- LPWSTR p = apxMszToCRLFW(hPool, lpBuf);
- SetDlgItemTextW(hDlg, IDC_PPJOPTIONS, p);
- apxFree(lpBuf);
- apxFree(p);
- }
- v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_java, L"JvmMs");
- if (v && v != 0xFFFFFFFF) {
- wsprintfA(bn, "%d", v);
- SetDlgItemTextA(hDlg, IDC_PPJMS, bn);
- }
- v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_java, L"JvmMx");
- if (v && v != 0xFFFFFFFF) {
- wsprintfA(bn, "%d", v);
- SetDlgItemTextA(hDlg, IDC_PPJMX, bn);
- }
- v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_java, L"JvmSs");
- if (v && v != 0xFFFFFFFF) {
- wsprintfA(bn, "%d", v);
- SetDlgItemTextA(hDlg, IDC_PPJSS, bn);
- }
-
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_PPJBJVM:
- b = apxGetJavaSoftHome(hPool, TRUE);
- lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPJBJVM, 0),
- apxLoadResourceW(IDS_DLLFILES, 1), NULL,
- b,
- TRUE, NULL);
- apxFree(b);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 4);
- }
- break;
- case IDC_PPJAUTO:
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 4);
- if (IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
- EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
- lpBuf = apxGetJavaSoftRuntimeLib(hPool);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
- apxFree(lpBuf);
- }
- }
- else {
- EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), TRUE);
- }
- break;
- case IDC_PPJJVM:
- case IDC_PPJCLASSPATH:
- case IDC_PPJOPTIONS:
- case IDC_PPJMX:
- case IDC_PPJMS:
- case IDC_PPJSS:
- if (HIWORD(wParam) == EN_CHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 4);
- }
- break;
- }
- break;
- case WM_NOTIFY:
- lpShn = (LPPSHNOTIFY )lParam;
- switch (lpShn->hdr.code) {
- case PSN_APPLY: /* sent when OK or Apply button pressed */
- if (__generalJvmSave(hDlg))
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- else {
- SET_BIT_FLAG(_propertyChanged, 4);
- SetWindowLong(hDlg, DWLP_MSGRESULT,
- PSNRET_INVALID_NOCHANGEPAGE);
- return TRUE;
- }
-
- break;
- }
- break;
-
- default:
- break;
- }
- return FALSE;
-}
-
-LRESULT CALLBACK __startProperty(HWND hDlg,
- UINT uMessage,
- WPARAM wParam,
- LPARAM lParam)
-{
- LPPSHNOTIFY lpShn;
- LPWSTR lpBuf, b;
-
- switch (uMessage) {
- case WM_INITDIALOG:
- {
- startPage = 4;
- if (!bpropCentered)
- apxCenterWindow(GetParent(hDlg), NULL);
- bpropCentered = TRUE;
-
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"");
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"jvm");
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), _s_java);
-
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_start, L"Class")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPRCLASS, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_start, L"Image")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_start, L"WorkingPath")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_start, L"Method")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPRMETHOD, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_start, L"Params", NULL, NULL)) != NULL) {
- b = apxMszToCRLFW(hPool, lpBuf);
- SetDlgItemTextW(hDlg, IDC_PPRARGS, b);
- apxFree(lpBuf);
- apxFree(b);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_start, L"Mode")) != NULL) {
- if (!lstrcmpiW(lpBuf, L"jvm")) {
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 1);
-
- }
- else if (!lstrcmpiW(lpBuf, _s_java)) {
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 2);
- }
- else {
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 0);
- EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
- }
- apxFree(lpBuf);
- }
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_PPRBWPATH:
- lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
- NULL);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 5);
- }
- break;
- case IDC_PPRBIMAGE:
- lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
- apxLoadResourceW(IDS_EXEFILES, 1), NULL,
- NULL, TRUE, NULL);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 5);
- }
- break;
- case IDC_PPRCLASS:
- case IDC_PPRMETHOD:
- case IDC_PPRARGS:
- case IDC_PPRIMAGE:
- case IDC_PPRWPATH:
- if (HIWORD(wParam) == EN_CHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 5);
- }
- break;
- case IDC_PPRMODE:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 5);
- if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPRMODE))) {
- EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), FALSE);
- }
- else {
- EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
- }
- }
- break;
-
- }
- break;
- case WM_NOTIFY:
- lpShn = (LPPSHNOTIFY )lParam;
- switch (lpShn->hdr.code) {
- case PSN_APPLY: /* sent when OK or Apply button pressed */
- if (__generalStartSave(hDlg))
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- else {
- SET_BIT_FLAG(_propertyChanged, 5);
- SetWindowLong(hDlg, DWLP_MSGRESULT,
- PSNRET_INVALID_NOCHANGEPAGE);
- return TRUE;
- }
-
- break;
- }
- break;
-
- default:
- break;
- }
- return FALSE;
-}
-
-LRESULT CALLBACK __stopProperty(HWND hDlg,
- UINT uMessage,
- WPARAM wParam,
- LPARAM lParam)
-{
- LPPSHNOTIFY lpShn;
- LPWSTR lpBuf, b;
- DWORD v;
-
- switch (uMessage) {
- case WM_INITDIALOG:
- {
- startPage = 5;
- if (!bpropCentered)
- apxCenterWindow(GetParent(hDlg), NULL);
- bpropCentered = TRUE;
-
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"");
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"jvm");
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), _s_java);
-
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"Class")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPSCLASS, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"Image")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"WorkingPath")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"Method")) != NULL) {
- SetDlgItemTextW(hDlg, IDC_PPSMETHOD, lpBuf);
- apxFree(lpBuf);
- }
- if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"Params", NULL, NULL)) != NULL) {
- b = apxMszToCRLFW(hPool, lpBuf);
- SetDlgItemTextW(hDlg, IDC_PPSARGS, b);
- apxFree(lpBuf);
- apxFree(b);
- }
- v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"Timeout");
- {
- CHAR bn[32];
- wsprintfA(bn, "%d", v);
- SetDlgItemTextA(hDlg, IDC_PPSTIMEOUT, bn);
- }
- if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
- _s_stop, L"Mode")) != NULL) {
- if (!lstrcmpiW(lpBuf, L"jvm")) {
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 1);
-
- }
- else if (!lstrcmpiW(lpBuf, _s_java)) {
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 2);
- }
- else {
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 0);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
- }
- apxFree(lpBuf);
- }
- }
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_PPSBWPATH:
- lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
- NULL);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 6);
- }
- break;
- case IDC_PPSBIMAGE:
- lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
- apxLoadResourceW(IDS_EXEFILES, 1), NULL,
- NULL, TRUE, NULL);
- if (lpBuf) {
- SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);
- apxFree(lpBuf);
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 6);
- }
- break;
- case IDC_PPSCLASS:
- case IDC_PPSMETHOD:
- case IDC_PPSTIMEOUT:
- case IDC_PPSARGS:
- case IDC_PPSIMAGE:
- case IDC_PPSWPATH:
- if (HIWORD(wParam) == EN_CHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 6);
- }
- break;
- case IDC_PPSMODE:
- if (HIWORD(wParam) == CBN_SELCHANGE) {
- PropSheet_Changed(GetParent(hDlg), hDlg);
- SET_BIT_FLAG(_propertyChanged, 6);
- if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSMODE))) {
- EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), FALSE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), FALSE);
- }
- else {
- EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
- EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
- }
- }
- break;
-
- }
- break;
- case WM_NOTIFY:
- lpShn = (LPPSHNOTIFY )lParam;
- switch (lpShn->hdr.code) {
- case PSN_APPLY: /* sent when OK or Apply button pressed */
- if (__generalStopSave(hDlg))
- PropSheet_UnChanged(GetParent(hDlg), hDlg);
- else {
- SET_BIT_FLAG(_propertyChanged, 6);
- SetWindowLong(hDlg, DWLP_MSGRESULT,
- PSNRET_INVALID_NOCHANGEPAGE);
- return TRUE;
- }
-
- break;
- }
- break;
-
- default:
- break;
- }
- return FALSE;
-}
-
-void __initPpage(PROPSHEETPAGEW *lpPage, INT iDlg, INT iTitle, DLGPROC pfnDlgProc)
-{
- lpPage->dwSize = sizeof(PROPSHEETPAGE);
- lpPage->dwFlags = PSP_USETITLE;
- lpPage->hInstance = _gui_store->hInstance;
- lpPage->pszTemplate = MAKEINTRESOURCEW(iDlg);
- lpPage->pszIcon = NULL;
- lpPage->pfnDlgProc = pfnDlgProc;
- lpPage->pszTitle = MAKEINTRESOURCEW(iTitle);
- lpPage->lParam = 0;
-}
-
-void ShowServiceProperties(HWND hWnd)
-{
- PROPSHEETPAGEW psP[6];
- PROPSHEETHEADERW psH;
- WCHAR szT[1024] = {0};
-
- if (_propertyOpened) {
- SetForegroundWindow(_gui_store->hMainWnd);
- return;
- }
- __initPpage(&psP[0], IDD_PROPPAGE_SGENERAL, IDS_PPGENERAL,
- __generalProperty);
- __initPpage(&psP[1], IDD_PROPPAGE_LOGON, IDS_PPLOGON,
- __logonProperty);
- __initPpage(&psP[2], IDD_PROPPAGE_LOGGING, IDS_PPLOGGING,
- __loggingProperty);
- __initPpage(&psP[3], IDD_PROPPAGE_JVM, IDS_PPJAVAVM,
- __jvmProperty);
- __initPpage(&psP[4], IDD_PROPPAGE_START, IDS_PPSTART,
- __startProperty);
- __initPpage(&psP[5], IDD_PROPPAGE_STOP, IDS_PPSTOP,
- __stopProperty);
-
- if (_currentEntry && _currentEntry->lpConfig)
- lstrcpyW(szT, _currentEntry->lpConfig->lpDisplayName);
- else
- return;
- lstrcatW(szT, L" Properties");
-
- psH.dwSize = sizeof(PROPSHEETHEADER);
- psH.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
- psH.hwndParent = bEnableTry ? hWnd : NULL;
- psH.hInstance = _gui_store->hInstance;
- psH.pszIcon = MAKEINTRESOURCEW(IDI_MAINICON);
- psH.pszCaption = szT;
- psH.nPages = 6;
- psH.ppsp = (LPCPROPSHEETPAGEW) &psP;
- psH.pfnCallback = (PFNPROPSHEETCALLBACK)__propertyCallback;
- psH.nStartPage = startPage;
-
- PropertySheetW(&psH);
- _propertyOpened = FALSE;
- if (!bEnableTry)
- PostQuitMessage(0);
- bpropCentered = FALSE;
-
-}
-
-static void signalService(LPCWSTR szServiceName)
-{
- HANDLE event;
- WCHAR en[SIZ_DESLEN];
- int i;
-
- lstrcpyW(en, L"Global\\");
- lstrcatW(en, szServiceName);
- lstrcatW(en, L"SIGNAL");
- for (i = 7; i < lstrlenW(en); i++) {
- if (en[i] >= L'a' && en[i] <= L'z')
- en[i] = en[i] - 32;
- }
-
-
- event = OpenEventW(EVENT_MODIFY_STATE, FALSE, en);
- if (event) {
- SetEvent(event);
- CloseHandle(event);
- }
- else
- apxDisplayError(TRUE, NULL, 0, "Unable to open the Event Mutex");
-
-}
-
-LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- switch (uMsg) {
- case WM_CREATE:
- if (bEnableTry) {
- if (_currentEntry && _currentEntry->lpConfig) {
- BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
- apxManageTryIconW(hWnd, NIM_ADD, NULL,
- _currentEntry->lpConfig->lpDisplayName,
- isRunning ? hIcoRun : hIcoStop);
- }
- else {
- apxManageTryIconA(hWnd, NIM_ADD, NULL,
- apxLoadResourceA(IDS_APPLICATION, 0),
- NULL);
- }
- }
- else
- ShowServiceProperties(hWnd);
-
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam)) {
- case IDM_TM_CONFIG:
- ShowServiceProperties(hWnd);
- break;
- case IDM_TM_ABOUT:
- apxAboutBox(hWnd);
- break;
- case IDM_TM_EXIT:
- SendMessage(hWnd, WM_CLOSE, 0, 0);
- break;
- case IDM_TM_START:
- if (!_propertyOpened)
- apxProgressBox(hWnd, apxLoadResource(IDS_HSSTART, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __startServiceCallback, NULL);
- break;
- case IDM_TM_STOP:
- if (!_propertyOpened)
- apxProgressBox(hWnd, apxLoadResource(IDS_HSSTOP, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __stopServiceCallback, NULL);
- break;
- case IDM_TM_PAUSE:
- if (!_propertyOpened)
- apxProgressBox(hWnd, apxLoadResource(IDS_HSPAUSE, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __pauseServiceCallback, NULL);
- break;
- case IDM_TM_RESTART:
- if (!_propertyOpened)
- apxProgressBox(hWnd, apxLoadResource(IDS_HSRESTART, 0),
- _currentEntry->lpConfig->lpDisplayName,
- __restartServiceCallback, NULL);
- break;
- case IDM_TM_DUMP:
- signalService(_currentEntry->szServiceName);
- break;
- case IDMS_REFRESH:
- if (bEnableTry &&
- (_currentEntry = apxServiceEntry(hService, TRUE)) != NULL) {
- BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
- apxManageTryIconW(hWnd, NIM_MODIFY, NULL,
- _currentEntry->lpConfig->lpDisplayName,
- isRunning ? hIcoRun : hIcoStop);
- }
- break;
-
- }
- break;
- case WM_TRAYMESSAGE:
- switch(lParam) {
- case WM_LBUTTONDBLCLK:
- ShowServiceProperties(hWnd);
- break;
- case WM_RBUTTONUP:
- _currentEntry = apxServiceEntry(hService, TRUE);
- createRbuttonTryMenu(hWnd);
- break;
- }
- break;
- case WM_QUIT:
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- break;
- case WM_DESTROY:
- if (bEnableTry)
- apxManageTryIconA(hWnd, NIM_DELETE, NULL, NULL, NULL);
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- break;
- }
-
- return FALSE;
-}
-
-static BOOL loadConfiguration()
-{
- return TRUE;
-}
-
-static BOOL saveConfiguration()
-{
- return TRUE;
-}
-
-/* Main program entry
- * Since we are inependant from CRT
- * the arguments are not used
- */
-#ifdef _NO_CRTLIBRARY
-int xMain(void)
-#else
-int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
-#endif
-{
- MSG msg;
- LPAPXCMDLINE lpCmdline;
- HANDLE mutex = NULL;
- BOOL quiet = FALSE;
-
- apxHandleManagerInitialize();
- hPool = apxPoolCreate(NULL, 0);
-
- /* Parse the command line */
- if ((lpCmdline = apxCmdlineParse(hPool, _options, _commands)) == NULL) {
- /* TODO: dispalay error message */
- apxDisplayError(TRUE, NULL, 0, "Error parsing command line");
- goto cleanup;
- }
-
- if (!lpCmdline->dwCmdIndex) {
- /* Skip sytem error message */
- SetLastError(ERROR_SUCCESS);
- apxDisplayError(TRUE, NULL, 0,
- apxLoadResourceA(IDS_ERRORCMD, 0),
- lpCmdLine);
- goto cleanup;
- }
- else if (lpCmdline->dwCmdIndex == 4)
- quiet = TRUE;
- else if (lpCmdline->dwCmdIndex >= 2)
- bEnableTry = TRUE;
- hService = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
- if (IS_INVALID_HANDLE(hService)) {
- if (!quiet)
- apxDisplayError(TRUE, NULL, 0, "Unable to open the Service Manager");
- goto cleanup;
- }
- /* Open the main service handle */
- if (!apxServiceOpen(hService, lpCmdline->szApplication,
- SERVICE_ALL_ACCESS)) {
- LPWSTR w = lpCmdline->szApplication + lstrlenW(lpCmdline->szApplication) - 1;
- if (*w == L'w')
- *w = L'\0';
- if (!apxServiceOpen(hService, lpCmdline->szApplication,
- SERVICE_ALL_ACCESS)) {
- if (!apxServiceOpen(hService, lpCmdline->szApplication,
- GENERIC_READ | GENERIC_EXECUTE)) {
-
- if (!quiet)
- apxDisplayError(TRUE, NULL, 0, "Unable to open the service '%S'",
- lpCmdline->szApplication);
- goto cleanup;
- }
- }
- }
- /* Obtain service parameters and status */
- if (!(_currentEntry = apxServiceEntry(hService, TRUE))) {
- if (!quiet)
- apxDisplayError(TRUE, NULL, 0, "Unable to query the service '%S' status",
- lpCmdline->szApplication);
- goto cleanup;
- }
-#ifdef _UNICODE
- _gui_store = apxGuiInitialize(MainWndProc, lpCmdline->szApplication);
-#else
- {
- CHAR szApp[MAX_PATH];
- _gui_store = apxGuiInitialize(MainWndProc,
- WideToAscii(lpCmdline->szApplication, szApp));
- }
-#endif
- if (!_gui_store) {
- if (!quiet)
- apxDisplayError(TRUE, NULL, 0, "Unable to initialize GUI manager");
- goto cleanup;
- }
- hIcoRun = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONRUN),
- IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
- hIcoStop = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONSTOP),
- IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-
- /* Handle //MQ// option */
- if (lpCmdline->dwCmdIndex == 4) {
- HANDLE hOther = FindWindow(_gui_store->szWndClass, NULL);
- if (hOther)
- SendMessage(hOther, WM_CLOSE, 0, 0);
- goto cleanup;
- }
-
- if (!_options[0].dwValue) {
- mutex = CreateMutex(NULL, FALSE, _gui_store->szWndMutex);
- if ((mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
- /* Skip sytem error message */
- SetLastError(ERROR_SUCCESS);
- if (!quiet)
- apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ALREAY_RUNING, 0),
- lpCmdline->szApplication);
- goto cleanup;
- }
- }
- hRegistry = apxCreateRegistry(hPool, KEY_ALL_ACCESS, NULL,
- apxLoadResource(IDS_APPLICATION, 0),
- APXREG_USER);
- loadConfiguration();
- hRegserv = apxCreateRegistryW(hPool, KEY_READ | KEY_WRITE | KREG_WOW6432,
- PRG_REGROOT,
- lpCmdline->szApplication,
- APXREG_SOFTWARE | APXREG_SERVICE);
-
- if (IS_INVALID_HANDLE(hRegserv)) {
- if (!quiet)
- apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ERRSREG, 0));
- return FALSE;
- }
- /* Create main invisible window */
- _gui_store->hMainWnd = CreateWindow(_gui_store->szWndClass,
- apxLoadResource(IDS_APPLICATION, 0),
- 0, 0, 0, 0, 0,
- NULL, NULL,
- _gui_store->hInstance,
- NULL);
-
- if (!_gui_store->hMainWnd) {
- goto cleanup;
- }
- if (lpCmdline->dwCmdIndex == 3)
- PostMessage(_gui_store->hMainWnd, WM_COMMAND, IDM_TM_START, 0);
-
- while (GetMessage(&msg, NULL, 0, 0)) {
- if(!TranslateAccelerator(_gui_store->hMainWnd,
- _gui_store->hAccel, &msg)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- saveConfiguration();
-
-cleanup:
- if (hIcoStop)
- DestroyIcon(hIcoStop);
- if (hIcoRun)
- DestroyIcon(hIcoRun);
- if (mutex)
- CloseHandle(mutex);
- if (lpCmdline)
- apxCmdlineFree(lpCmdline);
- apxCloseHandle(hService);
- apxHandleManagerDestroy();
- ExitProcess(0);
- return 0;
-}
-
Copied: tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.c (from rev 2689, trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,1763 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ * prunmgr -- Service Manager Application.
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+/* Force the JNI vprintf functions */
+#define _DEBUG_JNI 1
+#include "apxwin.h"
+#include "prunmgr.h"
+
+LPAPXGUISTORE _gui_store = NULL;
+#define PRUNMGR_CLASS TEXT("PRUNMGR")
+#define TMNU_CONF TEXT("Configure...")
+#define TMNU_START TEXT("Start service")
+#define TMNU_STOP TEXT("Stop service")
+#define TMNU_EXIT TEXT("Exit")
+#define TMNU_ABOUT TEXT("About")
+#define TMNU_DUMP TEXT("Thread Dump")
+
+/* Display only Started/Paused status */
+#define STAT_STARTED TEXT("Started")
+#define STAT_PAUSED TEXT("Paused")
+#define STAT_STOPPED TEXT("Stopped")
+#define STAT_DISABLED TEXT("Disabled")
+#define STAT_NONE TEXT("")
+#define STAT_SYSTEM L"LocalSystem"
+
+#define LOGL_ERROR L"Error"
+#define LOGL_DEBUG L"Debug"
+#define LOGL_INFO L"Info"
+#define LOGL_WARN L"Warning"
+
+
+#define START_AUTO L"Automatic"
+#define START_MANUAL L"Manual"
+#define START_DISABLED L"Disabled"
+#define START_BOOT L"Boot"
+#define START_SYSTEM L"SystemInit"
+#define EMPTY_PASSWORD L" "
+
+#ifdef WIN64
+#define KREG_WOW6432 KEY_WOW64_32KEY
+#else
+#define KREG_WOW6432 0
+#endif
+
+/* Main application pool */
+APXHANDLE hPool = NULL;
+APXHANDLE hService = NULL;
+APXHANDLE hRegistry = NULL;
+APXHANDLE hRegserv = NULL;
+HICON hIcoRun = NULL;
+HICON hIcoStop = NULL;
+
+LPAPXSERVENTRY _currentEntry = NULL;
+
+BOOL bEnableTry = FALSE;
+DWORD startPage = 0;
+
+static LPCWSTR _s_log = L"Log";
+static LPCWSTR _s_java = L"Java";
+static LPCWSTR _s_start = L"Start";
+static LPCWSTR _s_stop = L"Stop";
+
+/* Allowed prunmgr commands */
+static LPCWSTR _commands[] = {
+ L"ES", /* 1 Manage Service (default)*/
+ L"MS", /* 2 Monitor Service */
+ L"MR", /* 3 Monitor Service and start if not runing */
+ L"MQ", /* 4 Quit all running Monitor applications */
+ NULL
+};
+
+/* Allowed procrun parameters */
+static APXCMDLINEOPT _options[] = {
+/* 0 */ { L"AllowMultiInstances", NULL, NULL, APXCMDOPT_INT, NULL, 0},
+ /* NULL terminate the array */
+ { NULL }
+};
+
+/* Create RBUTTON try menu
+ * Configure... (default, or lbutton dblclick)
+ * Start <service name>
+ * Stop <service name>
+ * Exit
+ * Logo
+ */
+static void createRbuttonTryMenu(HWND hWnd)
+{
+ HMENU hMnu;
+ POINT pt;
+ BOOL canStop = FALSE;
+ BOOL canStart = FALSE;
+ hMnu = CreatePopupMenu();
+
+ if (_currentEntry) {
+ if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING) {
+ if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP)
+ canStop = TRUE;
+ }
+ else if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_STOPPED) {
+ if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED)
+ canStart = TRUE;
+ }
+ }
+ apxAppendMenuItem(hMnu, IDM_TM_CONFIG, TMNU_CONF, TRUE, TRUE);
+ apxAppendMenuItem(hMnu, IDM_TM_START, TMNU_START, FALSE, canStart);
+ apxAppendMenuItem(hMnu, IDM_TM_STOP, TMNU_STOP, FALSE, canStop);
+ apxAppendMenuItem(hMnu, IDM_TM_DUMP, TMNU_DUMP, FALSE, canStop);
+ apxAppendMenuItem(hMnu, IDM_TM_EXIT, TMNU_EXIT, FALSE, TRUE);
+ apxAppendMenuItem(hMnu, -1, NULL, FALSE, FALSE);
+ apxAppendMenuItem(hMnu, IDM_TM_ABOUT, TMNU_ABOUT, FALSE, TRUE);
+
+ /* Ensure we have a focus */
+ if (!SetForegroundWindow(hWnd))
+ SetForegroundWindow(NULL);
+ GetCursorPos(&pt);
+ /* Display the try menu */
+ TrackPopupMenu(hMnu, TPM_LEFTALIGN | TPM_RIGHTBUTTON,
+ pt.x, pt.y, 0, hWnd, NULL);
+ DestroyMenu(hMnu);
+}
+
+/* wParam progress dialog handle
+ */
+static BOOL __startServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService)) {
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return FALSE;
+ }
+ if (apxServiceControl(hService, SERVICE_CONTROL_CONTINUE, WM_USER+2,
+ __startServiceCallback, hDlg)) {
+ _currentEntry->stServiceStatus.dwCurrentState = SERVICE_RUNNING;
+ _currentEntry->stStatusProcess.dwCurrentState = SERVICE_RUNNING;
+
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(500);
+ break;
+ }
+ return TRUE;
+}
+
+static BOOL __stopServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ if (apxServiceControl(hService, SERVICE_CONTROL_STOP, WM_USER+2,
+ __stopServiceCallback, hDlg)) {
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ if (wParam == 4)
+ AplCopyMemory(&_currentEntry->stServiceStatus,
+ (LPVOID)lParam, sizeof(SERVICE_STATUS));
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(100);
+ break;
+ }
+ return TRUE;
+}
+
+static BOOL __restartServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ /* TODO: use 128 as controll code */
+ if (apxServiceControl(hService, 128, WM_USER+2,
+ __restartServiceCallback, hDlg)) {
+
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ if (wParam == 4)
+ AplCopyMemory(&_currentEntry->stServiceStatus,
+ (LPVOID)lParam, sizeof(SERVICE_STATUS));
+
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(100);
+ break;
+ }
+ return TRUE;
+}
+
+static BOOL __pauseServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ if (apxServiceControl(hService, SERVICE_CONTROL_PAUSE, WM_USER+2,
+ __pauseServiceCallback, hDlg)) {
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ if (wParam == 4)
+ AplCopyMemory(&_currentEntry->stServiceStatus,
+ (LPVOID)lParam, sizeof(SERVICE_STATUS));
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(100);
+ break;
+ }
+ return TRUE;
+}
+
+static DWORD _propertyChanged;
+static BOOL _propertyOpened = FALSE;
+static HWND _propertyHwnd = NULL;
+/* Service property pages */
+int CALLBACK __propertyCallback(HWND hwndPropSheet, UINT uMsg, LPARAM lParam)
+{
+ switch(uMsg) {
+ case PSCB_PRECREATE:
+ {
+ LPDLGTEMPLATE lpTemplate = (LPDLGTEMPLATE)lParam;
+ if (!(lpTemplate->style & WS_SYSMENU))
+ lpTemplate->style |= WS_SYSMENU;
+ _propertyHwnd = hwndPropSheet;
+
+ _propertyChanged = 0;
+ _propertyOpened = TRUE;
+ return TRUE;
+ }
+ break;
+ case PSCB_INITIALIZED:
+ break;
+ }
+ return TRUE;
+}
+
+BOOL __generalPropertySave(HWND hDlg)
+{
+ WCHAR szN[SIZ_RESLEN];
+ WCHAR szD[SIZ_DESLEN];
+ DWORD dwStartType = SERVICE_NO_CHANGE;
+ int i;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 1);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, SIZ_DESMAX);
+ i = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST));
+ if (i == 0)
+ dwStartType = SERVICE_AUTO_START;
+ else if (i == 1)
+ dwStartType = SERVICE_DEMAND_START;
+ else if (i == 2)
+ dwStartType = SERVICE_DISABLED;
+ apxServiceSetNames(hService, NULL, szN, szD, NULL, NULL);
+ apxServiceSetOptions(hService, SERVICE_NO_CHANGE, dwStartType, SERVICE_NO_CHANGE);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+
+ return TRUE;
+}
+
+BOOL __generalLogonSave(HWND hDlg)
+{
+ WCHAR szU[SIZ_RESLEN];
+ WCHAR szP[SIZ_RESLEN];
+ WCHAR szC[SIZ_RESLEN];
+ DWORD dwStartType = SERVICE_NO_CHANGE;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 2);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ GetDlgItemTextW(hDlg, IDC_PPSLUSER, szU, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, SIZ_RESMAX);
+
+ if (lstrlenW(szU) && lstrcmpiW(szU, STAT_SYSTEM)) {
+ if (szP[0] != L' ' && szC[0] != L' ' && !lstrcmpW(szP, szC)) {
+ apxServiceSetNames(hService, NULL, NULL, NULL, szU, szP);
+ lstrlcpyW(_currentEntry->szObjectName, SIZ_RESLEN, szU);
+ }
+ else {
+ MessageBoxW(hDlg, apxLoadResourceW(IDS_VALIDPASS, 0),
+ apxLoadResourceW(IDS_APPLICATION, 1),
+ MB_OK | MB_ICONSTOP);
+ return FALSE;
+ }
+ }
+ else {
+ apxServiceSetNames(hService, NULL, NULL, NULL, STAT_SYSTEM, L"");
+ lstrlcpyW(_currentEntry->szObjectName, SIZ_RESLEN, STAT_SYSTEM);
+ if (IsDlgButtonChecked(hDlg, IDC_PPSLID) == BST_CHECKED)
+ apxServiceSetOptions(hService,
+ _currentEntry->stServiceStatus.dwServiceType | SERVICE_INTERACTIVE_PROCESS,
+ SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+ else
+ apxServiceSetOptions(hService,
+ _currentEntry->stServiceStatus.dwServiceType & ~SERVICE_INTERACTIVE_PROCESS,
+ SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+ }
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalLoggingSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_DESLEN];
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 3)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 3);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+
+ GetDlgItemTextW(hDlg, IDC_PPLGLEVEL, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Level", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGPATH, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Path", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGPREFIX, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Prefix", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGPIDFILE, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"PidFile", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdOutput", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGSTDERR, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdError", szB);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalJvmSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_HUGLEN];
+ LPWSTR p, s;
+ DWORD l;
+ if (!(TST_BIT_FLAG(_propertyChanged, 4)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 4);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ if (!IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
+ GetDlgItemTextW(hDlg, IDC_PPJJVM, szB, SIZ_HUGMAX);
+ }
+ else
+ lstrcpyW(szB, L"auto");
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Jvm", szB);
+ GetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Classpath", szB);
+
+ l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPJOPTIONS));
+ p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+ GetDlgItemTextW(hDlg, IDC_PPJOPTIONS, p, l + 1);
+ s = apxCRLFToMszW(hPool, p, &l);
+ apxFree(p);
+ apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Options", s, l);
+ if (!GetDlgItemTextW(hDlg, IDC_PPJMS, szB, SIZ_HUGMAX))
+ szB[0] = L'\0';
+
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMs",
+ apxAtoulW(szB));
+ if (!GetDlgItemTextW(hDlg, IDC_PPJMX, szB, SIZ_DESMAX))
+ szB[0] = L'\0';
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMx",
+ apxAtoulW(szB));
+ if (!GetDlgItemTextW(hDlg, IDC_PPJSS, szB, SIZ_DESMAX))
+ szB[0] = L'\0';
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmSs",
+ apxAtoulW(szB));
+ apxFree(s);
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalStartSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_HUGLEN];
+ LPWSTR p, s;
+ DWORD l;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 5)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 5);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+
+ GetDlgItemTextW(hDlg, IDC_PPRCLASS, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Class", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRIMAGE, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Image", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRWPATH, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"WorkingPath", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRMETHOD, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Method", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRMODE, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Mode", szB);
+
+ l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPRARGS));
+ p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+ GetDlgItemTextW(hDlg, IDC_PPRARGS, p, l + 1);
+ s = apxCRLFToMszW(hPool, p, &l);
+ apxFree(p);
+ apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Params", s, l);
+ apxFree(s);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalStopSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_HUGLEN];
+ LPWSTR p, s;
+ DWORD l;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 6)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 6);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+
+ GetDlgItemTextW(hDlg, IDC_PPSCLASS, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Class", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSIMAGE, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Image", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSWPATH, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"WorkingPath", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSMETHOD, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Method", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSTIMEOUT, szB, SIZ_HUGMAX);
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Timeout", apxAtoulW(szB));
+ GetDlgItemTextW(hDlg, IDC_PPSMODE, szB, SIZ_HUGMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Mode", szB);
+
+ l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPSARGS));
+ p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+ GetDlgItemTextW(hDlg, IDC_PPSARGS, p, l + 1);
+ s = apxCRLFToMszW(hPool, p, &l);
+ apxFree(p);
+ apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Params", s, l);
+ apxFree(s);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+void __generalPropertyRefresh(HWND hDlg)
+{
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), FALSE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), FALSE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), FALSE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), FALSE);
+ switch (_currentEntry->stServiceStatus.dwCurrentState) {
+ case SERVICE_RUNNING:
+ if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP ||
+ _currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), TRUE);
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STARTED);
+ }
+ else
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+ if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) {
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), TRUE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+ }
+ break;
+ case SERVICE_PAUSED:
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_PAUSED);
+ break;
+ case SERVICE_STOPPED:
+ if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STOPPED);
+ }
+ else
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+ break;
+ default:
+ break;
+ }
+}
+
+static BOOL bpropCentered = FALSE;
+LRESULT CALLBACK __generalProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ WCHAR szBuf[SIZ_DESLEN];
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ if (!bEnableTry)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ else if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+ startPage = 0;
+ if (!bEnableTry)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSGDISP), EM_LIMITTEXT, SIZ_RESMAX, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSGDESC), EM_LIMITTEXT, SIZ_DESMAX, 0);
+
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_AUTO);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_MANUAL);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_DISABLED);
+ if (_currentEntry->lpConfig->dwStartType == SERVICE_AUTO_START)
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 0);
+ else if (_currentEntry->lpConfig->dwStartType == SERVICE_DEMAND_START)
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 1);
+ else if (_currentEntry->lpConfig->dwStartType == SERVICE_DISABLED)
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 2);
+
+ SetDlgItemTextW(hDlg, IDC_PPSGNAME, _currentEntry->szServiceName);
+ SetDlgItemTextW(hDlg, IDC_PPSGDISP, _currentEntry->lpConfig->lpDisplayName);
+ SetDlgItemTextW(hDlg, IDC_PPSGDESC, _currentEntry->szServiceDescription);
+ SetDlgItemTextW(hDlg, IDC_PPSGDEXE, _currentEntry->lpConfig->lpBinaryPathName);
+ __generalPropertyRefresh(hDlg);
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPSGCMBST:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 1);
+ }
+ break;
+ case IDC_PPSGDISP:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ GetDlgItemTextW(hDlg, IDC_PPSGDISP, szBuf, SIZ_RESMAX);
+ if (!lstrcmpW(szBuf, _currentEntry->lpConfig->lpDisplayName)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 1);
+ }
+ else {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 1);
+ }
+ }
+ break;
+ case IDC_PPSGDESC:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ GetDlgItemTextW(hDlg, IDC_PPSGDESC, szBuf, SIZ_DESMAX);
+ if (!lstrcmpW(szBuf, _currentEntry->szServiceDescription)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 1);
+ }
+ else {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 1);
+ }
+ }
+ break;
+ case IDC_PPSGSTART:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSSTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __startServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ case IDC_PPSGSTOP:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSSTOP, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __stopServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ case IDC_PPSGPAUSE:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSPAUSE, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __pauseServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ case IDC_PPSGRESTART:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSRESTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __restartServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalPropertySave(hDlg)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ }
+ else {
+ SET_BIT_FLAG(_propertyChanged, 1);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+LRESULT CALLBACK __logonProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ WCHAR szBuf[SIZ_DESLEN];
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ BOOL bAccount = FALSE;
+ startPage = 1;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+
+ SendMessage(GetDlgItem(hDlg, IDC_PPSLUSER), EM_LIMITTEXT, 63, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSLPASS), EM_LIMITTEXT, 63, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSLCPASS), EM_LIMITTEXT, 63, 0);
+ /* Check if we use LocalSystem or user defined account */
+ if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+ bAccount = TRUE;
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLUA);
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+ SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+ SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+ }
+ else {
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLLS);
+ if (_currentEntry->lpConfig->dwServiceType &
+ SERVICE_INTERACTIVE_PROCESS)
+ CheckDlgButton(hDlg, IDC_PPSLID, BST_CHECKED);
+ }
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), !bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), bAccount);
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPSLLS:
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, L"");
+ SetDlgItemTextW(hDlg, IDC_PPSLPASS, L"");
+ SetDlgItemTextW(hDlg, IDC_PPSLCPASS, L"");
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), FALSE);
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);
+ if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ else {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ break;
+ case IDC_PPSLUA:
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+ SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+ SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), TRUE);
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);
+ if (lstrcmpW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ else {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ break;
+ case IDC_PPSLID:
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ break;
+ case IDC_PPSLUSER:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ GetDlgItemTextW(hDlg, IDC_PPSLUSER, szBuf, SIZ_RESMAX);
+ if (!lstrcmpiW(szBuf, _currentEntry->szObjectName)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ else {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ }
+ break;
+ case IDC_PPSLPASS:
+ case IDC_PPSLCPASS:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ WCHAR szP[SIZ_RESLEN];
+ WCHAR szC[SIZ_RESLEN];
+ GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, SIZ_RESMAX);
+ /* check for valid password match */
+ if (szP[0] == L' ' && szC[0] == L' ') {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ else if (!lstrcmpW(szP, szC)) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ }
+ break;
+ case IDC_PPSLBROWSE:
+ {
+ WCHAR szUser[SIZ_RESLEN];
+ if (apxDlgSelectUser(hDlg, szUser))
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, szUser);
+ }
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalLogonSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 2);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __loggingProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf;
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ LPWSTR b;
+ startPage = 2;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_ERROR);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_INFO);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_WARN);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_DEBUG);
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"Level")) != NULL) {
+ if (!lstrcmpiW(b, LOGL_ERROR))
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
+ else if (!lstrcmpiW(b, LOGL_INFO))
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 1);
+ else if (!lstrcmpiW(b, LOGL_WARN))
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 2);
+ else
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 3);
+ apxFree(b);
+ }
+ else
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 1);
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"Path")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPATH, b);
+ apxFree(b);
+ }
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"Prefix")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, b);
+ apxFree(b);
+ }
+ else
+ SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, L"commons-daemon");
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"PidFile")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPIDFILE, b);
+ apxFree(b);
+ }
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"StdOutput")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, b);
+ apxFree(b);
+ }
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"StdError")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, b);
+ apxFree(b);
+ }
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPLGLEVEL:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGPATH:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGPREFIX:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGPIDFILE:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGSTDERR:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGSTDOUT:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGBPATH:
+ lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_LGPATHTITLE, 0),
+ NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPATH, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGBSTDOUT:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDOUT, 0),
+ apxLoadResourceW(IDS_ALLFILES, 1), NULL,
+ NULL, FALSE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGBSTDERR:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDERR, 0),
+ apxLoadResourceW(IDS_ALLFILES, 1), NULL,
+ NULL, FALSE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalLoggingSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 3);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __jvmProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf, b;
+ DWORD v;
+ CHAR bn[32];
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ startPage = 3;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Jvm")) != NULL) {
+ if (!lstrcmpiW(lpBuf, L"auto")) {
+ CheckDlgButton(hDlg, IDC_PPJAUTO, BST_CHECKED);
+ apxFree(lpBuf);
+ lpBuf = apxGetJavaSoftRuntimeLib(hPool);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
+ }
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+ apxFree(lpBuf);
+ }
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Classpath")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Options", NULL, NULL)) != NULL) {
+ LPWSTR p = apxMszToCRLFW(hPool, lpBuf);
+ SetDlgItemTextW(hDlg, IDC_PPJOPTIONS, p);
+ apxFree(lpBuf);
+ apxFree(p);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"JvmMs");
+ if (v && v != 0xFFFFFFFF) {
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPJMS, bn);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"JvmMx");
+ if (v && v != 0xFFFFFFFF) {
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPJMX, bn);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"JvmSs");
+ if (v && v != 0xFFFFFFFF) {
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPJSS, bn);
+ }
+
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPJBJVM:
+ b = apxGetJavaSoftHome(hPool, TRUE);
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPJBJVM, 0),
+ apxLoadResourceW(IDS_DLLFILES, 1), NULL,
+ b,
+ TRUE, NULL);
+ apxFree(b);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 4);
+ }
+ break;
+ case IDC_PPJAUTO:
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 4);
+ if (IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
+ lpBuf = apxGetJavaSoftRuntimeLib(hPool);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+ apxFree(lpBuf);
+ }
+ }
+ else {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), TRUE);
+ }
+ break;
+ case IDC_PPJJVM:
+ case IDC_PPJCLASSPATH:
+ case IDC_PPJOPTIONS:
+ case IDC_PPJMX:
+ case IDC_PPJMS:
+ case IDC_PPJSS:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 4);
+ }
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalJvmSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 4);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __startProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf, b;
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ startPage = 4;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"exe");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"jvm");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), _s_java);
+
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Class")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRCLASS, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Image")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"WorkingPath")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Method")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRMETHOD, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Params", NULL, NULL)) != NULL) {
+ b = apxMszToCRLFW(hPool, lpBuf);
+ SetDlgItemTextW(hDlg, IDC_PPRARGS, b);
+ apxFree(lpBuf);
+ apxFree(b);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Mode")) != NULL) {
+ if (!lstrcmpiW(lpBuf, L"jvm")) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 1);
+
+ }
+ else if (!lstrcmpiW(lpBuf, _s_java)) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 2);
+ }
+ else {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 0);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
+ }
+ apxFree(lpBuf);
+ }
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPRBWPATH:
+ lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
+ NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ }
+ break;
+ case IDC_PPRBIMAGE:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
+ apxLoadResourceW(IDS_EXEFILES, 1), NULL,
+ NULL, TRUE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ }
+ break;
+ case IDC_PPRCLASS:
+ case IDC_PPRMETHOD:
+ case IDC_PPRARGS:
+ case IDC_PPRIMAGE:
+ case IDC_PPRWPATH:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ }
+ break;
+ case IDC_PPRMODE:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPRMODE))) {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), FALSE);
+ }
+ else {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
+ }
+ }
+ break;
+
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalStartSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 5);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __stopProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf, b;
+ DWORD v;
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ startPage = 5;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"exe");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"jvm");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), _s_java);
+
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Class")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSCLASS, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Image")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"WorkingPath")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Method")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSMETHOD, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Params", NULL, NULL)) != NULL) {
+ b = apxMszToCRLFW(hPool, lpBuf);
+ SetDlgItemTextW(hDlg, IDC_PPSARGS, b);
+ apxFree(lpBuf);
+ apxFree(b);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Timeout");
+ {
+ CHAR bn[32];
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPSTIMEOUT, bn);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Mode")) != NULL) {
+ if (!lstrcmpiW(lpBuf, L"jvm")) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 1);
+
+ }
+ else if (!lstrcmpiW(lpBuf, _s_java)) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 2);
+ }
+ else {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 0);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
+ }
+ apxFree(lpBuf);
+ }
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPSBWPATH:
+ lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
+ NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ }
+ break;
+ case IDC_PPSBIMAGE:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
+ apxLoadResourceW(IDS_EXEFILES, 1), NULL,
+ NULL, TRUE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ }
+ break;
+ case IDC_PPSCLASS:
+ case IDC_PPSMETHOD:
+ case IDC_PPSTIMEOUT:
+ case IDC_PPSARGS:
+ case IDC_PPSIMAGE:
+ case IDC_PPSWPATH:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ }
+ break;
+ case IDC_PPSMODE:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSMODE))) {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), FALSE);
+ }
+ else {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
+ }
+ }
+ break;
+
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalStopSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 6);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+void __initPpage(PROPSHEETPAGEW *lpPage, INT iDlg, INT iTitle, DLGPROC pfnDlgProc)
+{
+ lpPage->dwSize = sizeof(PROPSHEETPAGE);
+ lpPage->dwFlags = PSP_USETITLE;
+ lpPage->hInstance = _gui_store->hInstance;
+ lpPage->pszTemplate = MAKEINTRESOURCEW(iDlg);
+ lpPage->pszIcon = NULL;
+ lpPage->pfnDlgProc = pfnDlgProc;
+ lpPage->pszTitle = MAKEINTRESOURCEW(iTitle);
+ lpPage->lParam = 0;
+}
+
+void ShowServiceProperties(HWND hWnd)
+{
+ PROPSHEETPAGEW psP[6];
+ PROPSHEETHEADERW psH;
+ WCHAR szT[SIZ_DESLEN] = {0};
+
+ if (_propertyOpened) {
+ SetForegroundWindow(_gui_store->hMainWnd);
+ return;
+ }
+ __initPpage(&psP[0], IDD_PROPPAGE_SGENERAL, IDS_PPGENERAL,
+ __generalProperty);
+ __initPpage(&psP[1], IDD_PROPPAGE_LOGON, IDS_PPLOGON,
+ __logonProperty);
+ __initPpage(&psP[2], IDD_PROPPAGE_LOGGING, IDS_PPLOGGING,
+ __loggingProperty);
+ __initPpage(&psP[3], IDD_PROPPAGE_JVM, IDS_PPJAVAVM,
+ __jvmProperty);
+ __initPpage(&psP[4], IDD_PROPPAGE_START, IDS_PPSTART,
+ __startProperty);
+ __initPpage(&psP[5], IDD_PROPPAGE_STOP, IDS_PPSTOP,
+ __stopProperty);
+
+ if (_currentEntry && _currentEntry->lpConfig)
+ lstrlcpyW(szT, SIZ_DESMAX, _currentEntry->lpConfig->lpDisplayName);
+ else
+ return;
+ lstrlcatW(szT, SIZ_DESMAX, L" Properties");
+
+ psH.dwSize = sizeof(PROPSHEETHEADER);
+ psH.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
+ psH.hwndParent = bEnableTry ? hWnd : NULL;
+ psH.hInstance = _gui_store->hInstance;
+ psH.pszIcon = MAKEINTRESOURCEW(IDI_MAINICON);
+ psH.pszCaption = szT;
+ psH.nPages = 6;
+ psH.ppsp = (LPCPROPSHEETPAGEW) &psP;
+ psH.pfnCallback = (PFNPROPSHEETCALLBACK)__propertyCallback;
+ psH.nStartPage = startPage;
+
+ PropertySheetW(&psH);
+ _propertyOpened = FALSE;
+ if (!bEnableTry)
+ PostQuitMessage(0);
+ bpropCentered = FALSE;
+
+}
+
+static void signalService(LPCWSTR szServiceName)
+{
+ HANDLE event;
+ WCHAR en[SIZ_DESLEN];
+ int i;
+
+ lstrlcpyW(en, SIZ_DESLEN, L"Global\\");
+ lstrlcatW(en, SIZ_DESLEN, szServiceName);
+ lstrlcatW(en, SIZ_DESLEN, L"SIGNAL");
+ for (i = 7; i < lstrlenW(en); i++) {
+ if (en[i] >= L'a' && en[i] <= L'z')
+ en[i] = en[i] - 32;
+ }
+
+
+ event = OpenEventW(EVENT_MODIFY_STATE, FALSE, en);
+ if (event) {
+ SetEvent(event);
+ CloseHandle(event);
+ }
+ else
+ apxDisplayError(TRUE, NULL, 0, "Unable to open the Event Mutex");
+
+}
+
+LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
+ case WM_CREATE:
+ if (bEnableTry) {
+ if (_currentEntry && _currentEntry->lpConfig) {
+ BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
+ apxManageTryIconW(hWnd, NIM_ADD, NULL,
+ _currentEntry->lpConfig->lpDisplayName,
+ isRunning ? hIcoRun : hIcoStop);
+ }
+ else {
+ apxManageTryIconA(hWnd, NIM_ADD, NULL,
+ apxLoadResourceA(IDS_APPLICATION, 0),
+ NULL);
+ }
+ }
+ else
+ ShowServiceProperties(hWnd);
+
+ break;
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDM_TM_CONFIG:
+ ShowServiceProperties(hWnd);
+ break;
+ case IDM_TM_ABOUT:
+ apxAboutBox(hWnd);
+ break;
+ case IDM_TM_EXIT:
+ SendMessage(hWnd, WM_CLOSE, 0, 0);
+ break;
+ case IDM_TM_START:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSSTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __startServiceCallback, NULL);
+ break;
+ case IDM_TM_STOP:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSSTOP, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __stopServiceCallback, NULL);
+ break;
+ case IDM_TM_PAUSE:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSPAUSE, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __pauseServiceCallback, NULL);
+ break;
+ case IDM_TM_RESTART:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSRESTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __restartServiceCallback, NULL);
+ break;
+ case IDM_TM_DUMP:
+ signalService(_currentEntry->szServiceName);
+ break;
+ case IDMS_REFRESH:
+ if (bEnableTry &&
+ (_currentEntry = apxServiceEntry(hService, TRUE)) != NULL) {
+ BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
+ apxManageTryIconW(hWnd, NIM_MODIFY, NULL,
+ _currentEntry->lpConfig->lpDisplayName,
+ isRunning ? hIcoRun : hIcoStop);
+ }
+ break;
+
+ }
+ break;
+ case WM_TRAYMESSAGE:
+ switch(lParam) {
+ case WM_LBUTTONDBLCLK:
+ ShowServiceProperties(hWnd);
+ break;
+ case WM_RBUTTONUP:
+ _currentEntry = apxServiceEntry(hService, TRUE);
+ createRbuttonTryMenu(hWnd);
+ break;
+ }
+ break;
+ case WM_QUIT:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ break;
+ case WM_DESTROY:
+ if (bEnableTry)
+ apxManageTryIconA(hWnd, NIM_DELETE, NULL, NULL, NULL);
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ break;
+ }
+
+ return FALSE;
+}
+
+static BOOL loadConfiguration()
+{
+ return TRUE;
+}
+
+static BOOL saveConfiguration()
+{
+ return TRUE;
+}
+
+/* Main program entry
+ * Since we are inependant from CRT
+ * the arguments are not used
+ */
+#ifdef _NO_CRTLIBRARY
+int xMain(void)
+#else
+int WINAPI WinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow)
+#endif
+{
+ MSG msg;
+ LPAPXCMDLINE lpCmdline;
+ HANDLE mutex = NULL;
+ BOOL quiet = FALSE;
+
+ apxHandleManagerInitialize();
+ hPool = apxPoolCreate(NULL, 0);
+
+ /* Parse the command line */
+ if ((lpCmdline = apxCmdlineParse(hPool, _options, _commands)) == NULL) {
+ /* TODO: dispalay error message */
+ apxDisplayError(TRUE, NULL, 0, "Error parsing command line");
+ goto cleanup;
+ }
+
+ if (!lpCmdline->dwCmdIndex) {
+ /* Skip sytem error message */
+ SetLastError(ERROR_SUCCESS);
+ apxDisplayError(TRUE, NULL, 0,
+ apxLoadResourceA(IDS_ERRORCMD, 0),
+ lpCmdLine);
+ goto cleanup;
+ }
+ else if (lpCmdline->dwCmdIndex == 4)
+ quiet = TRUE;
+ else if (lpCmdline->dwCmdIndex >= 2)
+ bEnableTry = TRUE;
+ hService = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to open the Service Manager");
+ goto cleanup;
+ }
+ /* Open the main service handle */
+ if (!apxServiceOpen(hService, lpCmdline->szApplication,
+ SERVICE_ALL_ACCESS)) {
+ LPWSTR w = lpCmdline->szApplication + lstrlenW(lpCmdline->szApplication) - 1;
+ if (*w == L'w')
+ *w = L'\0';
+ if (!apxServiceOpen(hService, lpCmdline->szApplication,
+ SERVICE_ALL_ACCESS)) {
+ if (!apxServiceOpen(hService, lpCmdline->szApplication,
+ GENERIC_READ | GENERIC_EXECUTE)) {
+
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to open the service '%S'",
+ lpCmdline->szApplication);
+ goto cleanup;
+ }
+ }
+ }
+ /* Obtain service parameters and status */
+ if (!(_currentEntry = apxServiceEntry(hService, TRUE))) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to query the service '%S' status",
+ lpCmdline->szApplication);
+ goto cleanup;
+ }
+#ifdef _UNICODE
+ _gui_store = apxGuiInitialize(MainWndProc, lpCmdline->szApplication);
+#else
+ {
+ CHAR szApp[MAX_PATH];
+ _gui_store = apxGuiInitialize(MainWndProc,
+ WideToAscii(lpCmdline->szApplication, szApp));
+ }
+#endif
+ if (!_gui_store) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to initialize GUI manager");
+ goto cleanup;
+ }
+ hIcoRun = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONRUN),
+ IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ hIcoStop = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONSTOP),
+ IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+
+ /* Handle //MQ// option */
+ if (lpCmdline->dwCmdIndex == 4) {
+ HANDLE hOther = FindWindow(_gui_store->szWndClass, NULL);
+ if (hOther)
+ SendMessage(hOther, WM_CLOSE, 0, 0);
+ goto cleanup;
+ }
+
+ if (!_options[0].dwValue) {
+ mutex = CreateMutex(NULL, FALSE, _gui_store->szWndMutex);
+ if ((mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
+ /* Skip sytem error message */
+ SetLastError(ERROR_SUCCESS);
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ALREAY_RUNING, 0),
+ lpCmdline->szApplication);
+ goto cleanup;
+ }
+ }
+ hRegistry = apxCreateRegistry(hPool, KEY_ALL_ACCESS, NULL,
+ apxLoadResource(IDS_APPLICATION, 0),
+ APXREG_USER);
+ loadConfiguration();
+ hRegserv = apxCreateRegistryW(hPool, KEY_READ | KEY_WRITE | KREG_WOW6432,
+ PRG_REGROOT,
+ lpCmdline->szApplication,
+ APXREG_SOFTWARE | APXREG_SERVICE);
+
+ if (IS_INVALID_HANDLE(hRegserv)) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ERRSREG, 0));
+ return FALSE;
+ }
+ /* Create main invisible window */
+ _gui_store->hMainWnd = CreateWindow(_gui_store->szWndClass,
+ apxLoadResource(IDS_APPLICATION, 0),
+ 0, 0, 0, 0, 0,
+ NULL, NULL,
+ _gui_store->hInstance,
+ NULL);
+
+ if (!_gui_store->hMainWnd) {
+ goto cleanup;
+ }
+ if (lpCmdline->dwCmdIndex == 3)
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, IDM_TM_START, 0);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ if(!TranslateAccelerator(_gui_store->hMainWnd,
+ _gui_store->hAccel, &msg)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ saveConfiguration();
+
+cleanup:
+ if (hIcoStop)
+ DestroyIcon(hIcoStop);
+ if (hIcoRun)
+ DestroyIcon(hIcoRun);
+ if (mutex)
+ CloseHandle(mutex);
+ if (lpCmdline)
+ apxCmdlineFree(lpCmdline);
+ apxCloseHandle(hService);
+ apxHandleManagerDestroy();
+ ExitProcess(0);
+ return 0;
+}
+
Deleted: tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.h
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.h 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,141 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* ====================================================================
- *
- * Contributed by Mladen Turk <mturk(a)apache.org>
- * 05 Aug 2003
- * ====================================================================
- */
-
-#ifndef _PRUNMGR_H
-#define _PRUNMGR_H
-
-#undef PRG_VERSION
-#define PRG_VERSION "2.0.4.1"
-#define CSV_VERSION 2,0,4,1
-#define PRG_REGROOT L"JBoss\\JBoss Web 2"
-
-#define IDM_TM_EXIT 2000
-#define IDM_TM_START 2001
-#define IDM_TM_STOP 2002
-#define IDM_TM_PAUSE 2003
-#define IDM_TM_RESTART 2004
-#define IDM_TM_CONFIG 2005
-#define IDM_TM_ABOUT 2006
-#define IDM_TM_DUMP 2007
-
-#define IDMS_REFRESH 2020
-
-#define IDI_ICONSTOP 2030
-#define IDI_ICONRUN 2031
-
-
-
-/* Property pages */
-
-#define IDD_PROPPAGE_SGENERAL 2600
-#define IDC_PPSGNAME 2601
-#define IDC_PPSGDISP 2602
-#define IDC_PPSGDESC 2603
-#define IDC_PPSGDEXE 2604
-#define IDC_PPSGCMBST 2605
-#define IDC_PPSGSTATUS 2606
-#define IDC_PPSGSTART 2607
-#define IDC_PPSGSTOP 2608
-#define IDC_PPSGPAUSE 2609
-#define IDC_PPSGRESTART 2610
-
-#define IDD_PROPPAGE_LOGON 2620
-#define IDC_PPSLLS 2621
-#define IDC_PPSLID 2622
-#define IDC_PPSLUA 2623
-#define IDC_PPSLUSER 2624
-#define IDC_PPSLBROWSE 2625
-#define IDC_PPSLPASS 2626
-#define IDC_PPSLCPASS 2627
-#define IDL_PPSLPASS 2628
-#define IDL_PPSLCPASS 2629
-
-#define IDD_PROPPAGE_LOGGING 2640
-#define IDC_PPLGLEVEL 2641
-#define IDC_PPLGPATH 2642
-#define IDC_PPLGBPATH 2643
-#define IDC_PPLGPREFIX 2644
-#define IDC_PPLGSTDOUT 2645
-#define IDC_PPLGBSTDOUT 2646
-#define IDC_PPLGSTDERR 2647
-#define IDC_PPLGBSTDERR 2648
-
-#define IDD_PROPPAGE_JVM 2660
-#define IDC_PPJAUTO 2661
-#define IDC_PPJJVM 2662
-#define IDC_PPJBJVM 2663
-#define IDC_PPJCLASSPATH 2664
-#define IDC_PPJOPTIONS 2665
-#define IDC_PPJMS 2666
-#define IDC_PPJMX 2667
-#define IDC_PPJSS 2668
-
-#define IDD_PROPPAGE_START 2680
-#define IDC_PPRCLASS 2681
-#define IDC_PPRIMAGE 2682
-#define IDC_PPRBIMAGE 2683
-#define IDC_PPRWPATH 2684
-#define IDC_PPRBWPATH 2685
-#define IDC_PPRMETHOD 2686
-#define IDC_PPRARGS 2687
-#define IDC_PPRTIMEOUT 2688
-#define IDC_PPRMODE 2689
-
-#define IDD_PROPPAGE_STOP 2700
-#define IDC_PPSCLASS 2701
-#define IDC_PPSIMAGE 2702
-#define IDC_PPSBIMAGE 2703
-#define IDC_PPSWPATH 2704
-#define IDC_PPSBWPATH 2705
-#define IDC_PPSMETHOD 2706
-#define IDC_PPSARGS 2707
-#define IDC_PPSTIMEOUT 2708
-#define IDC_PPSMODE 2709
-
-#define IDS_ALREAY_RUNING 3100
-#define IDS_ERRORCMD 3101
-#define IDS_HSSTART 3102
-#define IDS_HSSTOP 3103
-#define IDS_HSPAUSE 3104
-#define IDS_HSRESTART 3105
-#define IDS_VALIDPASS 3106
-#define IDS_PPGENERAL 3107
-#define IDS_PPLOGON 3108
-#define IDS_PPLOGGING 3109
-#define IDS_PPJAVAVM 3110
-#define IDS_PPSTART 3111
-#define IDS_PPSTOP 3112
-#define IDS_LGPATHTITLE 3113
-#define IDS_ALLFILES 3114
-#define IDS_DLLFILES 3115
-#define IDS_EXEFILES 3116
-#define IDS_LGSTDERR 3117
-#define IDS_LGSTDOUT 3118
-#define IDS_PPJBJVM 3119
-#define IDS_PPWPATH 3120
-#define IDS_PPIMAGE 3121
-#define IDS_ERRSREG 3122
-
-#define IDS_NOTIMPLEMENTED 3199
-
-#endif /* _PRUNMGR_H */
Copied: tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.h (from rev 2689, trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.h (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.h 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,141 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ *
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+#ifndef _PRUNMGR_H
+#define _PRUNMGR_H
+
+#undef PRG_VERSION
+#define PRG_VERSION "2.0.5.1"
+#define CSV_VERSION 2,0,5,1
+#define PRG_REGROOT L"JBoss\\JBoss Web 2"
+
+#define IDM_TM_EXIT 2000
+#define IDM_TM_START 2001
+#define IDM_TM_STOP 2002
+#define IDM_TM_PAUSE 2003
+#define IDM_TM_RESTART 2004
+#define IDM_TM_CONFIG 2005
+#define IDM_TM_ABOUT 2006
+#define IDM_TM_DUMP 2007
+
+#define IDMS_REFRESH 2020
+
+#define IDI_ICONSTOP 2030
+#define IDI_ICONRUN 2031
+
+
+
+/* Property pages */
+
+#define IDD_PROPPAGE_SGENERAL 2600
+#define IDC_PPSGNAME 2601
+#define IDC_PPSGDISP 2602
+#define IDC_PPSGDESC 2603
+#define IDC_PPSGDEXE 2604
+#define IDC_PPSGCMBST 2605
+#define IDC_PPSGSTATUS 2606
+#define IDC_PPSGSTART 2607
+#define IDC_PPSGSTOP 2608
+#define IDC_PPSGPAUSE 2609
+#define IDC_PPSGRESTART 2610
+
+#define IDD_PROPPAGE_LOGON 2620
+#define IDC_PPSLLS 2621
+#define IDC_PPSLID 2622
+#define IDC_PPSLUA 2623
+#define IDC_PPSLUSER 2624
+#define IDC_PPSLBROWSE 2625
+#define IDC_PPSLPASS 2626
+#define IDC_PPSLCPASS 2627
+#define IDL_PPSLPASS 2628
+#define IDL_PPSLCPASS 2629
+
+#define IDD_PROPPAGE_LOGGING 2640
+#define IDC_PPLGLEVEL 2641
+#define IDC_PPLGPATH 2642
+#define IDC_PPLGBPATH 2643
+#define IDC_PPLGPREFIX 2644
+#define IDC_PPLGSTDOUT 2645
+#define IDC_PPLGBSTDOUT 2646
+#define IDC_PPLGSTDERR 2647
+#define IDC_PPLGBSTDERR 2648
+
+#define IDD_PROPPAGE_JVM 2660
+#define IDC_PPJAUTO 2661
+#define IDC_PPJJVM 2662
+#define IDC_PPJBJVM 2663
+#define IDC_PPJCLASSPATH 2664
+#define IDC_PPJOPTIONS 2665
+#define IDC_PPJMS 2666
+#define IDC_PPJMX 2667
+#define IDC_PPJSS 2668
+
+#define IDD_PROPPAGE_START 2680
+#define IDC_PPRCLASS 2681
+#define IDC_PPRIMAGE 2682
+#define IDC_PPRBIMAGE 2683
+#define IDC_PPRWPATH 2684
+#define IDC_PPRBWPATH 2685
+#define IDC_PPRMETHOD 2686
+#define IDC_PPRARGS 2687
+#define IDC_PPRTIMEOUT 2688
+#define IDC_PPRMODE 2689
+
+#define IDD_PROPPAGE_STOP 2700
+#define IDC_PPSCLASS 2701
+#define IDC_PPSIMAGE 2702
+#define IDC_PPSBIMAGE 2703
+#define IDC_PPSWPATH 2704
+#define IDC_PPSBWPATH 2705
+#define IDC_PPSMETHOD 2706
+#define IDC_PPSARGS 2707
+#define IDC_PPSTIMEOUT 2708
+#define IDC_PPSMODE 2709
+
+#define IDS_ALREAY_RUNING 3100
+#define IDS_ERRORCMD 3101
+#define IDS_HSSTART 3102
+#define IDS_HSSTOP 3103
+#define IDS_HSPAUSE 3104
+#define IDS_HSRESTART 3105
+#define IDS_VALIDPASS 3106
+#define IDS_PPGENERAL 3107
+#define IDS_PPLOGON 3108
+#define IDS_PPLOGGING 3109
+#define IDS_PPJAVAVM 3110
+#define IDS_PPSTART 3111
+#define IDS_PPSTOP 3112
+#define IDS_LGPATHTITLE 3113
+#define IDS_ALLFILES 3114
+#define IDS_DLLFILES 3115
+#define IDS_EXEFILES 3116
+#define IDS_LGSTDERR 3117
+#define IDS_LGSTDOUT 3118
+#define IDS_PPJBJVM 3119
+#define IDS_PPWPATH 3120
+#define IDS_PPIMAGE 3121
+#define IDS_ERRSREG 3122
+
+#define IDS_NOTIMPLEMENTED 3199
+
+#endif /* _PRUNMGR_H */
Deleted: tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.rc
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.rc 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,296 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "prunmgr.h"
-
-#define RSTR_SCMATS "Service Manager is attempting to "
-
-#define STR_COPYRIGHT "Copyright � 2008 Red Hat Middleware, LLC. " \
- "or its licensors, as applicable."
-
-#define STR_LICENSE "Distributable under LGPL license. " \
- "See terms of license at gnu.org."
-
-#define STR_COMPANY "Red Hat�, Inc."
-#define STR_TRADEMARK "� Red Hat Inc."
-#define STR_PRODUCT "JBoss Web Service manager"
-
-IDI_MAINICON ICON "../../resources/jboss.ico"
-IDI_REDHATICON ICON "../../resources/redhat.ico"
-IDI_ICONSTOP ICON "../../resources/procruns.ico"
-IDI_ICONRUN ICON "../../resources/procrunr.ico"
-IDR_LICENSE RTF "../../resources/license.rtf"
-BMP_JBOSSLOGO BITMAP "../../resources/jbosslogo.bmp"
-
-CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "prunmgr.manifest"
-
-IDD_ABOUTBOX DIALOGEX 0, 0, 337, 187
-STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
-CAPTION "JBoss Web Service Manager"
-FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
-BEGIN
- DEFPUSHBUTTON "&OK",IDOK,285,150,50,14
- CONTROL "",IDC_LICENSE,"RichEdit20A",ES_MULTILINE |
- ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
- CONTROL "BMP_JBOSSLOGO",IDC_STATIC,"Static",SS_BITMAP|0x00000040L,0,0,337,30
- LTEXT " ",IDC_ABOUTAPP,2,150,270,12
- LTEXT "Copyright � 2008 Red Hat Middleware, LLC.",IDC_STATIC,2,160,270,12
- LTEXT "http://www.jboss.org",IDC_STATIC,2,170,270,12
- PUSHBUTTON "&System Info",IAB_SYSINF,285,170,50,14
-END
-
-IDD_PROGRESS DIALOGEX 0, 0, 322, 92
-STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP |
- WS_CAPTION | WS_SYSMENU
-EXSTYLE WS_EX_TOPMOST
-CAPTION "JBoss Web Service Manager"
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
- DEFPUSHBUTTON "Cl&ose",IDOK,261,73,50,14
- PUSHBUTTON "&Cancel",IDCANCEL,202,73,50,14
- LTEXT " ",
- IDDP_HEAD,40,4,250,8
- LTEXT " ",IDDP_TEXT,40,15,250,44
- CONTROL "",IDDP_PROGRESS,"msctls_progress32",WS_BORDER,10,50,302,
- 14
- ICON IDI_MAINICON,IDC_STATIC,10,4,20,20,0,WS_EX_TRANSPARENT
-END
-
-IDD_SELUSER DIALOGEX 0, 0, 410, 201
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU |
- WS_THICKFRAME
-EXSTYLE WS_EX_CONTEXTHELP
-CAPTION "Select User"
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
- LTEXT "Name:",IDSU_SELNAME,10,183,22,8
- EDITTEXT IDSU_SELECTED,48,200,213,14,ES_AUTOHSCROLL
- DEFPUSHBUTTON "OK",IDOK,292,180,50,14,WS_DISABLED
- PUSHBUTTON "Cancel",IDCANCEL,348,180,50,14
- LTEXT "Look In:",IDC_STATIC,10,9,27,8
- CONTROL "",IDSU_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL |
- LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER |
- WS_TABSTOP,0,26,410,149,WS_EX_CLIENTEDGE
- CONTROL "",IDSU_COMBO,"ComboBoxEx32",CBS_DROPDOWNLIST |
- WS_VSCROLL | WS_TABSTOP,47,6,260,80
-END
-
-IDD_PROPPAGE_SGENERAL DIALOGEX 0, 0, 260, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- LTEXT "Service Name: ",IDC_STATIC,10,8,52,8
- LTEXT " ",IDC_PPSGNAME,70,8,240,8
- LTEXT "Display &name: ",IDC_STATIC,10,23,50,8
- EDITTEXT IDC_PPSGDISP,70,22,180,12,ES_AUTOHSCROLL
- LTEXT "&Description: ",IDC_STATIC,10,41,43,8
- EDITTEXT IDC_PPSGDESC,70,40,180,12,ES_AUTOHSCROLL
- LTEXT "Pat&h to executable:",IDC_STATIC,10,63,66,8
- EDITTEXT IDC_PPSGDEXE,10,75,240,12,ES_AUTOHSCROLL | WS_DISABLED
- LTEXT "Startup typ&e:",IDC_STATIC,10,94,46,8
- COMBOBOX IDC_PPSGCMBST,70,93,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
- CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,10,128,240,1
- LTEXT "Service Status:",IDC_STATIC,10,138,52,8
- LTEXT " ",IDC_PPSGSTATUS,70,138,240,8
- PUSHBUTTON "&Start",IDC_PPSGSTART,10,160,55,14,WS_DISABLED
- PUSHBUTTON "S&top",IDC_PPSGSTOP,71,160,55,14,WS_DISABLED
- PUSHBUTTON "&Pause",IDC_PPSGPAUSE,132,160,55,14,WS_DISABLED
- PUSHBUTTON "&Restart",IDC_PPSGRESTART,193,160,55,14,WS_DISABLED
-END
-
-IDD_PROPPAGE_LOGON DIALOGEX 0, 0, 260, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- LTEXT "Log on as:",IDC_STATIC,10,8,51,8
- CONTROL "&Local System account",IDC_PPSLLS,"Button",
- BS_AUTORADIOBUTTON,10,23,85,10
- CONTROL "Allo&w service to interact with desktop",IDC_PPSLID,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,37,135,10
- CONTROL "&This account:",IDC_PPSLUA,"Button",BS_AUTORADIOBUTTON,
- 10,59,61,10
- EDITTEXT IDC_PPSLUSER,86,58,114,12,ES_AUTOHSCROLL
- PUSHBUTTON "&Browse...",IDC_PPSLBROWSE,205,57,50,14
- LTEXT "&Password:",IDL_PPSLPASS,21,76,36,8
- EDITTEXT IDC_PPSLPASS,86,75,114,12,ES_PASSWORD | ES_AUTOHSCROLL
- LTEXT "&Confirm Password:",IDL_PPSLCPASS,20,93,63,8
- EDITTEXT IDC_PPSLCPASS,86,92,114,12,ES_PASSWORD | ES_AUTOHSCROLL
-END
-
-IDD_PROPPAGE_LOGGING DIALOGEX 0, 0, 260, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- LTEXT "&Level:",IDC_STATIC,10,18,46,8
- COMBOBOX IDC_PPLGLEVEL,70,17,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
- LTEXT "Log &path: ",IDC_STATIC,10,33,50,8
- EDITTEXT IDC_PPLGPATH,10,45,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPLGBPATH,232,44,18,14
- LTEXT "Log prefix: ",IDC_STATIC,10,63,50,8
- EDITTEXT IDC_PPLGPREFIX,70,62,158,12,ES_AUTOHSCROLL
-
- LTEXT "Redirect Stdout: ",IDC_STATIC,10,85,80,8
- EDITTEXT IDC_PPLGSTDOUT,10,97,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPLGBSTDOUT,232,96,18,14
- LTEXT "Redirect Stderror: ",IDC_STATIC,10,115,80,8
- EDITTEXT IDC_PPLGSTDERR,10,127,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPLGBSTDERR,232,126,18,14
-END
-
-IDD_PROPPAGE_JVM DIALOGEX 0, 0, 260, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- CONTROL " Use default",IDC_PPJAUTO,"Button",BS_AUTOCHECKBOX |
- WS_TABSTOP,10,8,72,12
- LTEXT "Java Virtual Machine: ",IDC_STATIC,10,23,80,8
- EDITTEXT IDC_PPJJVM,10,35,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPJBJVM,232,34,18,14
- LTEXT "Java Classpath:",IDC_STATIC,10,53,66,8
- EDITTEXT IDC_PPJCLASSPATH,10,65,240,12,ES_AUTOHSCROLL
- LTEXT "Java Options:",IDC_STATIC,10,83,66,8
- EDITTEXT IDC_PPJOPTIONS,10,95,240,40,ES_MULTILINE | ES_AUTOHSCROLL |
- ES_WANTRETURN | WS_VSCROLL
- LTEXT "Initial memory pool:",IDC_STATIC,10,140,80,8
- EDITTEXT IDC_PPJMS,90,139,100,12,ES_AUTOHSCROLL | ES_NUMBER
- LTEXT "MB",IDC_STATIC,195,140,25,8
- LTEXT "Maximum memory pool:",IDC_STATIC,10,156,80,8
- EDITTEXT IDC_PPJMX,90,155,100,12,ES_AUTOHSCROLL | ES_NUMBER
- LTEXT "MB",IDC_STATIC,195,156,25,8
- LTEXT "Thread stack size:",IDC_STATIC,10,172,80,8
- EDITTEXT IDC_PPJSS,90,171,100,12,ES_AUTOHSCROLL | ES_NUMBER
- LTEXT "KB",IDC_STATIC,195,172,25,8
-END
-
-IDD_PROPPAGE_START DIALOGEX 0, 0, 260, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- LTEXT "&Class: ",IDC_STATIC,10,8,50,8
- EDITTEXT IDC_PPRCLASS,10,20,240,12,ES_AUTOHSCROLL
- LTEXT "Image: ",IDC_STATIC,10,38,80,8
- EDITTEXT IDC_PPRIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
- PUSHBUTTON "...",IDC_PPRBIMAGE,232,49,18,14,WS_DISABLED
- LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
- EDITTEXT IDC_PPRWPATH,10,80,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPRBWPATH,232,79,18,14
- LTEXT "&Method: ",IDC_STATIC,10,98,50,8
- EDITTEXT IDC_PPRMETHOD,70,97,180,12,ES_AUTOHSCROLL
- LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
- EDITTEXT IDC_PPRARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
- ES_WANTRETURN | WS_VSCROLL
- LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
- EDITTEXT IDC_PPRTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | WS_DISABLED
- LTEXT "sec.",IDC_STATIC,175,150,25,8
- LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
- COMBOBOX IDC_PPRMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
-END
-
-IDD_PROPPAGE_STOP DIALOGEX 0, 0, 260, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- LTEXT "&Class: ",IDC_STATIC,10,8,50,8
- EDITTEXT IDC_PPSCLASS,10,20,240,12,ES_AUTOHSCROLL
- LTEXT "Image: ",IDC_STATIC,10,38,80,8
- EDITTEXT IDC_PPSIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
- PUSHBUTTON "...",IDC_PPSBIMAGE,232,49,18,14,WS_DISABLED
- LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
- EDITTEXT IDC_PPSWPATH,10,80,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPSBWPATH,232,79,18,14
- LTEXT "&Method: ",IDC_STATIC,10,98,50,8
- EDITTEXT IDC_PPSMETHOD,70,97,180,12,ES_AUTOHSCROLL
- LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
- EDITTEXT IDC_PPSARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
- ES_WANTRETURN | WS_VSCROLL
- LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
- EDITTEXT IDC_PPSTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | ES_NUMBER
- LTEXT "sec.",IDC_STATIC,175,150,25,8
- LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
- COMBOBOX IDC_PPSMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
- WS_TABSTOP
-END
-
-STRINGTABLE
-BEGIN
- IDS_APPLICATION STR_PRODUCT
- IDS_APPVERSION "Version 2.0.4"
- IDS_APPFULLNAME STR_PRODUCT " Version " PRG_VERSION
- IDS_APPCOPYRIGHT "Copyright � 2008 Red Hat Middleware, LLC."
- IDS_APPDESCRIPTION "JBoss Web Service Management Tool"
- IDS_ALREAY_RUNING "An instance of '%S' application is already running"
- IDS_ERRORCMD "Unknown command line option '%s'\nSee the manual for command line usage."
- IDS_HSSTART RSTR_SCMATS "start the following service ..."
- IDS_HSSTOP RSTR_SCMATS "stop the following service ..."
- IDS_HSRESTART RSTR_SCMATS "to restart the following service ..."
- IDS_HSPAUSE RSTR_SCMATS "to pause the following service ..."
- IDS_VALIDPASS "Please enter a valid password"
- IDS_PPGENERAL "General"
- IDS_PPLOGON "Log On"
- IDS_PPLOGGING "Logging"
- IDS_PPJAVAVM "Java"
- IDS_PPSTART "Startup"
- IDS_PPSTOP "Shutdown"
- IDS_NOTIMPLEMENTED "Sorry, but this feature is not implemented yet"
- IDS_LGPATHTITLE "Select Log root folder"
- IDS_ALLFILES "All Files (*.*)\0*.*\0"
- IDS_DLLFILES "Dynamic Link Libraries (*.dll)\0*.dll\0"
- IDS_EXEFILES "Executables (*.exe)\0*.exe\0"
- IDS_LGSTDOUT "Select Stdoutput filename"
- IDS_LGSTDERR "Select Stderror filename"
- IDS_PPJBJVM "Select Java Virtual Machine DLL"
- IDS_PPWPATH "Select Working path"
- IDS_PPIMAGE "Select Executable Image"
- IDS_ERRSREG "Unable to open the service registry key"
-END
-
-1 VERSIONINFO
- FILEVERSION CSV_VERSION
- PRODUCTVERSION CSV_VERSION
- FILEFLAGSMASK 0x3fL
-#if defined(_DEBUG)
- FILEFLAGS 0x03L
-#else
- FILEFLAGS 0x02L
-#endif
- FILEOS 0x40004L
- FILETYPE 0x1L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904b0"
- BEGIN
- VALUE "Comments", STR_COPYRIGHT "\0"
- VALUE "CompanyName", STR_COMPANY "\0"
- VALUE "FileDescription", STR_PRODUCT "\0"
- VALUE "FileVersion", PRG_VERSION
- VALUE "InternalName", STR_PRODUCT "\0"
- VALUE "LegalCopyright", STR_COPYRIGHT "\0"
- VALUE "OriginalFilename", "jbosswebw.exe\0"
- VALUE "ProductName", STR_PRODUCT "\0"
- VALUE "ProductVersion", PRG_VERSION
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1200
- END
-END
Copied: tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.rc (from rev 2689, trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.rc (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunmgr/prunmgr.rc 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,299 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "prunmgr.h"
+
+#define RSTR_SCMATS "Service Manager is attempting to "
+
+#define STR_COPYRIGHT "Copyright � 2010 Red Hat, Inc. " \
+ "or its licensors, as applicable."
+
+#define STR_LICENSE "Distributable under LGPL license. " \
+ "See terms of license at gnu.org."
+
+#define STR_COMPANY "Red Hat�, Inc."
+#define STR_TRADEMARK "� Red Hat Inc."
+#define STR_PRODUCT "JBoss Web Service manager"
+
+IDI_MAINICON ICON "../../resources/jboss.ico"
+IDI_REDHATICON ICON "../../resources/redhat.ico"
+IDI_ICONSTOP ICON "../../resources/procruns.ico"
+IDI_ICONRUN ICON "../../resources/procrunr.ico"
+IDR_LICENSE RTF "../../resources/license.rtf"
+BMP_JBOSSLOGO BITMAP "../../resources/jbosslogo.bmp"
+
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "prunmgr.manifest"
+
+IDD_ABOUTBOX DIALOGEX 0, 0, 337, 187
+STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
+CAPTION "JBoss Web Service Manager"
+FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
+BEGIN
+ DEFPUSHBUTTON "&OK",IDOK,285,150,50,14
+ CONTROL "",IDC_LICENSE,"RichEdit20A",ES_MULTILINE |
+ ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
+ CONTROL "BMP_JBOSSLOGO",IDC_STATIC,"Static",SS_BITMAP|0x00000040L,0,0,337,30
+ LTEXT " ",IDC_ABOUTAPP,2,150,270,12
+ LTEXT "Copyright � 2008 Red Hat Middleware, LLC.",IDC_STATIC,2,160,270,12
+ LTEXT "http://www.jboss.org",IDC_STATIC,2,170,270,12
+ PUSHBUTTON "&System Info",IAB_SYSINF,285,170,50,14
+END
+
+IDD_PROGRESS DIALOGEX 0, 0, 322, 92
+STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP |
+ WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_TOPMOST
+CAPTION "JBoss Web Service Manager"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "Cl&ose",IDOK,261,73,50,14
+ PUSHBUTTON "&Cancel",IDCANCEL,202,73,50,14
+ LTEXT " ",
+ IDDP_HEAD,40,4,250,8
+ LTEXT " ",IDDP_TEXT,40,15,250,44
+ CONTROL "",IDDP_PROGRESS,"msctls_progress32",WS_BORDER,10,50,302,
+ 14
+ ICON IDI_MAINICON,IDC_STATIC,10,4,20,20,0,WS_EX_TRANSPARENT
+END
+
+IDD_SELUSER DIALOGEX 0, 0, 410, 201
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU |
+ WS_THICKFRAME
+EXSTYLE WS_EX_CONTEXTHELP
+CAPTION "Select User"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "Name:",IDSU_SELNAME,10,183,22,8
+ EDITTEXT IDSU_SELECTED,48,200,213,14,ES_AUTOHSCROLL
+ DEFPUSHBUTTON "OK",IDOK,292,180,50,14,WS_DISABLED
+ PUSHBUTTON "Cancel",IDCANCEL,348,180,50,14
+ LTEXT "Look In:",IDC_STATIC,10,9,27,8
+ CONTROL "",IDSU_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL |
+ LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER |
+ WS_TABSTOP,0,26,410,149,WS_EX_CLIENTEDGE
+ CONTROL "",IDSU_COMBO,"ComboBoxEx32",CBS_DROPDOWNLIST |
+ WS_VSCROLL | WS_TABSTOP,47,6,260,80
+END
+
+IDD_PROPPAGE_SGENERAL DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "Service Name: ",IDC_STATIC,10,8,52,8
+ LTEXT " ",IDC_PPSGNAME,70,8,240,8
+ LTEXT "Display &name: ",IDC_STATIC,10,23,50,8
+ EDITTEXT IDC_PPSGDISP,70,22,180,12,ES_AUTOHSCROLL
+ LTEXT "&Description: ",IDC_STATIC,10,41,43,8
+ EDITTEXT IDC_PPSGDESC,70,40,180,12,ES_AUTOHSCROLL
+ LTEXT "Pat&h to executable:",IDC_STATIC,10,63,66,8
+ EDITTEXT IDC_PPSGDEXE,10,75,240,12,ES_AUTOHSCROLL | WS_DISABLED
+ LTEXT "Startup typ&e:",IDC_STATIC,10,94,46,8
+ COMBOBOX IDC_PPSGCMBST,70,93,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+ CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,10,128,240,1
+ LTEXT "Service Status:",IDC_STATIC,10,138,52,8
+ LTEXT " ",IDC_PPSGSTATUS,70,138,240,8
+ PUSHBUTTON "&Start",IDC_PPSGSTART,10,160,55,14,WS_DISABLED
+ PUSHBUTTON "S&top",IDC_PPSGSTOP,71,160,55,14,WS_DISABLED
+ PUSHBUTTON "&Pause",IDC_PPSGPAUSE,132,160,55,14,WS_DISABLED
+ PUSHBUTTON "&Restart",IDC_PPSGRESTART,193,160,55,14,WS_DISABLED
+END
+
+IDD_PROPPAGE_LOGON DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "Log on as:",IDC_STATIC,10,8,51,8
+ CONTROL "&Local System account",IDC_PPSLLS,"Button",
+ BS_AUTORADIOBUTTON,10,23,85,10
+ CONTROL "Allo&w service to interact with desktop",IDC_PPSLID,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,37,135,10
+ CONTROL "&This account:",IDC_PPSLUA,"Button",BS_AUTORADIOBUTTON,
+ 10,59,61,10
+ EDITTEXT IDC_PPSLUSER,86,58,114,12,ES_AUTOHSCROLL
+ PUSHBUTTON "&Browse...",IDC_PPSLBROWSE,205,57,50,14
+ LTEXT "&Password:",IDL_PPSLPASS,21,76,36,8
+ EDITTEXT IDC_PPSLPASS,86,75,114,12,ES_PASSWORD | ES_AUTOHSCROLL
+ LTEXT "&Confirm Password:",IDL_PPSLCPASS,20,93,63,8
+ EDITTEXT IDC_PPSLCPASS,86,92,114,12,ES_PASSWORD | ES_AUTOHSCROLL
+END
+
+IDD_PROPPAGE_LOGGING DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "&Level:",IDC_STATIC,10,18,46,8
+ COMBOBOX IDC_PPLGLEVEL,70,17,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+ LTEXT "Log &path: ",IDC_STATIC,10,33,50,8
+ EDITTEXT IDC_PPLGPATH,10,45,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBPATH,232,44,18,14
+ LTEXT "Log prefix: ",IDC_STATIC,10,63,50,8
+ EDITTEXT IDC_PPLGPREFIX,70,62,158,12,ES_AUTOHSCROLL
+
+ LTEXT "Pid file: ",IDC_STATIC,10,81,50,8
+ EDITTEXT IDC_PPLGPIDFILE,70,82,158,12,ES_AUTOHSCROLL
+
+ LTEXT "Redirect Stdout: ",IDC_STATIC,10,105,80,8
+ EDITTEXT IDC_PPLGSTDOUT,10,117,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBSTDOUT,232,116,18,14
+ LTEXT "Redirect Stderror: ",IDC_STATIC,10,135,80,8
+ EDITTEXT IDC_PPLGSTDERR,10,147,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBSTDERR,232,146,18,14
+END
+
+IDD_PROPPAGE_JVM DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ CONTROL " Use default",IDC_PPJAUTO,"Button",BS_AUTOCHECKBOX |
+ WS_TABSTOP,10,8,72,12
+ LTEXT "Java Virtual Machine: ",IDC_STATIC,10,23,80,8
+ EDITTEXT IDC_PPJJVM,10,35,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPJBJVM,232,34,18,14
+ LTEXT "Java Classpath:",IDC_STATIC,10,53,66,8
+ EDITTEXT IDC_PPJCLASSPATH,10,65,240,12,ES_AUTOHSCROLL
+ LTEXT "Java Options:",IDC_STATIC,10,83,66,8
+ EDITTEXT IDC_PPJOPTIONS,10,95,240,40,ES_MULTILINE | ES_AUTOHSCROLL |
+ ES_WANTRETURN | WS_VSCROLL
+ LTEXT "Initial memory pool:",IDC_STATIC,10,140,80,8
+ EDITTEXT IDC_PPJMS,90,139,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "MB",IDC_STATIC,195,140,25,8
+ LTEXT "Maximum memory pool:",IDC_STATIC,10,156,80,8
+ EDITTEXT IDC_PPJMX,90,155,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "MB",IDC_STATIC,195,156,25,8
+ LTEXT "Thread stack size:",IDC_STATIC,10,172,80,8
+ EDITTEXT IDC_PPJSS,90,171,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "KB",IDC_STATIC,195,172,25,8
+END
+
+IDD_PROPPAGE_START DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "&Class: ",IDC_STATIC,10,8,50,8
+ EDITTEXT IDC_PPRCLASS,10,20,240,12,ES_AUTOHSCROLL
+ LTEXT "Image: ",IDC_STATIC,10,38,80,8
+ EDITTEXT IDC_PPRIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
+ PUSHBUTTON "...",IDC_PPRBIMAGE,232,49,18,14,WS_DISABLED
+ LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
+ EDITTEXT IDC_PPRWPATH,10,80,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPRBWPATH,232,79,18,14
+ LTEXT "&Method: ",IDC_STATIC,10,98,50,8
+ EDITTEXT IDC_PPRMETHOD,70,97,180,12,ES_AUTOHSCROLL
+ LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
+ EDITTEXT IDC_PPRARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
+ ES_WANTRETURN | WS_VSCROLL
+ LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
+ EDITTEXT IDC_PPRTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | WS_DISABLED
+ LTEXT "sec.",IDC_STATIC,175,150,25,8
+ LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
+ COMBOBOX IDC_PPRMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+END
+
+IDD_PROPPAGE_STOP DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "&Class: ",IDC_STATIC,10,8,50,8
+ EDITTEXT IDC_PPSCLASS,10,20,240,12,ES_AUTOHSCROLL
+ LTEXT "Image: ",IDC_STATIC,10,38,80,8
+ EDITTEXT IDC_PPSIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
+ PUSHBUTTON "...",IDC_PPSBIMAGE,232,49,18,14,WS_DISABLED
+ LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
+ EDITTEXT IDC_PPSWPATH,10,80,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPSBWPATH,232,79,18,14
+ LTEXT "&Method: ",IDC_STATIC,10,98,50,8
+ EDITTEXT IDC_PPSMETHOD,70,97,180,12,ES_AUTOHSCROLL
+ LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
+ EDITTEXT IDC_PPSARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
+ ES_WANTRETURN | WS_VSCROLL
+ LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
+ EDITTEXT IDC_PPSTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "sec.",IDC_STATIC,175,150,25,8
+ LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
+ COMBOBOX IDC_PPSMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+END
+
+STRINGTABLE
+BEGIN
+ IDS_APPLICATION STR_PRODUCT
+ IDS_APPVERSION "Version 2.0.5"
+ IDS_APPFULLNAME STR_PRODUCT " Version " PRG_VERSION
+ IDS_APPCOPYRIGHT "Copyright � 2010 Red Hat, Inc."
+ IDS_APPDESCRIPTION "JBoss Web Service Management Tool"
+ IDS_ALREAY_RUNING "An instance of '%S' application is already running"
+ IDS_ERRORCMD "Unknown command line option '%s'\nSee the manual for command line usage."
+ IDS_HSSTART RSTR_SCMATS "start the following service ..."
+ IDS_HSSTOP RSTR_SCMATS "stop the following service ..."
+ IDS_HSRESTART RSTR_SCMATS "to restart the following service ..."
+ IDS_HSPAUSE RSTR_SCMATS "to pause the following service ..."
+ IDS_VALIDPASS "Please enter a valid password"
+ IDS_PPGENERAL "General"
+ IDS_PPLOGON "Log On"
+ IDS_PPLOGGING "Logging"
+ IDS_PPJAVAVM "Java"
+ IDS_PPSTART "Startup"
+ IDS_PPSTOP "Shutdown"
+ IDS_NOTIMPLEMENTED "Sorry, but this feature is not implemented yet"
+ IDS_LGPATHTITLE "Select Log root folder"
+ IDS_ALLFILES "All Files (*.*)\0*.*\0"
+ IDS_DLLFILES "Dynamic Link Libraries (*.dll)\0*.dll\0"
+ IDS_EXEFILES "Executables (*.exe)\0*.exe\0"
+ IDS_LGSTDOUT "Select Stdoutput filename"
+ IDS_LGSTDERR "Select Stderror filename"
+ IDS_PPJBJVM "Select Java Virtual Machine DLL"
+ IDS_PPWPATH "Select Working path"
+ IDS_PPIMAGE "Select Executable Image"
+ IDS_ERRSREG "Unable to open the service registry key"
+END
+
+1 VERSIONINFO
+ FILEVERSION CSV_VERSION
+ PRODUCTVERSION CSV_VERSION
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", STR_COPYRIGHT "\0"
+ VALUE "CompanyName", STR_COMPANY "\0"
+ VALUE "FileDescription", STR_PRODUCT "\0"
+ VALUE "FileVersion", PRG_VERSION
+ VALUE "InternalName", STR_PRODUCT "\0"
+ VALUE "LegalCopyright", STR_COPYRIGHT "\0"
+ VALUE "OriginalFilename", "jbosswebw.exe\0"
+ VALUE "ProductName", STR_PRODUCT "\0"
+ VALUE "ProductVersion", PRG_VERSION
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
Deleted: tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.c
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,1399 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* ====================================================================
- * prunsrv -- Service Runner.
- * Contributed by Mladen Turk <mturk(a)apache.org>
- * 05 Aug 2003
- * ====================================================================
- */
-
-/* Force the JNI vprintf functions */
-#define _DEBUG_JNI 1
-#include "apxwin.h"
-#include "prunsrv.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <fcntl.h>
-#include <io.h> /* _open_osfhandle */
-
-#ifndef MIN
-#define MIN(a,b) (((a)<(b)) ? (a) : (b))
-#endif
-
-#define STDIN_FILENO 0
-#define STDOUT_FILENO 1
-#define STDERR_FILENO 2
-
-#ifdef WIN64
-#define KREG_WOW6432 KEY_WOW64_32KEY
-#else
-#define KREG_WOW6432 0
-#endif
-
-typedef struct APX_STDWRAP {
- LPCWSTR szLogPath;
- LPCWSTR szStdOutFilename;
- LPCWSTR szStdErrFilename;
- HANDLE hStdOutFile;
- HANDLE hStdErrFile;
- FILE *fpStdOutFile;
- FILE *fpStdErrFile;
- FILE fpStdOutSave;
- FILE fpStdErrSave;
-} APX_STDWRAP;
-
-/* Use static variables instead of #defines */
-static LPCWSTR PRSRV_AUTO = L"auto";
-static LPCWSTR PRSRV_JAVA = L"java";
-static LPCWSTR PRSRV_JVM = L"jvm";
-static LPCWSTR PRSRV_MANUAL = L"manual";
-static LPCWSTR PRSRV_JBIN = L"\\bin\\java.exe";
-static LPCWSTR PRSRV_SIGNAL = L"SIGNAL";
-
-static LPCWSTR STYPE_INTERACTIVE = L"interactive";
-
-static LPWSTR _service_name = NULL;
-/* Allowed procrun commands */
-static LPCWSTR _commands[] = {
- L"TS", /* 1 Run Service as console application (default)*/
- L"RS", /* 2 Run Service */
- L"SS", /* 3 Stop Service */
- L"US", /* 4 Update Service parameters */
- L"IS", /* 5 Install Service */
- L"DS", /* 6 Delete Service */
- NULL
-};
-
-/* Allowed procrun parameters */
-static APXCMDLINEOPT _options[] = {
-
-/* 0 */ { L"Description", L"Description", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
-/* 1 */ { L"DisplayName", L"DisplayName", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
-/* 2 */ { L"Install", L"ImagePath", NULL, APXCMDOPT_STE | APXCMDOPT_SRV, NULL, 0},
-/* 3 */ { L"ServiceUser", L"ServiceUser", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
-/* 4 */ { L"ServicePassword", L"ServicePassword", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
-/* 5 */ { L"Startup", L"Startup", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
-/* 6 */ { L"Type", L"Type", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
-
-/* 7 */ { L"DependsOn", L"DependsOn", NULL, APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
-/* 8 */ { L"Environment", L"Environment", NULL, APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
-/* 9 */ { L"User", L"User", NULL, APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 10 */ { L"Password", L"Password", NULL, APXCMDOPT_BIN | APXCMDOPT_REG, NULL, 0},
-
-/* 11 */ { L"JavaHome", L"JavaHome", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 12 */ { L"Jvm", L"Jvm", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 13 */ { L"JvmOptions", L"Options", L"Java", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
-/* 14 */ { L"Classpath", L"Classpath", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 15 */ { L"JvmMs", L"JvmMs", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
-/* 16 */ { L"JvmMx", L"JvmMx", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
-/* 17 */ { L"JvmSs", L"JvmSs", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
-
-/* 18 */ { L"StopImage", L"Image", L"Stop", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 19 */ { L"StopPath", L"WorkingPath", L"Stop", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 20 */ { L"StopClass", L"Class", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 21 */ { L"StopParams", L"Params", L"Stop", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
-/* 22 */ { L"StopMethod", L"Method", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 23 */ { L"StopMode", L"Mode", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 24 */ { L"StopTimeout", L"Timeout", L"Stop", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
-
-/* 25 */ { L"StartImage", L"Image", L"Start", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 26 */ { L"StartPath", L"WorkingPath", L"Start", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 27 */ { L"StartClass", L"Class", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 28 */ { L"StartParams", L"Params", L"Start", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
-/* 29 */ { L"StartMethod", L"Method", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 30 */ { L"StartMode", L"Mode", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-
-/* 31 */ { L"LogPath", L"Path", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 32 */ { L"LogPrefix", L"Prefix", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 33 */ { L"LogLevel", L"Level", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
-/* 34 */ { L"StdError", L"StdError", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
-/* 35 */ { L"StdOutput", L"StdOutput", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
- /* NULL terminate the array */
- { NULL }
-};
-
-#define GET_OPT_V(x) _options[x].szValue
-#define GET_OPT_I(x) _options[x].dwValue
-#define GET_OPT_T(x) _options[x].dwType
-
-#define ST_DESCRIPTION GET_OPT_T(0)
-#define ST_DISPLAYNAME GET_OPT_T(1)
-#define ST_INSTALL GET_OPT_T(2)
-#define ST_SUSER GET_OPT_T(3)
-#define ST_SPASSWORD GET_OPT_T(4)
-#define ST_STARTUP GET_OPT_T(5)
-#define ST_TYPE GET_OPT_T(6)
-
-#define SO_DESCRIPTION GET_OPT_V(0)
-#define SO_DISPLAYNAME GET_OPT_V(1)
-#define SO_INSTALL GET_OPT_V(2)
-#define SO_SUSER GET_OPT_V(3)
-#define SO_SPASSWORD GET_OPT_V(4)
-#define SO_STARTUP GET_OPT_V(5)
-#define SO_TYPE GET_OPT_V(6)
-
-#define SO_DEPENDSON GET_OPT_V(7)
-#define SO_ENVIRONMENT GET_OPT_V(8)
-
-#define SO_USER GET_OPT_V(9)
-#define SO_PASSWORD GET_OPT_V(10)
-
-#define SO_JAVAHOME GET_OPT_V(11)
-#define SO_JVM GET_OPT_V(12)
-#define SO_JVMOPTIONS GET_OPT_V(13)
-#define SO_CLASSPATH GET_OPT_V(14)
-#define SO_JVMMS GET_OPT_I(15)
-#define SO_JVMMX GET_OPT_I(16)
-#define SO_JVMSS GET_OPT_I(17)
-
-#define SO_STOPIMAGE GET_OPT_V(18)
-#define SO_STOPPATH GET_OPT_V(19)
-#define SO_STOPCLASS GET_OPT_V(20)
-#define SO_STOPPARAMS GET_OPT_V(21)
-#define SO_STOPMETHOD GET_OPT_V(22)
-#define SO_STOPMODE GET_OPT_V(23)
-#define SO_STOPTIMEOUT GET_OPT_I(24)
-
-#define SO_STARTIMAGE GET_OPT_V(25)
-#define SO_STARTPATH GET_OPT_V(26)
-#define SO_STARTCLASS GET_OPT_V(27)
-#define SO_STARTPARAMS GET_OPT_V(28)
-#define SO_STARTMETHOD GET_OPT_V(29)
-#define SO_STARTMODE GET_OPT_V(30)
-
-#define SO_LOGPATH GET_OPT_V(31)
-#define SO_LOGPREFIX GET_OPT_V(32)
-#define SO_LOGLEVEL GET_OPT_V(33)
-
-#define SO_STDERROR GET_OPT_V(34)
-#define SO_STDOUTPUT GET_OPT_V(35)
-
-/* Main servic table entry
- * filled at run-time
- */
-static SERVICE_TABLE_ENTRYW _service_table[] = {
- {NULL, NULL},
- {NULL, NULL}
-};
-
-static SERVICE_STATUS _service_status;
-static SERVICE_STATUS_HANDLE _service_status_handle = NULL;
-/* Set if launched by SCM */
-static BOOL _service_mode = FALSE;
-/* JVM used as worker */
-static BOOL _jni_startup = FALSE;
-/* JVM used for shutdown */
-static BOOL _jni_shutdown = FALSE;
-/* Global variables and objects */
-static APXHANDLE gPool;
-static APXHANDLE gWorker;
-static APX_STDWRAP gStdwrap; /* stdio/stderr redirection */
-
-static LPWSTR _jni_jvmpath = NULL; /* Path to jvm dll */
-static LPSTR _jni_jvmoptions = NULL; /* Path to jvm options */
-
-static LPSTR _jni_classpath = NULL;
-static LPCWSTR _jni_rparam = NULL; /* Startup arguments */
-static LPCWSTR _jni_sparam = NULL; /* Shutdown arguments */
-static LPSTR _jni_rmethod = NULL; /* Startup arguments */
-static LPSTR _jni_smethod = NULL; /* Shutdown arguments */
-static CHAR _jni_rclass[SIZ_RESLEN] = {'\0'}; /* Startup class */
-static CHAR _jni_sclass[SIZ_RESLEN] = {'\0'}; /* Shutdown class */
-
-static HANDLE gShutdownEvent = NULL;
-static HANDLE gSignalEvent = NULL;
-static HANDLE gSignalThread = NULL;
-static BOOL gSignalValid = TRUE;
-
-DWORD WINAPI eventThread(LPVOID lpParam)
-{
- for (;;) {
- DWORD dw = WaitForSingleObject(gSignalEvent, INFINITE);
- if (dw == WAIT_OBJECT_0 && gSignalValid) {
- if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0))
- apxLogWrite(APXLOG_MARK_SYSERR);
- ResetEvent(gSignalEvent);
- }
- else
- break;
- }
- ExitThread(0);
- return 0;
-}
-
-/* redirect console stdout/stderr to files
- * so that java messages can get logged
- * If stderrfile is not specified it will
- * go to stdoutfile.
- */
-static BOOL redirectStdStreams(APX_STDWRAP *lpWrapper)
-{
- BOOL aErr = FALSE;
- BOOL aOut = FALSE;
-
- /* Clear up the handles */
- lpWrapper->fpStdErrFile = NULL;
- lpWrapper->fpStdOutFile = NULL;
-
- /* Save the original streams */
- lpWrapper->fpStdOutSave = *stdout;
- lpWrapper->fpStdErrSave = *stderr;
-
- /* redirect to file or console */
- if (lpWrapper->szStdOutFilename) {
- if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
- aOut = TRUE;
- lpWrapper->szStdOutFilename = apxLogFile(gPool,
- lpWrapper->szLogPath,
- NULL,
- L"stdout_");
- }
- /* Delete the file if not in append mode
- * XXX: See if we can use the params instead of that.
- */
- if (!aOut)
- DeleteFileW(lpWrapper->szStdOutFilename);
- lpWrapper->hStdOutFile = CreateFileW(lpWrapper->szStdOutFilename,
- GENERIC_WRITE | GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
- return FALSE;
- /* Allways move to the end of file */
- SetFilePointer(lpWrapper->hStdOutFile, 0, NULL, FILE_END);
- }
- else {
- lpWrapper->hStdOutFile = CreateFileW(L"CONOUT$",
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
- return FALSE;
- }
- if (lpWrapper->szStdErrFilename) {
- if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
- aErr = TRUE;
- lpWrapper->szStdErrFilename = apxLogFile(gPool,
- lpWrapper->szLogPath,
- NULL,
- L"stderr_");
- }
- if (!aErr)
- DeleteFileW(lpWrapper->szStdErrFilename);
- lpWrapper->hStdErrFile = CreateFileW(lpWrapper->szStdErrFilename,
- GENERIC_WRITE | GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (IS_INVALID_HANDLE(lpWrapper->hStdErrFile))
- return FALSE;
- SetFilePointer(lpWrapper->hStdErrFile, 0, NULL, FILE_END);
- }
- else if (lpWrapper->szStdOutFilename) {
- /* Use the same file handle for stderr as for stdout */
- lpWrapper->szStdErrFilename = lpWrapper->szStdOutFilename;
- lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
- }
- else {
- lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
- }
- /* Open the stream buffers
- * This will redirect all printf to go to the redirected files.
- * It is used for JNI vprintf functionality.
- */
- lpWrapper->fpStdOutFile = _fdopen(_open_osfhandle(
- (intptr_t)lpWrapper->hStdOutFile,
- _O_TEXT), "w");
- lpWrapper->fpStdErrFile = _fdopen(_open_osfhandle(
- (intptr_t)lpWrapper->hStdErrFile,
- _O_TEXT), "w");
- if (lpWrapper->fpStdOutFile) {
- *stdout = *lpWrapper->fpStdOutFile;
- setvbuf(stdout, NULL, _IONBF, 0);
- }
- if (lpWrapper->fpStdErrFile) {
- *stderr = *lpWrapper->fpStdErrFile;
- setvbuf(stderr, NULL, _IONBF, 0);
- }
- return TRUE;
-}
-
-static void cleanupStdStreams(APX_STDWRAP *lpWrapper)
-{
- /* Close the redirectied streams */
- if (lpWrapper->fpStdOutFile) {
- fclose(lpWrapper->fpStdOutFile);
- *stdout = lpWrapper->fpStdOutSave;
- }
- if (lpWrapper->fpStdErrFile) {
- fclose(lpWrapper->fpStdErrFile);
- *stderr = lpWrapper->fpStdErrSave;
- }
-}
-
-/* Debugging functions */
-static void printUsage(LPAPXCMDLINE lpCmdline)
-{
-#ifdef _DEBUG
- int i = 0;
- fwprintf(stderr, L"Usage: %s //CMD//Servce [--options]\n",
- lpCmdline->szExecutable);
- fwprintf(stderr, L" Commands:\n");
- fwprintf(stderr, L" //IS//ServiceName Install Service\n");
- fwprintf(stderr, L" //US//ServiceName Update Service parameters\n");
- fwprintf(stderr, L" //DS//ServiceName Delete Service\n");
- fwprintf(stderr, L" //RS//ServiceName Run Service\n");
- fwprintf(stderr, L" //SS//ServiceName Stop Service\n");
- fwprintf(stderr,
- L" //TS//ServiceName Run Service as console application\n");
- fwprintf(stderr, L" Options:\n");
- while (_options[i].szName) {
- fwprintf(stderr, L" --%s\n", _options[i].szName);
- ++i;
- }
-#endif
-}
-/* Display configuration parameters */
-static void dumpCmdline()
-{
- int i = 0;
- while (_options[i].szName) {
- if (_options[i].dwType & APXCMDOPT_INT)
- fwprintf(stderr, L"--%-16s %d\n", _options[i].szName,
- _options[i].dwValue);
- else if (_options[i].szValue)
- fwprintf(stderr, L"--%-16s %s\n", _options[i].szName,
- _options[i].szValue);
- else
- fwprintf(stderr, L"--%-16s <NULL>\n", _options[i].szName);
- ++i;
- }
-}
-
-static void setInprocEnvironment()
-{
- LPWSTR p, e;
-
- if (!SO_ENVIRONMENT)
- return; /* Nothing to do */
-
- for (p = SO_ENVIRONMENT; *p; p++) {
- e = apxExpandStrW(gPool, p);
- _wputenv(e);
- apxFree(e);
- while (*p)
- p++;
- }
-}
-
-/* Load the configuration from Registry
- * loads only nonspecified items
- */
-static BOOL loadConfiguration(LPAPXCMDLINE lpCmdline)
-{
- APXHANDLE hRegistry;
- int i = 0;
-
- SetLastError(ERROR_SUCCESS);
- hRegistry = apxCreateRegistryW(gPool, KEY_READ | KREG_WOW6432,
- PRG_REGROOT,
- lpCmdline->szApplication,
- APXREG_SOFTWARE | APXREG_SERVICE);
- if (IS_INVALID_HANDLE(hRegistry)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return FALSE;
- }
- /* browse through options */
- while (_options[i].szName) {
- DWORD dwFrom;
-
- dwFrom = (_options[i].dwType & APXCMDOPT_REG) ? APXREG_PARAMSOFTWARE : APXREG_SERVICE;
- if (!(_options[i].dwType & APXCMDOPT_FOUND)) {
- if (_options[i].dwType & APXCMDOPT_STR) {
- _options[i].szValue = apxRegistryGetStringW(hRegistry,
- dwFrom,
- _options[i].szSubkey,
- _options[i].szRegistry);
- /* Expand environment variables */
- if (_options[i].szValue && (_options[i].dwType & APXCMDOPT_STE)) {
- LPWSTR exp = apxExpandStrW(gPool, _options[i].szValue);
- if (exp != _options[i].szValue)
- apxFree(_options[i].szValue);
- _options[i].szValue = exp;
- }
- }
- else if (_options[i].dwType & APXCMDOPT_INT) {
- _options[i].dwValue = apxRegistryGetNumberW(hRegistry,
- dwFrom,
- _options[i].szSubkey,
- _options[i].szRegistry);
- }
- else if (_options[i].dwType & APXCMDOPT_MSZ) {
- _options[i].szValue = apxRegistryGetMzStrW(hRegistry,
- dwFrom,
- _options[i].szSubkey,
- _options[i].szRegistry,
- NULL,
- &(_options[i].dwValue));
- }
- }
- /* Merge the command line options with registry */
- else if (_options[i].dwType & APXCMDOPT_ADD) {
- LPWSTR cv = _options[i].szValue;
- LPWSTR ov = NULL;
- if (_options[i].dwType & APXCMDOPT_MSZ) {
- ov = apxRegistryGetMzStrW(hRegistry, dwFrom,
- _options[i].szSubkey,
- _options[i].szRegistry,
- NULL,
- &(_options[i].dwValue));
- _options[i].szValue = apxMultiSzCombine(gPool, ov, cv,
- &(_options[i].dwValue));
- if (ov)
- apxFree(ov);
- }
- }
- ++i;
- }
- apxCloseHandle(hRegistry);
-#ifdef _DEBUG
- dumpCmdline();
-#endif
- return TRUE;
-}
-
-/* Save changed configuration to registry
- */
-static BOOL saveConfiguration(LPAPXCMDLINE lpCmdline)
-{
- APXHANDLE hRegistry;
- int i = 0;
- hRegistry = apxCreateRegistryW(gPool, KEY_WRITE | KREG_WOW6432,
- PRG_REGROOT,
- lpCmdline->szApplication,
- APXREG_SOFTWARE | APXREG_SERVICE);
- if (IS_INVALID_HANDLE(hRegistry))
- return FALSE;
- /* TODO: Use array size */
- while (_options[i].szName) {
- /* Skip the service params */
- if ((_options[i].dwType & APXCMDOPT_SRV) ||
- !(_options[i].dwType & APXCMDOPT_FOUND)) {
- /* Skip non-modified version */
- }
- /* Update only modified params */
- else if (_options[i].dwType & APXCMDOPT_STR)
- apxRegistrySetStrW(hRegistry, APXREG_PARAMSOFTWARE,
- _options[i].szSubkey,
- _options[i].szRegistry,
- _options[i].szValue);
- else if (_options[i].dwType & APXCMDOPT_INT)
- apxRegistrySetNumW(hRegistry, APXREG_PARAMSOFTWARE,
- _options[i].szSubkey,
- _options[i].szRegistry,
- _options[i].dwValue);
- else if (_options[i].dwType & APXCMDOPT_MSZ)
- apxRegistrySetMzStrW(hRegistry, APXREG_PARAMSOFTWARE,
- _options[i].szSubkey,
- _options[i].szRegistry,
- _options[i].szValue,
- _options[i].dwValue);
- ++i;
- }
- apxCloseHandle(hRegistry);
- return TRUE;
-}
-
-/* Operations */
-static BOOL docmdInstallService(LPAPXCMDLINE lpCmdline)
-{
- APXHANDLE hService;
- BOOL rv;
- DWORD dwStart = SERVICE_DEMAND_START;
- DWORD dwType = SERVICE_WIN32_OWN_PROCESS;
- WCHAR szImage[SIZ_HUGLEN];
-
- apxLogWrite(APXLOG_MARK_DEBUG "Installing service...");
- hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
- if (IS_INVALID_HANDLE(hService)) {
- apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
- return FALSE;
- }
- /* Check the startup mode */
- if ((ST_STARTUP & APXCMDOPT_FOUND) &&
- lstrcmpiW(SO_STARTUP, PRSRV_AUTO) == 0)
- dwStart = SERVICE_AUTO_START;
- /* Check the service type */
- if ((ST_TYPE & APXCMDOPT_FOUND) &&
- lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE) == 0)
- dwType |= SERVICE_INTERACTIVE_PROCESS;
-
- /* Check if --Install is provided */
- if (!SO_INSTALL) {
- lstrcpyW(szImage, lpCmdline->szExePath);
- lstrcatW(szImage, L"\\");
- lstrcatW(szImage, lpCmdline->szExecutable);
- lstrcatW(szImage, L".exe");
- }
- else
- lstrcpyW(szImage, SO_INSTALL);
- /* Replace not needed qoutes */
- apxStrQuoteInplaceW(szImage);
- /* Add run-service command line option */
- lstrcatW(szImage, L" //RS//");
- lstrcatW(szImage, lpCmdline->szApplication);
- SO_INSTALL = apxPoolStrdupW(gPool, szImage);
- /* Ensure that option gets saved in the registry */
- ST_INSTALL |= APXCMDOPT_FOUND;
-#ifdef _DEBUG
- /* Display configured options */
- dumpCmdline();
-#endif
- apxLogWrite(APXLOG_MARK_INFO "Service %S name %S", lpCmdline->szApplication,
- SO_DISPLAYNAME);
- rv = apxServiceInstall(hService,
- lpCmdline->szApplication,
- SO_DISPLAYNAME, /* --DisplayName */
- SO_INSTALL,
- SO_DEPENDSON, /* --DependendsOn */
- dwType,
- dwStart);
- /* Set the --Description */
- if (rv) {
- LPCWSTR sd = NULL;
- LPCWSTR su = NULL;
- LPCWSTR sp = NULL;
- if (ST_DESCRIPTION & APXCMDOPT_FOUND) {
- sd = SO_DESCRIPTION;
- apxLogWrite(APXLOG_MARK_DEBUG "Setting service description %S",
- SO_DESCRIPTION);
- }
- if (ST_SUSER & APXCMDOPT_FOUND) {
- su = SO_SUSER;
- apxLogWrite(APXLOG_MARK_DEBUG "Setting service user %S",
- SO_SUSER);
- }
- if (ST_SPASSWORD & APXCMDOPT_FOUND) {
- sp = SO_SPASSWORD;
- apxLogWrite(APXLOG_MARK_DEBUG "Setting service password %S",
- SO_SPASSWORD);
- }
- apxServiceSetNames(hService, NULL, NULL, sd, su, sp);
- }
- apxCloseHandle(hService);
- if (rv) {
- saveConfiguration(lpCmdline);
- apxLogWrite(APXLOG_MARK_INFO "Service %S installed",
- lpCmdline->szApplication);
- }
- else
- apxLogWrite(APXLOG_MARK_ERROR "Failed installing %S service",
- lpCmdline->szApplication);
-
- return rv;
-}
-
-static BOOL docmdDeleteService(LPAPXCMDLINE lpCmdline)
-{
- APXHANDLE hService;
- BOOL rv = FALSE;
-
- apxLogWrite(APXLOG_MARK_INFO "Deleting service...");
- hService = apxCreateService(gPool, SC_MANAGER_CONNECT, FALSE);
- if (IS_INVALID_HANDLE(hService)) {
- apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
- return FALSE;
- }
- /* Delete service will stop the service if running */
- if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
- WCHAR szWndManagerClass[SIZ_RESLEN];
- HANDLE hWndManager = NULL;
- lstrcpyW(szWndManagerClass, lpCmdline->szApplication);
- lstrcatW(szWndManagerClass, L"_CLASS");
- /* Close the monitor application if running */
- if ((hWndManager = FindWindowW(szWndManagerClass, NULL)) != NULL) {
- SendMessage(hWndManager, WM_CLOSE, 0, 0);
- }
- rv = apxServiceDelete(hService);
- }
- if (rv) {
- /* Delete all service registry settings */
- apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, TRUE);
- apxLogWrite(APXLOG_MARK_DEBUG "Service %S deleted",
- lpCmdline->szApplication);
- }
- else {
- apxDisplayError(TRUE, NULL, 0, "Unable to delete %S service",
- lpCmdline->szApplication);
- }
- apxCloseHandle(hService);
- apxLogWrite(APXLOG_MARK_INFO "Delete service finished.");
- return rv;
-}
-
-static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
-{
- APXHANDLE hService;
- BOOL rv = FALSE;
-
- apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
- hService = apxCreateService(gPool, GENERIC_ALL, FALSE);
- if (IS_INVALID_HANDLE(hService)) {
- apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
- return FALSE;
- }
-
- SetLastError(ERROR_SUCCESS);
- /* Open the service */
- if (apxServiceOpen(hService, lpCmdline->szApplication,
- GENERIC_READ | GENERIC_EXECUTE)) {
- rv = apxServiceControl(hService,
- SERVICE_CONTROL_STOP,
- 0,
- NULL,
- NULL);
- if (rv)
- apxLogWrite(APXLOG_MARK_INFO "Service %S stopped",
- lpCmdline->szApplication);
- else
- apxLogWrite(APXLOG_MARK_ERROR "Failed to stop %S service",
- lpCmdline->szApplication);
-
- }
- else
- apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
- lpCmdline->szApplication);
- apxCloseHandle(hService);
- apxLogWrite(APXLOG_MARK_INFO "Stop service finished.");
- return rv;
-}
-
-static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
-{
- APXHANDLE hService;
- BOOL rv = FALSE;
-
- apxLogWrite(APXLOG_MARK_INFO "Updating service...");
-
- hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
- if (IS_INVALID_HANDLE(hService)) {
- apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
- return FALSE;
- }
- SetLastError(0);
- /* Open the service */
- if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
- DWORD dwStart = SERVICE_NO_CHANGE;
- DWORD dwType = SERVICE_NO_CHANGE;
- LPCWSTR su = NULL;
- LPCWSTR sp = NULL;
- if (ST_SUSER & APXCMDOPT_FOUND) {
- su = SO_SUSER;
- apxLogWrite(APXLOG_MARK_DEBUG "Setting service user %S",
- SO_SUSER);
- }
- if (ST_SPASSWORD & APXCMDOPT_FOUND) {
- sp = SO_SPASSWORD;
- apxLogWrite(APXLOG_MARK_DEBUG "Setting service password %S",
- SO_SPASSWORD);
- }
- apxServiceSetNames(hService,
- NULL, /* Never update the ImagePath */
- SO_DISPLAYNAME,
- SO_DESCRIPTION,
- su,
- sp);
- /* Update the --Startup mode */
- if (ST_STARTUP & APXCMDOPT_FOUND) {
- if (!lstrcmpiW(SO_STARTUP, PRSRV_AUTO))
- dwStart = SERVICE_AUTO_START;
- else if (!lstrcmpiW(SO_STARTUP, PRSRV_MANUAL))
- dwStart = SERVICE_DEMAND_START;
- }
- if (ST_TYPE & APXCMDOPT_FOUND) {
- if (!lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE))
- dwType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS;
- }
- apxServiceSetOptions(hService,
- dwType,
- dwStart,
- SERVICE_NO_CHANGE);
-
- apxLogWrite(APXLOG_MARK_INFO "Service %S updated",
- lpCmdline->szApplication);
-
- saveConfiguration(lpCmdline);
- }
- else
- apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
- lpCmdline->szApplication);
- apxCloseHandle(hService);
- apxLogWrite(APXLOG_MARK_INFO "Update service finished.");
- return rv;
-}
-
-
-/* Report the service status to the SCM
- */
-int reportServiceStatus(DWORD dwCurrentState,
- DWORD dwWin32ExitCode,
- DWORD dwWaitHint)
-{
- static DWORD dwCheckPoint = 1;
- BOOL fResult = TRUE;
-
- if (_service_mode && _service_status_handle) {
- if (dwCurrentState == SERVICE_START_PENDING)
- _service_status.dwControlsAccepted = 0;
- else
- _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
-
- _service_status.dwCurrentState = dwCurrentState;
- _service_status.dwWin32ExitCode = dwWin32ExitCode;
- _service_status.dwWaitHint = dwWaitHint;
-
- if ((dwCurrentState == SERVICE_RUNNING) ||
- (dwCurrentState == SERVICE_STOPPED))
- _service_status.dwCheckPoint = 0;
- else
- _service_status.dwCheckPoint = dwCheckPoint++;
- fResult = SetServiceStatus(_service_status_handle, &_service_status);
- if (!fResult) {
- /* TODO: Deal with error */
- }
- }
- return fResult;
-}
-
-
-BOOL child_callback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- /* TODO: Make stdout and stderr buffers
- * to prevent streams intermixing when there
- * is no separate file for each stream
- */
- if (uMsg == WM_CHAR) {
- int ch = LOWORD(wParam);
- if (lParam)
- fputc(ch, stderr);
- else
- fputc(ch, stdout);
- }
- return TRUE;
-}
-
-/* Executed when the service receives stop event */
-static DWORD WINAPI serviceStop(LPVOID lpParameter)
-{
- APXHANDLE hWorker = NULL;
- DWORD rv = 0;
- BOOL wait_to_die = FALSE;
- DWORD timeout = SO_STOPTIMEOUT * 1000;
- DWORD dwCtrlType = (DWORD)((BYTE *)lpParameter - (BYTE *)0);
-
- apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
-
- if (IS_INVALID_HANDLE(gWorker)) {
- apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
- return TRUE; /* Nothing to do */
- }
- if (_jni_shutdown) {
- if (!SO_STARTPATH && SO_STOPPATH) {
- /* If the Working path is specified change the current directory
- * but only if the start path wasn't specified already.
- */
- SetCurrentDirectoryW(SO_STARTPATH);
- }
- hWorker = apxCreateJava(gPool, _jni_jvmpath);
- if (IS_INVALID_HANDLE(hWorker)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
- return 1;
- }
- if (!apxJavaInitialize(hWorker, _jni_classpath, _jni_jvmoptions,
- SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
- rv = 2;
- apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
- goto cleanup;
- }
- if (!apxJavaLoadMainClass(hWorker, _jni_sclass, _jni_smethod, _jni_sparam)) {
- rv = 2;
- apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s",
- _jni_rclass, _jni_classpath);
- goto cleanup;
- }
- /* Create sutdown event */
- gShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (!apxJavaStart(hWorker)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed starting java");
- rv = 3;
- }
- else {
- apxLogWrite(APXLOG_MARK_DEBUG "Waiting for java jni stop worker to finish...");
- apxJavaWait(hWorker, INFINITE, FALSE);
- apxLogWrite(APXLOG_MARK_DEBUG "Java jni stop worker finished.");
- }
- wait_to_die = TRUE;
- }
- else if (SO_STOPMODE) { /* Only in case we have a stop mode */
- DWORD nArgs;
- LPWSTR *pArgs;
- /* Redirect process */
- hWorker = apxCreateProcessW(gPool,
- 0,
- child_callback,
- SO_USER,
- SO_PASSWORD,
- FALSE);
- if (IS_INVALID_HANDLE(hWorker)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
- return 1;
- }
- if (!apxProcessSetExecutableW(hWorker, SO_STOPIMAGE)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
- SO_STARTIMAGE);
- rv = 2;
- goto cleanup;
- }
- /* Assemble the command line */
- nArgs = apxMultiSzToArrayW(gPool, SO_STOPPARAMS, &pArgs);
- /* Pass the argv to child process */
- if (!apxProcessSetCommandArgsW(hWorker, SO_STOPIMAGE,
- nArgs, pArgs)) {
- rv = 3;
- apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
- nArgs);
- goto cleanup;
- }
- /* Set the working path */
- if (!apxProcessSetWorkingPathW(hWorker, SO_STOPPATH)) {
- rv = 4;
- apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
- SO_STOPPATH);
- goto cleanup;
- }
- /* Finally execute the child process
- */
- if (!apxProcessExecute(hWorker)) {
- rv = 5;
- apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
- goto cleanup;
- } else {
- apxLogWrite(APXLOG_MARK_DEBUG "Waiting stop worker to finish...");
- apxHandleWait(hWorker, INFINITE, FALSE);
- apxLogWrite(APXLOG_MARK_DEBUG "Stop worker finished.");
- }
- wait_to_die = TRUE;
- }
-cleanup:
- /* Close Java JNI handle or stop worker
- * If this is the single JVM instance it will unload
- * the JVM dll too.
- * The worker will be closed on service exit.
- */
- if (!IS_INVALID_HANDLE(hWorker))
- apxCloseHandle(hWorker);
- if (gSignalEvent) {
- gSignalValid = FALSE;
- SetEvent(gSignalEvent);
- WaitForSingleObject(gSignalThread, 1000);
- CloseHandle(gSignalEvent);
- CloseHandle(gSignalThread);
- gSignalEvent = NULL;
- }
- SetEvent(gShutdownEvent);
- if (timeout > 0x7FFFFFFF)
- timeout = INFINITE; /* If the timeout was '-1' wait forewer */
- if (wait_to_die && !timeout)
- timeout = 300 * 1000; /* Use the 5 minute default shutdown */
-
- if (dwCtrlType == SERVICE_CONTROL_SHUTDOWN)
- timeout = MIN(timeout, apxGetMaxServiceTimeout(gPool));
- reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, timeout);
-
- if (timeout) {
- FILETIME fts, fte;
- ULARGE_INTEGER s, e;
- DWORD nms;
- /* Wait to give it a chance to die naturally, then kill it. */
- apxLogWrite(APXLOG_MARK_DEBUG "Waiting for worker to die naturally...");
- GetSystemTimeAsFileTime(&fts);
- rv = apxHandleWait(gWorker, timeout, TRUE);
- GetSystemTimeAsFileTime(&fte);
- s.LowPart = fts.dwLowDateTime;
- s.HighPart = fts.dwHighDateTime;
- e.LowPart = fte.dwLowDateTime;
- e.HighPart = fte.dwHighDateTime;
- nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
- if (rv == WAIT_OBJECT_0) {
- rv = 0;
- apxLogWrite(APXLOG_MARK_DEBUG "Worker finished gracefully in %d ms.", nms);
- }
- else
- apxLogWrite(APXLOG_MARK_DEBUG "Worker was killed in %d ms.", nms);
- }
- else {
- apxLogWrite(APXLOG_MARK_DEBUG "Sending WM_CLOSE to worker");
- apxHandleSendMessage(gWorker, WM_CLOSE, 0, 0);
- }
-
- apxLogWrite(APXLOG_MARK_INFO "Service stopped.");
- reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
- return rv;
-}
-
-/* Executed when the service receives start event */
-static DWORD serviceStart()
-{
- DWORD rv = 0;
- DWORD nArgs;
- LPWSTR *pArgs;
- FILETIME fts;
-
- apxLogWrite(APXLOG_MARK_INFO "Starting service...");
-
- if (!IS_INVALID_HANDLE(gWorker)) {
- apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
- return TRUE; /* Nothing to do */
- }
- GetSystemTimeAsFileTime(&fts);
- if (_jni_startup) {
- if (SO_STARTPATH) {
- /* If the Working path is specified change the current directory */
- SetCurrentDirectoryW(SO_STARTPATH);
- }
- /* Set the environment using putenv, so JVM can use it */
- setInprocEnvironment();
- /* Create the JVM glbal worker */
- gWorker = apxCreateJava(gPool, _jni_jvmpath);
- if (IS_INVALID_HANDLE(gWorker)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
- return 1;
- }
- if (!apxJavaInitialize(gWorker, _jni_classpath, _jni_jvmoptions,
- SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
- rv = 2;
- apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
- goto cleanup;
- }
- if (!apxJavaLoadMainClass(gWorker, _jni_rclass, _jni_rmethod, _jni_rparam)) {
- rv = 3;
- apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s", _jni_rclass, _jni_classpath);
- goto cleanup;
- }
- apxJavaSetOut(gWorker, TRUE, gStdwrap.szStdErrFilename);
- apxJavaSetOut(gWorker, FALSE, gStdwrap.szStdOutFilename);
- if (!apxJavaStart(gWorker)) {
- rv = 4;
- apxLogWrite(APXLOG_MARK_ERROR "Failed starting Java");
- goto cleanup;
- }
- apxLogWrite(APXLOG_MARK_DEBUG "Java started %s", _jni_rclass);
- }
- else {
- /* Redirect process */
- gWorker = apxCreateProcessW(gPool,
- 0,
- child_callback,
- SO_USER,
- SO_PASSWORD,
- FALSE);
- if (IS_INVALID_HANDLE(gWorker)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
- return 1;
- }
- if (!apxProcessSetExecutableW(gWorker, SO_STARTIMAGE)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
- SO_STARTIMAGE);
- rv = 2;
- goto cleanup;
- }
- /* Assemble the command line */
- nArgs = apxMultiSzToArrayW(gPool, SO_STARTPARAMS, &pArgs);
- /* Pass the argv to child process */
- if (!apxProcessSetCommandArgsW(gWorker, SO_STARTIMAGE,
- nArgs, pArgs)) {
- rv = 3;
- apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
- nArgs);
- goto cleanup;
- }
- /* Set the working path */
- if (!apxProcessSetWorkingPathW(gWorker, SO_STARTPATH)) {
- rv = 4;
- apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
- SO_STARTPATH);
- goto cleanup;
- }
- /* Finally execute the child process
- */
- if (!apxProcessExecute(gWorker)) {
- rv = 5;
- apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
- goto cleanup;
- }
- }
- if (rv == 0) {
- FILETIME fte;
- ULARGE_INTEGER s, e;
- DWORD nms;
- GetSystemTimeAsFileTime(&fte);
- s.LowPart = fts.dwLowDateTime;
- s.HighPart = fts.dwHighDateTime;
- e.LowPart = fte.dwLowDateTime;
- e.HighPart = fte.dwHighDateTime;
- nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
- apxLogWrite(APXLOG_MARK_INFO "Service started in %d ms.", nms);
- }
- return rv;
-cleanup:
- if (!IS_INVALID_HANDLE(gWorker))
- apxCloseHandle(gWorker); /* Close the worker handle */
- gWorker = NULL;
- return rv;
-}
-
-/* Service control handler
- */
-void WINAPI service_ctrl_handler(DWORD dwCtrlCode)
-{
- DWORD threadId;
- HANDLE stopThread;
-
- switch (dwCtrlCode) {
- case SERVICE_CONTROL_STOP:
- reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
- /* Stop the service asynchronously */
- stopThread = CreateThread(NULL, 0,
- serviceStop,
- (LPVOID)SERVICE_CONTROL_STOP,
- 0, &threadId);
- WaitForSingleObject(stopThread, INFINITE);
- CloseHandle(stopThread);
-
- return;
- case SERVICE_CONTROL_SHUTDOWN:
- apxLogWrite(APXLOG_MARK_INFO "Service SHUTDOWN signaled");
- reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
- /* Stop the service asynchronously */
- stopThread = CreateThread(NULL, 0,
- serviceStop,
- (LPVOID)SERVICE_CONTROL_SHUTDOWN,
- 0, &threadId);
- WaitForSingleObject(stopThread, INFINITE);
- CloseHandle(stopThread);
- return;
- case SERVICE_CONTROL_INTERROGATE:
- reportServiceStatus(_service_status.dwCurrentState,
- _service_status.dwWin32ExitCode,
- _service_status.dwWaitHint);
- return;
- default:
- break;
- }
-}
-
-/* Console control handler
- *
- */
-BOOL WINAPI console_handler(DWORD dwCtrlType)
-{
- switch (dwCtrlType) {
- case CTRL_BREAK_EVENT:
- apxLogWrite(APXLOG_MARK_INFO "Console CTRL+BREAK event signaled");
- return FALSE;
- case CTRL_C_EVENT:
- apxLogWrite(APXLOG_MARK_INFO "Console CTRL+C event signaled");
- serviceStop((LPVOID)SERVICE_CONTROL_STOP);
- return TRUE;
- case CTRL_CLOSE_EVENT:
- apxLogWrite(APXLOG_MARK_INFO "Console CTRL+CLOSE event signaled");
- serviceStop((LPVOID)SERVICE_CONTROL_STOP);
- return TRUE;
- case CTRL_SHUTDOWN_EVENT:
- apxLogWrite(APXLOG_MARK_INFO "Console SHUTDOWN event signaled");
- serviceStop((LPVOID)SERVICE_CONTROL_SHUTDOWN);
- return TRUE;
- case CTRL_LOGOFF_EVENT:
- apxLogWrite(APXLOG_MARK_INFO "Console LOGOFF event signaled");
- if (!_service_mode) {
- serviceStop((LPVOID)SERVICE_CONTROL_STOP);
- }
- return TRUE;
- break;
-
- }
- return FALSE;
-}
-
-/* Main service execution loop */
-void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
-{
- DWORD rc;
- _service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
- _service_status.dwCurrentState = SERVICE_START_PENDING;
- _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
- SERVICE_ACCEPT_PAUSE_CONTINUE;
- _service_status.dwWin32ExitCode = 0;
- _service_status.dwCheckPoint = 0;
- _service_status.dwWaitHint = 0;
- _service_status.dwServiceSpecificExitCode = 0;
-
- apxLogWrite(APXLOG_MARK_DEBUG "Inside ServiceMain...");
-
- if (_service_name) {
- WCHAR en[SIZ_DESLEN];
- int i;
- PSECURITY_ATTRIBUTES sa = GetNullACL();
- lstrcpyW(en, L"Global\\");
- lstrcatW(en, _service_name);
- lstrcatW(en, PRSRV_SIGNAL);
- for (i = 7; i < lstrlenW(en); i++) {
- if (en[i] >= L'a' && en[i] <= L'z')
- en[i] = en[i] - 32;
- }
- gSignalEvent = CreateEventW(sa, TRUE, FALSE, en);
- CleanNullACL((void *)sa);
-
- if (gSignalEvent) {
- DWORD tid;
- gSignalThread = CreateThread(NULL, 0, eventThread, NULL, 0, &tid);
- }
- }
- /* Check the StartMode */
- if (SO_STARTMODE) {
- if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
- _jni_startup = TRUE;
- WideToAscii(SO_STARTCLASS, _jni_rclass);
- /* Exchange all dots with slashes */
- apxStrCharReplaceA(_jni_rclass, '.', '/');
- _jni_rparam = SO_STARTPARAMS;
- }
- else if (!lstrcmpiW(SO_STARTMODE, PRSRV_JAVA)) {
- LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
- if (szJH) {
- jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
- lstrcpyW(jx, szJH);
- lstrcatW(jx, PRSRV_JBIN);
- SO_STARTPATH = szJH;
- }
- /* StartImage now contains the full path to the java.exe */
- SO_STARTIMAGE = jx;
- }
- }
- /* Check the StopMode */
- if (SO_STOPMODE) {
- if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
- _jni_shutdown = TRUE;
- WideToAscii(SO_STOPCLASS, _jni_sclass);
- apxStrCharReplaceA(_jni_sclass, '.', '/');
- _jni_sparam = SO_STOPPARAMS;
- }
- else if (!lstrcmpiW(SO_STOPMODE, PRSRV_JAVA)) {
- LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
- if (szJH) {
- jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
- lstrcpyW(jx, szJH);
- lstrcatW(jx, PRSRV_JBIN);
- SO_STOPPATH = szJH;
- }
- /* StopImage now contains the full path to the java.exe */
- SO_STOPIMAGE = jx;
- }
- }
- /* Find the classpath */
- if (_jni_shutdown || _jni_startup) {
- if (SO_JVM) {
- if (lstrcmpW(SO_JVM, PRSRV_AUTO))
- _jni_jvmpath = SO_JVM;
- }
- if (SO_CLASSPATH)
- _jni_classpath = WideToUTF8(SO_CLASSPATH);
- if (SO_STARTMETHOD)
- _jni_rmethod = WideToAscii(SO_STARTMETHOD, (LPSTR)SO_STARTMETHOD);
- if (SO_STOPMETHOD)
- _jni_smethod = WideToAscii(SO_STOPMETHOD, (LPSTR)SO_STOPMETHOD);
- _jni_jvmoptions = MzWideToUTF8(SO_JVMOPTIONS);
- }
- if (_service_mode) {
- /* Register Service Control handler */
- _service_status_handle = RegisterServiceCtrlHandlerW(_service_name,
- service_ctrl_handler);
- if (IS_INVALID_HANDLE(_service_status_handle)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed to register Service Control for %S",
- _service_name);
- goto cleanup;
- }
- /* Allocate console so that events gets processed */
- AllocConsole();
- }
- reportServiceStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
- if ((rc = serviceStart()) == 0) {
- /* Service is started */
- DWORD rv;
- reportServiceStatus(SERVICE_RUNNING, NO_ERROR, 0);
- apxLogWrite(APXLOG_MARK_DEBUG "Waiting worker to finish...");
- /* Set console handler to capture CTRL events */
- SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
-
- rv = apxHandleWait(gWorker, INFINITE, FALSE);
- apxLogWrite(APXLOG_MARK_DEBUG "Worker finished.");
- reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
- fflush(stdout);
- }
- else {
- apxLogWrite(APXLOG_MARK_ERROR "ServiceStart returned %d", rc);
- goto cleanup;
- }
- if (gShutdownEvent) {
- /* Ensure that shutdown thread exits before us */
- apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
- WaitForSingleObject(gShutdownEvent, 60 * 1000);
- apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
- CloseHandle(gShutdownEvent);
- }
- reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
-
- return;
-cleanup:
- /* Cleanup */
- reportServiceStatus(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, 0);
- return;
-}
-
-
-/* Run the service in the debug mode */
-BOOL docmdDebugService(LPAPXCMDLINE lpCmdline)
-{
- BOOL rv = FALSE;
-
- _service_mode = FALSE;
- _service_name = lpCmdline->szApplication;
- apxLogWrite(APXLOG_MARK_INFO "Debugging Service...");
- serviceMain(0, NULL);
- apxLogWrite(APXLOG_MARK_INFO "Debug service finished.");
-
- return rv;
-}
-
-BOOL docmdRunService(LPAPXCMDLINE lpCmdline)
-{
- BOOL rv = FALSE;
- _service_mode = TRUE;
-
- apxLogWrite(APXLOG_MARK_INFO "Running Service...");
- _service_name = lpCmdline->szApplication;
- _service_table[0].lpServiceName = lpCmdline->szApplication;
- _service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTIONW)serviceMain;
- rv = (StartServiceCtrlDispatcherW(_service_table) == FALSE);
- apxLogWrite(APXLOG_MARK_INFO "Run service finished.");
- return rv;
-}
-
-void __cdecl main(int argc, char **argv)
-{
- UINT rv = 0;
-
- LPAPXCMDLINE lpCmdline;
-
- apxHandleManagerInitialize();
- /* Create the main Pool */
- gPool = apxPoolCreate(NULL, 0);
-
- /* Parse the command line */
- if ((lpCmdline = apxCmdlineParse(gPool, _options, _commands)) == NULL) {
- apxLogWrite(APXLOG_MARK_ERROR "Invalid command line arguments");
- rv = 1;
- goto cleanup;
- }
- apxCmdlineLoadEnvVars(lpCmdline);
- if (lpCmdline->dwCmdIndex < 5 &&
- !loadConfiguration(lpCmdline)) {
- apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
- rv = 2;
- goto cleanup;
- }
-
- apxLogOpen(gPool, SO_LOGPATH, SO_LOGPREFIX);
- apxLogLevelSetW(NULL, SO_LOGLEVEL);
- apxLogWrite(APXLOG_MARK_DEBUG "Procrun log initialized");
- apxLogWrite(APXLOG_MARK_INFO "Procrun (%s) started", PRG_VERSION);
-
- AplZeroMemory(&gStdwrap, sizeof(APX_STDWRAP));
-
- gStdwrap.szLogPath = SO_LOGPATH;
- /* In debug mode allways use console */
- if (lpCmdline->dwCmdIndex != 1) {
- gStdwrap.szStdOutFilename = SO_STDOUTPUT;
- gStdwrap.szStdErrFilename = SO_STDERROR;
- }
- redirectStdStreams(&gStdwrap);
- switch (lpCmdline->dwCmdIndex) {
- case 1: /* Run Service as console application */
- if (!docmdDebugService(lpCmdline))
- rv = 3;
- break;
- case 2: /* Run Service */
- if (!docmdRunService(lpCmdline))
- rv = 4;
- break;
- case 3: /* Stop Service */
- if (!docmdStopService(lpCmdline))
- rv = 5;
- break;
- case 4: /* Update Service parameters */
- if (!docmdUpdateService(lpCmdline))
- rv = 6;
- break;
- case 5: /* Install Service */
- if (!docmdInstallService(lpCmdline))
- rv = 7;
- break;
- case 6: /* Delete Service */
- if (!docmdDeleteService(lpCmdline))
- rv = 8;
- break;
- default:
- /* Unknown command option */
- apxLogWrite(APXLOG_MARK_ERROR "Unknown command line option");
- printUsage(lpCmdline);
- rv = 99;
- break;
- }
-
-cleanup:
- apxLogWrite(APXLOG_MARK_INFO "Procrun finished.");
- if (lpCmdline)
- apxCmdlineFree(lpCmdline);
- if (_service_status_handle)
- CloseHandle(_service_status_handle);
- _service_status_handle = NULL;
- apxLogClose(NULL);
- apxHandleManagerDestroy();
- cleanupStdStreams(&gStdwrap);
- ExitProcess(rv);
-}
Copied: tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.c (from rev 2689, trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,1491 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ * prunsrv -- Service Runner.
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+/* Force the JNI vprintf functions */
+#define _DEBUG_JNI 1
+#include "apxwin.h"
+#include "prunsrv.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <io.h> /* _open_osfhandle */
+
+#ifndef MIN
+#define MIN(a,b) (((a)<(b)) ? (a) : (b))
+#endif
+
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+#define ONE_MINUTE (60 * 1000)
+
+#ifdef WIN64
+#define KREG_WOW6432 KEY_WOW64_32KEY
+#else
+#define KREG_WOW6432 0
+#endif
+
+typedef struct APX_STDWRAP {
+ LPCWSTR szLogPath;
+ LPCWSTR szStdOutFilename;
+ LPCWSTR szStdErrFilename;
+ FILE *fpStdOutFile;
+ FILE *fpStdErrFile;
+} APX_STDWRAP;
+
+/* Use static variables instead of #defines */
+static LPCWSTR PRSRV_AUTO = L"auto";
+static LPCWSTR PRSRV_JAVA = L"java";
+static LPCWSTR PRSRV_JVM = L"jvm";
+static LPCWSTR PRSRV_MANUAL = L"manual";
+static LPCWSTR PRSRV_JBIN = L"\\bin\\java.exe";
+static LPCWSTR PRSRV_SIGNAL = L"SIGNAL";
+
+static LPCWSTR STYPE_INTERACTIVE = L"interactive";
+
+static LPWSTR _service_name = NULL;
+/* Allowed procrun commands */
+static LPCWSTR _commands[] = {
+ L"TS", /* 1 Run Service as console application (default)*/
+ L"RS", /* 2 Run Service */
+ L"SS", /* 3 Stop Service */
+ L"US", /* 4 Update Service parameters */
+ L"IS", /* 5 Install Service */
+ L"DS", /* 6 Delete Service */
+ L"?", /* 7 Help */
+ L"VS", /* 8 Version */
+ NULL
+};
+
+/* Allowed procrun parameters */
+static APXCMDLINEOPT _options[] = {
+
+/* 0 */ { L"Description", L"Description", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 1 */ { L"DisplayName", L"DisplayName", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 2 */ { L"Install", L"ImagePath", NULL, APXCMDOPT_STE | APXCMDOPT_SRV, NULL, 0},
+/* 3 */ { L"ServiceUser", L"ServiceUser", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 4 */ { L"ServicePassword", L"ServicePassword", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 5 */ { L"Startup", L"Startup", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 6 */ { L"Type", L"Type", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+
+/* 7 */ { L"DependsOn", L"DependsOn", NULL, APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 8 */ { L"Environment", L"Environment", NULL, APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 9 */ { L"User", L"User", NULL, APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 10 */ { L"Password", L"Password", NULL, APXCMDOPT_BIN | APXCMDOPT_REG, NULL, 0},
+
+/* 11 */ { L"JavaHome", L"JavaHome", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 12 */ { L"Jvm", L"Jvm", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 13 */ { L"JvmOptions", L"Options", L"Java", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 14 */ { L"Classpath", L"Classpath", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 15 */ { L"JvmMs", L"JvmMs", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+/* 16 */ { L"JvmMx", L"JvmMx", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+/* 17 */ { L"JvmSs", L"JvmSs", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+
+/* 18 */ { L"StopImage", L"Image", L"Stop", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 19 */ { L"StopPath", L"WorkingPath", L"Stop", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 20 */ { L"StopClass", L"Class", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 21 */ { L"StopParams", L"Params", L"Stop", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 22 */ { L"StopMethod", L"Method", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 23 */ { L"StopMode", L"Mode", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 24 */ { L"StopTimeout", L"Timeout", L"Stop", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+
+/* 25 */ { L"StartImage", L"Image", L"Start", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 26 */ { L"StartPath", L"WorkingPath", L"Start", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 27 */ { L"StartClass", L"Class", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 28 */ { L"StartParams", L"Params", L"Start", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 29 */ { L"StartMethod", L"Method", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 30 */ { L"StartMode", L"Mode", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+
+/* 31 */ { L"LogPath", L"Path", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 32 */ { L"LogPrefix", L"Prefix", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 33 */ { L"LogLevel", L"Level", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 34 */ { L"StdError", L"StdError", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 35 */ { L"StdOutput", L"StdOutput", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 36 */ { L"LogJniMessages", L"LogJniMessages", L"Log", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 1},
+/* 37 */ { L"PidFile", L"PidFile", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+ /* NULL terminate the array */
+ { NULL }
+};
+
+#define GET_OPT_V(x) _options[x].szValue
+#define GET_OPT_I(x) _options[x].dwValue
+#define GET_OPT_T(x) _options[x].dwType
+
+#define ST_DESCRIPTION GET_OPT_T(0)
+#define ST_DISPLAYNAME GET_OPT_T(1)
+#define ST_INSTALL GET_OPT_T(2)
+#define ST_SUSER GET_OPT_T(3)
+#define ST_SPASSWORD GET_OPT_T(4)
+#define ST_STARTUP GET_OPT_T(5)
+#define ST_TYPE GET_OPT_T(6)
+
+#define SO_DESCRIPTION GET_OPT_V(0)
+#define SO_DISPLAYNAME GET_OPT_V(1)
+#define SO_INSTALL GET_OPT_V(2)
+#define SO_SUSER GET_OPT_V(3)
+#define SO_SPASSWORD GET_OPT_V(4)
+#define SO_STARTUP GET_OPT_V(5)
+#define SO_TYPE GET_OPT_V(6)
+
+#define SO_DEPENDSON GET_OPT_V(7)
+#define SO_ENVIRONMENT GET_OPT_V(8)
+
+#define SO_USER GET_OPT_V(9)
+#define SO_PASSWORD GET_OPT_V(10)
+
+#define SO_JAVAHOME GET_OPT_V(11)
+#define SO_JVM GET_OPT_V(12)
+#define SO_JVMOPTIONS GET_OPT_V(13)
+#define SO_CLASSPATH GET_OPT_V(14)
+#define SO_JVMMS GET_OPT_I(15)
+#define SO_JVMMX GET_OPT_I(16)
+#define SO_JVMSS GET_OPT_I(17)
+
+#define SO_STOPIMAGE GET_OPT_V(18)
+#define SO_STOPPATH GET_OPT_V(19)
+#define SO_STOPCLASS GET_OPT_V(20)
+#define SO_STOPPARAMS GET_OPT_V(21)
+#define SO_STOPMETHOD GET_OPT_V(22)
+#define SO_STOPMODE GET_OPT_V(23)
+#define SO_STOPTIMEOUT GET_OPT_I(24)
+
+#define SO_STARTIMAGE GET_OPT_V(25)
+#define SO_STARTPATH GET_OPT_V(26)
+#define SO_STARTCLASS GET_OPT_V(27)
+#define SO_STARTPARAMS GET_OPT_V(28)
+#define SO_STARTMETHOD GET_OPT_V(29)
+#define SO_STARTMODE GET_OPT_V(30)
+
+#define SO_LOGPATH GET_OPT_V(31)
+#define SO_LOGPREFIX GET_OPT_V(32)
+#define SO_LOGLEVEL GET_OPT_V(33)
+
+#define SO_STDERROR GET_OPT_V(34)
+#define SO_STDOUTPUT GET_OPT_V(35)
+#define SO_JNIVFPRINTF GET_OPT_I(36)
+#define SO_PIDFILE GET_OPT_V(37)
+
+/* Main service table entry
+ * filled at run-time
+ */
+static SERVICE_TABLE_ENTRYW _service_table[] = {
+ {NULL, NULL},
+ {NULL, NULL}
+};
+
+static SERVICE_STATUS _service_status;
+static SERVICE_STATUS_HANDLE _service_status_handle = NULL;
+/* Set if launched by SCM */
+static BOOL _service_mode = FALSE;
+/* JVM used as worker */
+static BOOL _jni_startup = FALSE;
+/* JVM used for shutdown */
+static BOOL _jni_shutdown = FALSE;
+/* Java used as worker */
+static BOOL _java_startup = FALSE;
+/* Java used for shutdown */
+static BOOL _java_shutdown = FALSE;
+/* Global variables and objects */
+static APXHANDLE gPool;
+static APXHANDLE gWorker;
+static APX_STDWRAP gStdwrap; /* stdio/stderr redirection */
+
+static LPWSTR _jni_jvmpath = NULL; /* Path to jvm dll */
+static LPSTR _jni_jvmoptions = NULL; /* Path to jvm options */
+
+static LPSTR _jni_classpath = NULL;
+static LPCWSTR _jni_rparam = NULL; /* Startup arguments */
+static LPCWSTR _jni_sparam = NULL; /* Shutdown arguments */
+static LPSTR _jni_rmethod = NULL; /* Startup method */
+static LPSTR _jni_smethod = NULL; /* Shutdown method */
+static LPSTR _jni_rclass = NULL; /* Startup class */
+static LPSTR _jni_sclass = NULL; /* Shutdown class */
+
+static HANDLE gShutdownEvent = NULL;
+static HANDLE gSignalEvent = NULL;
+static HANDLE gSignalThread = NULL;
+static HANDLE gPidfileHandle = NULL;
+static LPWSTR gPidfileName = NULL;
+static BOOL gSignalValid = TRUE;
+
+DWORD WINAPI eventThread(LPVOID lpParam)
+{
+ for (;;) {
+ DWORD dw = WaitForSingleObject(gSignalEvent, INFINITE);
+ if (dw == WAIT_OBJECT_0 && gSignalValid) {
+ if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0))
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ ResetEvent(gSignalEvent);
+ }
+ else
+ break;
+ }
+ ExitThread(0);
+ return 0;
+}
+
+/* redirect console stdout/stderr to files
+ * so that java messages can get logged
+ * If stderrfile is not specified it will
+ * go to stdoutfile.
+ */
+static BOOL redirectStdStreams(APX_STDWRAP *lpWrapper)
+{
+ BOOL aErr = FALSE;
+ BOOL aOut = FALSE;
+
+ if (lpWrapper->szStdOutFilename || lpWrapper->szStdErrFilename)
+ AllocConsole();
+ /* redirect to file or console */
+ if (lpWrapper->szStdOutFilename) {
+ if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
+ aOut = TRUE;
+ lpWrapper->szStdOutFilename = apxLogFile(gPool,
+ lpWrapper->szLogPath,
+ L"service-stdout",
+ NULL, TRUE);
+ }
+ /* Delete the file if not in append mode
+ * XXX: See if we can use the params instead of that.
+ */
+ if (!aOut)
+ DeleteFileW(lpWrapper->szStdOutFilename);
+ if ((lpWrapper->fpStdOutFile = _wfopen(lpWrapper->szStdOutFilename,
+ L"a"))) {
+ _dup2(_fileno(lpWrapper->fpStdOutFile), 1);
+ *stdout = *lpWrapper->fpStdOutFile;
+ setvbuf(stdout, NULL, _IONBF, 0);
+ }
+ }
+ if (lpWrapper->szStdErrFilename) {
+ if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
+ aErr = TRUE;
+ lpWrapper->szStdErrFilename = apxLogFile(gPool,
+ lpWrapper->szLogPath,
+ L"service-stderr",
+ NULL, TRUE);
+ }
+ if (!aErr)
+ DeleteFileW(lpWrapper->szStdErrFilename);
+ if ((lpWrapper->fpStdErrFile = _wfopen(lpWrapper->szStdErrFilename,
+ L"a"))) {
+ _dup2(_fileno(lpWrapper->fpStdErrFile), 2);
+ *stderr = *lpWrapper->fpStdErrFile;
+ setvbuf(stderr, NULL, _IONBF, 0);
+ }
+ }
+ else if (lpWrapper->fpStdOutFile) {
+ _dup2(_fileno(lpWrapper->fpStdOutFile), 2);
+ *stderr = *lpWrapper->fpStdOutFile;
+ setvbuf(stderr, NULL, _IONBF, 0);
+ }
+ return TRUE;
+}
+
+/* Debugging functions */
+static void printUsage(LPAPXCMDLINE lpCmdline, BOOL isHelp)
+{
+ int i = 0;
+ fwprintf(stderr, L"Usage: %s //CMD//Service [--options]\n",
+ lpCmdline->szExecutable);
+ fwprintf(stderr, L" Commands:\n");
+ if (isHelp)
+ fwprintf(stderr, L" //? This page\n");
+ fwprintf(stderr, L" //IS[//ServiceName] Install Service\n");
+ fwprintf(stderr, L" //US[//ServiceName] Update Service parameters\n");
+ fwprintf(stderr, L" //DS[//ServiceName] Delete Service\n");
+ fwprintf(stderr, L" //RS[//ServiceName] Run Service\n");
+ fwprintf(stderr, L" //SS[//ServiceName] Stop Service\n");
+ fwprintf(stderr, L" //TS[//ServiceName] Run Service as console application\n");
+ fwprintf(stderr, L" //PP[//Num Seconds] Sleep for n Seconds (defaults to 60)\n");
+ fwprintf(stderr, L" //VS Display version\n");
+ fwprintf(stderr, L" Options:\n");
+ while (_options[i].szName) {
+ fwprintf(stderr, L" --%s\n", _options[i].szName);
+ ++i;
+ }
+}
+
+static void printVersion(void)
+{
+#ifdef _WIN64
+ int b = 64;
+#else
+ int b = 32;
+#endif
+ fwprintf(stderr, L"Commons Daemon Service Runner version %S/Win%d (%S)\n",
+ PRG_VERSION, b, __DATE__);
+ fwprintf(stderr, L"Copyright (c) 2000-2010 The Apache Software Foundation.\n");
+}
+
+/* Display configuration parameters */
+static void dumpCmdline()
+{
+ int i = 0;
+ while (_options[i].szName) {
+ if (_options[i].dwType & APXCMDOPT_INT)
+ fwprintf(stderr, L"--%-16s %d\n", _options[i].szName,
+ _options[i].dwValue);
+ else if (_options[i].szValue)
+ fwprintf(stderr, L"--%-16s %s\n", _options[i].szName,
+ _options[i].szValue);
+ else
+ fwprintf(stderr, L"--%-16s <NULL>\n", _options[i].szName);
+ ++i;
+ }
+}
+
+static void setInprocEnvironment()
+{
+ LPWSTR p, e;
+
+ if (!SO_ENVIRONMENT)
+ return; /* Nothing to do */
+
+ for (p = SO_ENVIRONMENT; *p; p++) {
+ e = apxExpandStrW(gPool, p);
+ _wputenv(e);
+ apxFree(e);
+ while (*p)
+ p++;
+ }
+}
+
+/* Load the configuration from Registry
+ * loads only nonspecified items
+ */
+static BOOL loadConfiguration(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hRegistry;
+ int i = 0;
+
+ SetLastError(ERROR_SUCCESS);
+ hRegistry = apxCreateRegistryW(gPool, KEY_READ | KREG_WOW6432,
+ PRG_REGROOT,
+ lpCmdline->szApplication,
+ APXREG_SOFTWARE | APXREG_SERVICE);
+ if (IS_INVALID_HANDLE(hRegistry)) {
+ if (GetLastError() == ERROR_FILE_NOT_FOUND)
+ apxLogWrite(APXLOG_MARK_WARN "The system cannot find the Registry key for service '%S'",
+ lpCmdline->szApplication);
+ else
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ /* browse through options */
+ while (_options[i].szName) {
+ DWORD dwFrom;
+
+ dwFrom = (_options[i].dwType & APXCMDOPT_REG) ? APXREG_PARAMSOFTWARE : APXREG_SERVICE;
+ if (!(_options[i].dwType & APXCMDOPT_FOUND)) {
+ if (_options[i].dwType & APXCMDOPT_STR) {
+ _options[i].szValue = apxRegistryGetStringW(hRegistry,
+ dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry);
+ /* Expand environment variables */
+ if (_options[i].szValue && (_options[i].dwType & APXCMDOPT_STE)) {
+ LPWSTR exp = apxExpandStrW(gPool, _options[i].szValue);
+ if (exp != _options[i].szValue)
+ apxFree(_options[i].szValue);
+ _options[i].szValue = exp;
+ }
+ }
+ else if (_options[i].dwType & APXCMDOPT_INT) {
+ _options[i].dwValue = apxRegistryGetNumberW(hRegistry,
+ dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry);
+ }
+ else if (_options[i].dwType & APXCMDOPT_MSZ) {
+ _options[i].szValue = apxRegistryGetMzStrW(hRegistry,
+ dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ NULL,
+ &(_options[i].dwValue));
+ }
+ }
+ /* Merge the command line options with registry */
+ else if (_options[i].dwType & APXCMDOPT_ADD) {
+ LPWSTR cv = _options[i].szValue;
+ LPWSTR ov = NULL;
+ if (_options[i].dwType & APXCMDOPT_MSZ) {
+ ov = apxRegistryGetMzStrW(hRegistry, dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ NULL,
+ &(_options[i].dwValue));
+ _options[i].szValue = apxMultiSzCombine(gPool, ov, cv,
+ &(_options[i].dwValue));
+ if (ov)
+ apxFree(ov);
+ }
+ }
+ ++i;
+ }
+ apxCloseHandle(hRegistry);
+#ifdef _DEBUG
+ dumpCmdline();
+#endif
+ return TRUE;
+}
+
+/* Save changed configuration to registry
+ */
+static BOOL saveConfiguration(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hRegistry;
+ int i = 0;
+ hRegistry = apxCreateRegistryW(gPool, KEY_WRITE | KREG_WOW6432,
+ PRG_REGROOT,
+ lpCmdline->szApplication,
+ APXREG_SOFTWARE | APXREG_SERVICE);
+ if (IS_INVALID_HANDLE(hRegistry))
+ return FALSE;
+ /* TODO: Use array size */
+ while (_options[i].szName) {
+ /* Skip the service params */
+ if ((_options[i].dwType & APXCMDOPT_SRV) ||
+ !(_options[i].dwType & APXCMDOPT_FOUND)) {
+ /* Skip non-modified version */
+ }
+ /* Update only modified params */
+ else if (_options[i].dwType & APXCMDOPT_STR)
+ apxRegistrySetStrW(hRegistry, APXREG_PARAMSOFTWARE,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ _options[i].szValue);
+ else if (_options[i].dwType & APXCMDOPT_INT)
+ apxRegistrySetNumW(hRegistry, APXREG_PARAMSOFTWARE,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ _options[i].dwValue);
+ else if (_options[i].dwType & APXCMDOPT_MSZ)
+ apxRegistrySetMzStrW(hRegistry, APXREG_PARAMSOFTWARE,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ _options[i].szValue,
+ _options[i].dwValue);
+ ++i;
+ }
+ apxCloseHandle(hRegistry);
+ return TRUE;
+}
+
+/* Operations */
+static BOOL docmdInstallService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv;
+ DWORD dwStart = SERVICE_DEMAND_START;
+ DWORD dwType = SERVICE_WIN32_OWN_PROCESS;
+ WCHAR szImage[SIZ_HUGLEN];
+
+ apxLogWrite(APXLOG_MARK_DEBUG "Installing service...");
+ hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+ /* Check the startup mode */
+ if ((ST_STARTUP & APXCMDOPT_FOUND) &&
+ lstrcmpiW(SO_STARTUP, PRSRV_AUTO) == 0)
+ dwStart = SERVICE_AUTO_START;
+ /* Check the service type */
+ if ((ST_TYPE & APXCMDOPT_FOUND) &&
+ lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE) == 0)
+ dwType |= SERVICE_INTERACTIVE_PROCESS;
+
+ /* Check if --Install is provided */
+ if (!SO_INSTALL) {
+ lstrlcpyW(szImage, SIZ_HUGLEN, lpCmdline->szExePath);
+ lstrlcatW(szImage, SIZ_HUGLEN, L"\\");
+ lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szExecutable);
+ lstrlcatW(szImage, SIZ_HUGLEN, L".exe");
+ }
+ else
+ lstrcpyW(szImage, SO_INSTALL);
+ /* Replace not needed qoutes */
+ apxStrQuoteInplaceW(szImage);
+ /* Add run-service command line option */
+ lstrlcatW(szImage, SIZ_HUGLEN, L" //RS//");
+ lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szApplication);
+ SO_INSTALL = apxPoolStrdupW(gPool, szImage);
+ /* Ensure that option gets saved in the registry */
+ ST_INSTALL |= APXCMDOPT_FOUND;
+#ifdef _DEBUG
+ /* Display configured options */
+ dumpCmdline();
+#endif
+ apxLogWrite(APXLOG_MARK_INFO "Service %S name %S", lpCmdline->szApplication,
+ SO_DISPLAYNAME);
+ rv = apxServiceInstall(hService,
+ lpCmdline->szApplication,
+ SO_DISPLAYNAME, /* --DisplayName */
+ SO_INSTALL,
+ SO_DEPENDSON, /* --DependendsOn */
+ dwType,
+ dwStart);
+ /* Set the --Description */
+ if (rv) {
+ LPCWSTR sd = NULL;
+ LPCWSTR su = NULL;
+ LPCWSTR sp = NULL;
+ if (ST_DESCRIPTION & APXCMDOPT_FOUND) {
+ sd = SO_DESCRIPTION;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service description %S",
+ SO_DESCRIPTION);
+ }
+ if (ST_SUSER & APXCMDOPT_FOUND) {
+ su = SO_SUSER;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service user %S",
+ SO_SUSER);
+ }
+ if (ST_SPASSWORD & APXCMDOPT_FOUND) {
+ sp = SO_SPASSWORD;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service password %S",
+ SO_SPASSWORD);
+ }
+ apxServiceSetNames(hService, NULL, NULL, sd, su, sp);
+ }
+ apxCloseHandle(hService);
+ if (rv) {
+ saveConfiguration(lpCmdline);
+ apxLogWrite(APXLOG_MARK_INFO "Service '%S' installed",
+ lpCmdline->szApplication);
+ }
+ else
+ apxLogWrite(APXLOG_MARK_ERROR "Failed installing '%S' service",
+ lpCmdline->szApplication);
+
+ return rv;
+}
+
+static BOOL docmdDeleteService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv = FALSE;
+
+ apxLogWrite(APXLOG_MARK_INFO "Deleting service...");
+ hService = apxCreateService(gPool, SC_MANAGER_CONNECT, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+ /* Delete service will stop the service if running */
+ if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ WCHAR szWndManagerClass[SIZ_RESLEN];
+ HANDLE hWndManager = NULL;
+ lstrlcpyW(szWndManagerClass, SIZ_RESLEN, lpCmdline->szApplication);
+ lstrlcatW(szWndManagerClass, SIZ_RESLEN, L"_CLASS");
+ /* Close the monitor application if running */
+ if ((hWndManager = FindWindowW(szWndManagerClass, NULL)) != NULL) {
+ SendMessage(hWndManager, WM_CLOSE, 0, 0);
+ }
+ rv = apxServiceDelete(hService);
+ }
+ if (rv) {
+ /* Delete all service registry settings */
+ apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, KREG_WOW6432, TRUE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Service '%S' deleted",
+ lpCmdline->szApplication);
+ }
+ else {
+ apxDisplayError(FALSE, NULL, 0, "Unable to delete '%S' service",
+ lpCmdline->szApplication);
+ }
+ apxCloseHandle(hService);
+ apxLogWrite(APXLOG_MARK_INFO "Delete service finished.");
+ return rv;
+}
+
+static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv = FALSE;
+
+ apxLogWrite(APXLOG_MARK_INFO "Stopping service '%S' ...",
+ lpCmdline->szApplication);
+ hService = apxCreateService(gPool, GENERIC_ALL, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+
+ SetLastError(ERROR_SUCCESS);
+ /* Open the service */
+ if (apxServiceOpen(hService, lpCmdline->szApplication,
+ GENERIC_READ | GENERIC_EXECUTE)) {
+ rv = apxServiceControl(hService,
+ SERVICE_CONTROL_STOP,
+ 0,
+ NULL,
+ NULL);
+ if (rv)
+ apxLogWrite(APXLOG_MARK_INFO "Service '%S' stopped",
+ lpCmdline->szApplication);
+ else
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to stop '%S' service",
+ lpCmdline->szApplication);
+
+ }
+ else
+ apxDisplayError(FALSE, NULL, 0, "Unable to open '%S' service",
+ lpCmdline->szApplication);
+ apxCloseHandle(hService);
+ apxLogWrite(APXLOG_MARK_INFO "Stop service finished.");
+ return rv;
+}
+
+static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv = TRUE;
+
+ apxLogWrite(APXLOG_MARK_INFO "Updating service...");
+
+ hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+ SetLastError(0);
+ /* Open the service */
+ if (!apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ /* Close the existing manager handler.
+ * It will be reopened inside install.
+ */
+ apxCloseHandle(hService);
+ /* In case service doesn't exist try to install it.
+ * Install will fail if there is no minimum parameters required.
+ */
+ return docmdInstallService(lpCmdline);
+ }
+ else {
+ DWORD dwStart = SERVICE_NO_CHANGE;
+ DWORD dwType = SERVICE_NO_CHANGE;
+ LPCWSTR su = NULL;
+ LPCWSTR sp = NULL;
+ if (ST_SUSER & APXCMDOPT_FOUND) {
+ su = SO_SUSER;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service user %S",
+ SO_SUSER);
+ }
+ if (ST_SPASSWORD & APXCMDOPT_FOUND) {
+ sp = SO_SPASSWORD;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service password %S",
+ SO_SPASSWORD);
+ }
+ rv = (rv && apxServiceSetNames(hService,
+ NULL, /* Never update the ImagePath */
+ SO_DISPLAYNAME,
+ SO_DESCRIPTION,
+ su,
+ sp));
+ /* Update the --Startup mode */
+ if (ST_STARTUP & APXCMDOPT_FOUND) {
+ if (!lstrcmpiW(SO_STARTUP, PRSRV_AUTO))
+ dwStart = SERVICE_AUTO_START;
+ else if (!lstrcmpiW(SO_STARTUP, PRSRV_MANUAL))
+ dwStart = SERVICE_DEMAND_START;
+ }
+ if (ST_TYPE & APXCMDOPT_FOUND) {
+ if (!lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE))
+ dwType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS;
+ }
+ rv = (rv && apxServiceSetOptions(hService,
+ dwType,
+ dwStart,
+ SERVICE_NO_CHANGE));
+
+ apxLogWrite(APXLOG_MARK_INFO "Service '%S' updated",
+ lpCmdline->szApplication);
+
+ rv = (rv && saveConfiguration(lpCmdline));
+ }
+ apxCloseHandle(hService);
+ if (rv)
+ apxLogWrite(APXLOG_MARK_INFO "Update service finished.");
+ else
+ apxLogWrite(APXLOG_MARK_INFO "Update service '%S' failed.",
+ lpCmdline->szApplication);
+ return rv;
+}
+
+
+/* Report the service status to the SCM
+ */
+int reportServiceStatus(DWORD dwCurrentState,
+ DWORD dwWin32ExitCode,
+ DWORD dwWaitHint)
+{
+ static DWORD dwCheckPoint = 1;
+ BOOL fResult = TRUE;
+
+ if (_service_mode && _service_status_handle) {
+ if (dwCurrentState == SERVICE_START_PENDING)
+ _service_status.dwControlsAccepted = 0;
+ else
+ _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+
+ _service_status.dwCurrentState = dwCurrentState;
+ _service_status.dwWin32ExitCode = dwWin32ExitCode;
+ _service_status.dwWaitHint = dwWaitHint;
+
+ if ((dwCurrentState == SERVICE_RUNNING) ||
+ (dwCurrentState == SERVICE_STOPPED))
+ _service_status.dwCheckPoint = 0;
+ else
+ _service_status.dwCheckPoint = dwCheckPoint++;
+ fResult = SetServiceStatus(_service_status_handle, &_service_status);
+ if (!fResult) {
+ /* TODO: Deal with error */
+ }
+ }
+ return fResult;
+}
+
+
+BOOL child_callback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ /* TODO: Make stdout and stderr buffers
+ * to prevent streams intermixing when there
+ * is no separate file for each stream
+ */
+ if (uMsg == WM_CHAR) {
+ int ch = LOWORD(wParam);
+ if (lParam)
+ fputc(ch, stderr);
+ else
+ fputc(ch, stdout);
+ }
+ return TRUE;
+}
+
+/* Executed when the service receives stop event */
+static DWORD WINAPI serviceStop(LPVOID lpParameter)
+{
+ APXHANDLE hWorker = NULL;
+ DWORD rv = 0;
+ BOOL wait_to_die = FALSE;
+ DWORD timeout = SO_STOPTIMEOUT * 1000;
+ DWORD dwCtrlType = (DWORD)((BYTE *)lpParameter - (BYTE *)0);
+
+ apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+
+ if (IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
+ return TRUE; /* Nothing to do */
+ }
+ if (_jni_shutdown) {
+ if (!SO_STARTPATH && SO_STOPPATH) {
+ /* If the Working path is specified change the current directory
+ * but only if the start path wasn't specified already.
+ */
+ SetCurrentDirectoryW(SO_STARTPATH);
+ }
+ hWorker = apxCreateJava(gPool, _jni_jvmpath);
+ if (IS_INVALID_HANDLE(hWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
+ return 1;
+ }
+ if (!apxJavaInitialize(hWorker, _jni_classpath, _jni_jvmoptions,
+ SO_JVMMS, SO_JVMMX, SO_JVMSS, SO_JNIVFPRINTF)) {
+ rv = 2;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
+ goto cleanup;
+ }
+ if (!apxJavaLoadMainClass(hWorker, _jni_sclass, _jni_smethod, _jni_sparam)) {
+ rv = 2;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s",
+ _jni_rclass, _jni_classpath);
+ goto cleanup;
+ }
+ /* Create sutdown event */
+ gShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (!apxJavaStart(hWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed starting java");
+ rv = 3;
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for java jni stop worker to finish...");
+ apxJavaWait(hWorker, INFINITE, FALSE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Java jni stop worker finished.");
+ }
+ wait_to_die = TRUE;
+ }
+ else if (SO_STOPMODE) { /* Only in case we have a stop mode */
+ DWORD nArgs;
+ LPWSTR *pArgs;
+ /* Redirect process */
+ hWorker = apxCreateProcessW(gPool,
+ 0,
+ child_callback,
+ SO_USER,
+ SO_PASSWORD,
+ FALSE);
+ if (IS_INVALID_HANDLE(hWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
+ return 1;
+ }
+ if (!apxProcessSetExecutableW(hWorker, SO_STOPIMAGE)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
+ SO_STARTIMAGE);
+ rv = 2;
+ goto cleanup;
+ }
+ /* Assemble the command line */
+ if (_java_shutdown) {
+ nArgs = apxJavaCmdInitialize(gPool, SO_CLASSPATH, SO_STOPCLASS,
+ SO_JVMOPTIONS, SO_JVMMS, SO_JVMMX,
+ SO_JVMSS, SO_STOPPARAMS, &pArgs);
+ }
+ else {
+ nArgs = apxMultiSzToArrayW(gPool, SO_STOPPARAMS, &pArgs);
+ }
+
+ /* Pass the argv to child process */
+ if (!apxProcessSetCommandArgsW(hWorker, SO_STOPIMAGE,
+ nArgs, pArgs)) {
+ rv = 3;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
+ nArgs);
+ goto cleanup;
+ }
+ /* Set the working path */
+ if (!apxProcessSetWorkingPathW(hWorker, SO_STOPPATH)) {
+ rv = 4;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
+ SO_STOPPATH);
+ goto cleanup;
+ }
+ /* Finally execute the child process
+ */
+ if (!apxProcessExecute(hWorker)) {
+ rv = 5;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
+ goto cleanup;
+ } else {
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for stop worker to finish...");
+ apxHandleWait(hWorker, INFINITE, FALSE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Stop worker finished.");
+ }
+ wait_to_die = TRUE;
+ }
+cleanup:
+ /* Close Java JNI handle or stop worker
+ * If this is the single JVM instance it will unload
+ * the JVM dll too.
+ * The worker will be closed on service exit.
+ */
+ if (!IS_INVALID_HANDLE(hWorker))
+ apxCloseHandle(hWorker);
+ if (gSignalEvent) {
+ gSignalValid = FALSE;
+ SetEvent(gSignalEvent);
+ WaitForSingleObject(gSignalThread, 1000);
+ CloseHandle(gSignalEvent);
+ CloseHandle(gSignalThread);
+ gSignalEvent = NULL;
+ }
+ SetEvent(gShutdownEvent);
+ if (timeout > 0x7FFFFFFF)
+ timeout = INFINITE; /* If the timeout was '-1' wait forewer */
+ if (wait_to_die && !timeout)
+ timeout = 300 * 1000; /* Use the 5 minute default shutdown */
+
+ if (dwCtrlType == SERVICE_CONTROL_SHUTDOWN)
+ timeout = MIN(timeout, apxGetMaxServiceTimeout(gPool));
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, timeout);
+
+ if (timeout) {
+ FILETIME fts, fte;
+ ULARGE_INTEGER s, e;
+ DWORD nms;
+ /* Wait to give it a chance to die naturally, then kill it. */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for worker to die naturally...");
+ GetSystemTimeAsFileTime(&fts);
+ rv = apxHandleWait(gWorker, timeout, TRUE);
+ GetSystemTimeAsFileTime(&fte);
+ s.LowPart = fts.dwLowDateTime;
+ s.HighPart = fts.dwHighDateTime;
+ e.LowPart = fte.dwLowDateTime;
+ e.HighPart = fte.dwHighDateTime;
+ nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
+ if (rv == WAIT_OBJECT_0) {
+ rv = 0;
+ apxLogWrite(APXLOG_MARK_DEBUG "Worker finished gracefully in %d ms.", nms);
+ }
+ else
+ apxLogWrite(APXLOG_MARK_DEBUG "Worker was killed in %d ms.", nms);
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_DEBUG "Sending WM_CLOSE to worker");
+ apxHandleSendMessage(gWorker, WM_CLOSE, 0, 0);
+ }
+
+ apxLogWrite(APXLOG_MARK_INFO "Service stopped.");
+ reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+ return rv;
+}
+
+/* Executed when the service receives start event */
+static DWORD serviceStart()
+{
+ DWORD rv = 0;
+ DWORD nArgs;
+ LPWSTR *pArgs;
+ FILETIME fts;
+
+ apxLogWrite(APXLOG_MARK_INFO "Starting service...");
+
+ if (!IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
+ return TRUE; /* Nothing to do */
+ }
+ if (SO_PIDFILE) {
+ gPidfileName = apxLogFile(gPool, SO_LOGPATH, SO_PIDFILE, NULL, FALSE);
+ if (GetFileAttributesW(gPidfileName) != INVALID_FILE_ATTRIBUTES) {
+ /* Pid file exists */
+ apxLogWrite(APXLOG_MARK_ERROR "Pid file '%S' exists", gPidfileName);
+ return 1;
+ }
+ }
+ GetSystemTimeAsFileTime(&fts);
+ if (_jni_startup) {
+ if (SO_STARTPATH) {
+ /* If the Working path is specified change the current directory */
+ SetCurrentDirectoryW(SO_STARTPATH);
+ }
+ /* Set the environment using putenv, so JVM can use it */
+ setInprocEnvironment();
+ /* Create the JVM glbal worker */
+ gWorker = apxCreateJava(gPool, _jni_jvmpath);
+ if (IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
+ return 1;
+ }
+ if (!apxJavaInitialize(gWorker, _jni_classpath, _jni_jvmoptions,
+ SO_JVMMS, SO_JVMMX, SO_JVMSS, SO_JNIVFPRINTF)) {
+ rv = 2;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
+ goto cleanup;
+ }
+ if (!apxJavaLoadMainClass(gWorker, _jni_rclass, _jni_rmethod, _jni_rparam)) {
+ rv = 3;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s", _jni_rclass, _jni_classpath);
+ goto cleanup;
+ }
+ apxJavaSetOut(gWorker, TRUE, gStdwrap.szStdErrFilename);
+ apxJavaSetOut(gWorker, FALSE, gStdwrap.szStdOutFilename);
+ if (!apxJavaStart(gWorker)) {
+ rv = 4;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to start Java");
+ goto cleanup;
+ }
+ apxLogWrite(APXLOG_MARK_DEBUG "Java started %s", _jni_rclass);
+ }
+ else {
+ /* Redirect process */
+ gWorker = apxCreateProcessW(gPool,
+ 0,
+ child_callback,
+ SO_USER,
+ SO_PASSWORD,
+ FALSE);
+ if (IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to create process");
+ return 1;
+ }
+ if (!apxProcessSetExecutableW(gWorker, SO_STARTIMAGE)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
+ SO_STARTIMAGE);
+ rv = 2;
+ goto cleanup;
+ }
+ /* Assemble the command line */
+ if (_java_startup) {
+ nArgs = apxJavaCmdInitialize(gPool, SO_CLASSPATH, SO_STARTCLASS,
+ SO_JVMOPTIONS, SO_JVMMS, SO_JVMMX,
+ SO_JVMSS, SO_STARTPARAMS, &pArgs);
+ }
+ else {
+ nArgs = apxMultiSzToArrayW(gPool, SO_STARTPARAMS, &pArgs);
+ }
+
+ /* Pass the argv to child process */
+ if (!apxProcessSetCommandArgsW(gWorker, SO_STARTIMAGE,
+ nArgs, pArgs)) {
+ rv = 3;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
+ nArgs);
+ goto cleanup;
+ }
+ /* Set the working path */
+ if (!apxProcessSetWorkingPathW(gWorker, SO_STARTPATH)) {
+ rv = 4;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
+ SO_STARTPATH);
+ goto cleanup;
+ }
+ /* Finally execute the child process
+ */
+ if (!apxProcessExecute(gWorker)) {
+ rv = 5;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to execute process");
+ goto cleanup;
+ }
+ }
+ if (rv == 0) {
+ FILETIME fte;
+ ULARGE_INTEGER s, e;
+ DWORD nms;
+ /* Create pidfile */
+ if (gPidfileName) {
+ char pids[32];
+ gPidfileHandle = CreateFileW(gPidfileName,
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_NEW,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (gPidfileHandle != INVALID_HANDLE_VALUE) {
+ DWORD wr = 0;
+ if (_jni_startup)
+ _snprintf(pids, 32, "%d\r\n", GetCurrentProcessId());
+ else
+ _snprintf(pids, 32, "%d\r\n", apxProcessGetPid(gWorker));
+ WriteFile(gPidfileHandle, pids, (DWORD)strlen(pids), &wr, NULL);
+ FlushFileBuffers(gPidfileName);
+ }
+ }
+ GetSystemTimeAsFileTime(&fte);
+ s.LowPart = fts.dwLowDateTime;
+ s.HighPart = fts.dwHighDateTime;
+ e.LowPart = fte.dwLowDateTime;
+ e.HighPart = fte.dwHighDateTime;
+ nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
+ apxLogWrite(APXLOG_MARK_INFO "Service started in %d ms.", nms);
+ }
+ return rv;
+cleanup:
+ if (!IS_INVALID_HANDLE(gWorker))
+ apxCloseHandle(gWorker); /* Close the worker handle */
+ gWorker = NULL;
+ return rv;
+}
+
+/* Service control handler
+ */
+void WINAPI service_ctrl_handler(DWORD dwCtrlCode)
+{
+ DWORD threadId;
+ HANDLE stopThread;
+
+ switch (dwCtrlCode) {
+ case SERVICE_CONTROL_STOP:
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
+ /* Stop the service asynchronously */
+ stopThread = CreateThread(NULL, 0,
+ serviceStop,
+ (LPVOID)SERVICE_CONTROL_STOP,
+ 0, &threadId);
+ WaitForSingleObject(stopThread, INFINITE);
+ CloseHandle(stopThread);
+
+ return;
+ case SERVICE_CONTROL_SHUTDOWN:
+ apxLogWrite(APXLOG_MARK_INFO "Service SHUTDOWN signaled");
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
+ /* Stop the service asynchronously */
+ stopThread = CreateThread(NULL, 0,
+ serviceStop,
+ (LPVOID)SERVICE_CONTROL_SHUTDOWN,
+ 0, &threadId);
+ WaitForSingleObject(stopThread, INFINITE);
+ CloseHandle(stopThread);
+ return;
+ case SERVICE_CONTROL_INTERROGATE:
+ reportServiceStatus(_service_status.dwCurrentState,
+ _service_status.dwWin32ExitCode,
+ _service_status.dwWaitHint);
+ return;
+ default:
+ break;
+ }
+}
+
+/* Console control handler
+ *
+ */
+BOOL WINAPI console_handler(DWORD dwCtrlType)
+{
+ switch (dwCtrlType) {
+ case CTRL_BREAK_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console CTRL+BREAK event signaled");
+ return FALSE;
+ case CTRL_C_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console CTRL+C event signaled");
+ serviceStop((LPVOID)SERVICE_CONTROL_STOP);
+ return TRUE;
+ case CTRL_CLOSE_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console CTRL+CLOSE event signaled");
+ serviceStop((LPVOID)SERVICE_CONTROL_STOP);
+ return TRUE;
+ case CTRL_SHUTDOWN_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console SHUTDOWN event signaled");
+ serviceStop((LPVOID)SERVICE_CONTROL_SHUTDOWN);
+ return TRUE;
+ case CTRL_LOGOFF_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console LOGOFF event signaled");
+ if (!_service_mode) {
+ serviceStop((LPVOID)SERVICE_CONTROL_STOP);
+ }
+ return TRUE;
+ break;
+
+ }
+ return FALSE;
+}
+
+/* Main service execution loop */
+void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
+{
+ DWORD rc;
+ _service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ _service_status.dwCurrentState = SERVICE_START_PENDING;
+ _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
+ SERVICE_ACCEPT_PAUSE_CONTINUE;
+ _service_status.dwWin32ExitCode = 0;
+ _service_status.dwCheckPoint = 0;
+ _service_status.dwWaitHint = 0;
+ _service_status.dwServiceSpecificExitCode = 0;
+
+ apxLogWrite(APXLOG_MARK_DEBUG "Inside ServiceMain...");
+
+ if (_service_name) {
+ WCHAR en[SIZ_HUGLEN];
+ int i;
+ PSECURITY_ATTRIBUTES sa = GetNullACL();
+ lstrlcpyW(en, SIZ_DESLEN, L"Global\\");
+ lstrlcatW(en, SIZ_DESLEN, _service_name);
+ lstrlcatW(en, SIZ_DESLEN, PRSRV_SIGNAL);
+ for (i = 7; i < lstrlenW(en); i++) {
+ if (en[i] >= L'a' && en[i] <= L'z')
+ en[i] = en[i] - 32;
+ }
+ gSignalEvent = CreateEventW(sa, TRUE, FALSE, en);
+ CleanNullACL((void *)sa);
+
+ if (gSignalEvent) {
+ DWORD tid;
+ gSignalThread = CreateThread(NULL, 0, eventThread, NULL, 0, &tid);
+ }
+ }
+ /* Check the StartMode */
+ if (SO_STARTMODE) {
+ if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
+ _jni_startup = TRUE;
+ _jni_rclass = WideToUTF8(SO_STARTCLASS);
+ /* Exchange all dots with slashes */
+ apxStrCharReplaceA(_jni_rclass, '.', '/');
+ _jni_rparam = SO_STARTPARAMS;
+ }
+ else if (!lstrcmpiW(SO_STARTMODE, PRSRV_JAVA)) {
+ LPWSTR jx = NULL, szJH = SO_JAVAHOME;
+ if (!szJH)
+ szJH = apxGetJavaSoftHome(gPool, FALSE);
+ if (szJH) {
+ jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
+ lstrcpyW(jx, szJH);
+ lstrcatW(jx, PRSRV_JBIN);
+ SO_STARTPATH = szJH;
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to find Java Runtime Environment.");
+ goto cleanup;
+ }
+ _java_startup = TRUE;
+ /* StartImage now contains the full path to the java.exe */
+ SO_STARTIMAGE = jx;
+ }
+ }
+ /* Check the StopMode */
+ if (SO_STOPMODE) {
+ if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
+ _jni_shutdown = TRUE;
+ _jni_sclass = WideToUTF8(SO_STOPCLASS);
+ apxStrCharReplaceA(_jni_sclass, '.', '/');
+ _jni_sparam = SO_STOPPARAMS;
+ }
+ else if (!lstrcmpiW(SO_STOPMODE, PRSRV_JAVA)) {
+ LPWSTR jx = NULL, szJH = SO_JAVAHOME;
+ if (!szJH)
+ szJH = apxGetJavaSoftHome(gPool, FALSE);
+ if (szJH) {
+ jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
+ lstrcpyW(jx, szJH);
+ lstrcatW(jx, PRSRV_JBIN);
+ SO_STOPPATH = szJH;
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to find Java Runtime Environment.");
+ goto cleanup;
+ }
+ _java_shutdown = TRUE;
+ /* StopImage now contains the full path to the java.exe */
+ SO_STOPIMAGE = jx;
+ }
+ }
+ /* Find the classpath */
+ if (_jni_shutdown || _jni_startup) {
+ if (SO_JVM) {
+ if (lstrcmpW(SO_JVM, PRSRV_AUTO))
+ _jni_jvmpath = SO_JVM;
+ }
+ if (SO_CLASSPATH)
+ _jni_classpath = WideToUTF8(SO_CLASSPATH);
+ if (SO_STARTMETHOD)
+ _jni_rmethod = WideToAscii(SO_STARTMETHOD, (LPSTR)SO_STARTMETHOD);
+ if (SO_STOPMETHOD)
+ _jni_smethod = WideToAscii(SO_STOPMETHOD, (LPSTR)SO_STOPMETHOD);
+ _jni_jvmoptions = MzWideToUTF8(SO_JVMOPTIONS);
+ }
+ if (_service_mode) {
+ /* Register Service Control handler */
+ _service_status_handle = RegisterServiceCtrlHandlerW(_service_name,
+ service_ctrl_handler);
+ if (IS_INVALID_HANDLE(_service_status_handle)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to register Service Control for %S",
+ _service_name);
+ goto cleanup;
+ }
+ /* Allocate console so that events gets processed */
+ AllocConsole();
+ }
+ reportServiceStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
+ if ((rc = serviceStart()) == 0) {
+ /* Service is started */
+ DWORD rv;
+ reportServiceStatus(SERVICE_RUNNING, NO_ERROR, 0);
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for worker to finish...");
+ /* Set console handler to capture CTRL events */
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
+
+ rv = apxHandleWait(gWorker, INFINITE, FALSE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Worker finished.");
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "ServiceStart returned %d", rc);
+ goto cleanup;
+ }
+ if (gShutdownEvent) {
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+ /* Ensure that shutdown thread exits before us */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
+ WaitForSingleObject(gShutdownEvent, ONE_MINUTE);
+ apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
+ CloseHandle(gShutdownEvent);
+ /* This will cause to wait for all threads to exit
+ */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to exit");
+ apxDestroyJvm(ONE_MINUTE);
+ }
+ else {
+ /* We came here without shutdown event
+ * Probably because main() returned without ensuring all threads
+ * have finished
+ */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for all threads to exit");
+ apxDestroyJvm(INFINITE);
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+ }
+ apxLogWrite(APXLOG_MARK_DEBUG "JVM destroyed.");
+ reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+
+ return;
+cleanup:
+ /* Cleanup */
+ reportServiceStatus(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, 0);
+ return;
+}
+
+
+/* Run the service in the debug mode */
+BOOL docmdDebugService(LPAPXCMDLINE lpCmdline)
+{
+ BOOL rv = FALSE;
+
+ _service_mode = FALSE;
+ _service_name = lpCmdline->szApplication;
+ apxLogWrite(APXLOG_MARK_INFO "Debugging '%S' Service...", _service_name);
+ serviceMain(0, NULL);
+ apxLogWrite(APXLOG_MARK_INFO "Debug service finished.");
+ SAFE_CLOSE_HANDLE(gPidfileHandle);
+ if (gPidfileName)
+ DeleteFileW(gPidfileName);
+ return rv;
+}
+
+BOOL docmdRunService(LPAPXCMDLINE lpCmdline)
+{
+ BOOL rv = FALSE;
+
+ _service_mode = TRUE;
+ _service_name = lpCmdline->szApplication;
+ apxLogWrite(APXLOG_MARK_INFO "Running '%S' Service...", _service_name);
+ _service_table[0].lpServiceName = lpCmdline->szApplication;
+ _service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTIONW)serviceMain;
+ rv = (StartServiceCtrlDispatcherW(_service_table) != 0);
+ apxLogWrite(APXLOG_MARK_INFO "Run service finished.");
+ SAFE_CLOSE_HANDLE(gPidfileHandle);
+ if (gPidfileName)
+ DeleteFileW(gPidfileName);
+ return rv;
+}
+
+void __cdecl main(int argc, char **argv)
+{
+ UINT rv = 0;
+
+ LPAPXCMDLINE lpCmdline;
+
+ if (argc > 1 && strncmp(argv[1], "//PP", 4) == 0) {
+ /* Handy sleep routine defaulting to 1 minute */
+ DWORD ss = 60;
+ if (argv[1][4] && argv[1][5] && argv[1][6]) {
+ int us = atoi(argv[1] + 6);
+ if (us > 0)
+ ss = (DWORD)us;
+ }
+ Sleep(ss * 1000);
+ ExitProcess(0);
+ return;
+ }
+ apxHandleManagerInitialize();
+ /* Create the main Pool */
+ gPool = apxPoolCreate(NULL, 0);
+
+ /* Parse the command line */
+ if ((lpCmdline = apxCmdlineParse(gPool, _options, _commands)) == NULL) {
+ apxLogWrite(APXLOG_MARK_ERROR "Invalid command line arguments");
+ rv = 1;
+ goto cleanup;
+ }
+ apxCmdlineLoadEnvVars(lpCmdline);
+ if (lpCmdline->dwCmdIndex < 5) {
+ if (!loadConfiguration(lpCmdline) &&
+ lpCmdline->dwCmdIndex < 4) {
+ apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
+ rv = 2;
+ goto cleanup;
+ }
+ }
+
+ apxLogOpen(gPool, SO_LOGPATH, SO_LOGPREFIX);
+ apxLogLevelSetW(NULL, SO_LOGLEVEL);
+ apxLogWrite(APXLOG_MARK_DEBUG "Commons Daemon procrun log initialized");
+ apxLogWrite(APXLOG_MARK_INFO "Commons Daemon procrun (%s) started", PRG_VERSION);
+
+ AplZeroMemory(&gStdwrap, sizeof(APX_STDWRAP));
+
+ gStdwrap.szLogPath = SO_LOGPATH;
+ /* In debug mode allways use console */
+ if (lpCmdline->dwCmdIndex != 1) {
+ gStdwrap.szStdOutFilename = SO_STDOUTPUT;
+ gStdwrap.szStdErrFilename = SO_STDERROR;
+ }
+ redirectStdStreams(&gStdwrap);
+ if (lpCmdline->dwCmdIndex == 2) {
+ SYSTEMTIME t;
+ GetLocalTime(&t);
+ fprintf(stdout, "\n%d-%02d-%02d %02d:%02d:%02d "
+ "Commons Daemon procrun stdout initialized\n",
+ t.wYear, t.wMonth, t.wDay,
+ t.wHour, t.wMinute, t.wSecond);
+ fprintf(stderr, "\n%d-%02d-%02d %02d:%02d:%02d "
+ "Commons Daemon procrun stderr initialized\n",
+ t.wYear, t.wMonth, t.wDay,
+ t.wHour, t.wMinute, t.wSecond);
+ }
+ switch (lpCmdline->dwCmdIndex) {
+ case 1: /* Run Service as console application */
+ if (!docmdDebugService(lpCmdline))
+ rv = 3;
+ break;
+ case 2: /* Run Service */
+ if (!docmdRunService(lpCmdline))
+ rv = 4;
+ break;
+ case 3: /* Stop Service */
+ if (!docmdStopService(lpCmdline))
+ rv = 5;
+ break;
+ case 4: /* Update Service parameters */
+ if (!docmdUpdateService(lpCmdline))
+ rv = 6;
+ break;
+ case 5: /* Install Service */
+ if (!docmdInstallService(lpCmdline))
+ rv = 7;
+ break;
+ case 6: /* Delete Service */
+ if (!docmdDeleteService(lpCmdline))
+ rv = 8;
+ break;
+ case 7: /* Print Usage and exit */
+ printUsage(lpCmdline, TRUE);
+ break;
+ case 8: /* Print version and exit */
+ printVersion();
+ break;
+ default:
+ /* Unknown command option */
+ apxLogWrite(APXLOG_MARK_ERROR "Unknown command line option");
+ printUsage(lpCmdline, FALSE);
+ rv = 99;
+ break;
+ }
+
+cleanup:
+ if (rv)
+ apxLogWrite(APXLOG_MARK_ERROR "Commons Daemon procrun failed "
+ "with exit value: %d", rv);
+ else
+ apxLogWrite(APXLOG_MARK_INFO "Commons Daemon procrun finished");
+ if (lpCmdline)
+ apxCmdlineFree(lpCmdline);
+ if (_service_status_handle)
+ CloseHandle(_service_status_handle);
+ _service_status_handle = NULL;
+ _flushall();
+ apxLogClose(NULL);
+ apxHandleManagerDestroy();
+ ExitProcess(rv);
+}
Deleted: tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.h
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.h 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,33 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* ====================================================================
- * jar2exe -- convert .jar file to WIN32 executable.
- * Contributed by Mladen Turk <mturk(a)apache.org>
- * 05 Aug 2003
- * ====================================================================
- */
-
-#ifndef _PRUNSRV_H
-#define _PRUNSRV_H
-
-#undef PRG_VERSION
-#define PRG_VERSION "2.0.4.1"
-#define CSV_VERSION 2,0,4,1
-#define PRG_REGROOT L"JBoss\\JBoss Web 2"
-
-#endif /* _PRUNSRV_H */
-
Copied: tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.h (from rev 2689, trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.h (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.h 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,33 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ * jar2exe -- convert .jar file to WIN32 executable.
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+#ifndef _PRUNSRV_H
+#define _PRUNSRV_H
+
+#undef PRG_VERSION
+#define PRG_VERSION "2.0.5.1"
+#define CSV_VERSION 2,0,5,1
+#define PRG_REGROOT L"JBoss\\JBoss Web 2"
+
+#endif /* _PRUNSRV_H */
+
Deleted: tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.rc
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.rc 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,65 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "prunsrv.h"
-
-#define STR_COPYRIGHT "Copyright � 2007 Red Hat Middleware, LLC. " \
- "or its licensors, as applicable."
-
-#define STR_LICENSE "Distributable under LGPL license. " \
- "See terms of license at gnu.org."
-
-#define STR_COMPANY "Red Hat�, Inc."
-#define STR_TRADEMARK "� Red Hat Inc."
-#define STR_PRODUCT "JBoss Web Service wrapper"
-
-IDI_MAINICON ICON "../../resources/jboss.ico"
-IDI_REDHATICON ICON "../../resources/jboss.ico"
-
-1 VERSIONINFO
- FILEVERSION CSV_VERSION
- PRODUCTVERSION CSV_VERSION
- FILEFLAGSMASK 0x3fL
-#if defined(_DEBUG)
- FILEFLAGS 0x03L
-#else
- FILEFLAGS 0x02L
-#endif
- FILEOS 0x40004L
- FILETYPE 0x1L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904b0"
- BEGIN
- VALUE "Comments", STR_COPYRIGHT "\0"
- VALUE "CompanyName", STR_COMPANY "\0"
- VALUE "FileDescription", STR_PRODUCT "\0"
- VALUE "FileVersion", PRG_VERSION
- VALUE "InternalName", STR_PRODUCT "\0"
- VALUE "LegalCopyright", STR_COPYRIGHT "\0"
- VALUE "OriginalFilename", "jbossweb.exe\0"
- VALUE "ProductName", STR_PRODUCT "\0"
- VALUE "ProductVersion", PRG_VERSION
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1200
- END
-END
Copied: tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.rc (from rev 2689, trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.rc (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/apps/prunsrv/prunsrv.rc 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,65 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "prunsrv.h"
+
+#define STR_COPYRIGHT "Copyright � 2010 Red Hat, Inc. " \
+ "or its licensors, as applicable."
+
+#define STR_LICENSE "Distributable under LGPL license. " \
+ "See terms of license at gnu.org."
+
+#define STR_COMPANY "Red Hat�, Inc."
+#define STR_TRADEMARK "� Red Hat Inc."
+#define STR_PRODUCT "JBoss Web Service wrapper"
+
+IDI_MAINICON ICON "../../resources/jboss.ico"
+IDI_REDHATICON ICON "../../resources/jboss.ico"
+
+1 VERSIONINFO
+ FILEVERSION CSV_VERSION
+ PRODUCTVERSION CSV_VERSION
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", STR_COPYRIGHT "\0"
+ VALUE "CompanyName", STR_COMPANY "\0"
+ VALUE "FileDescription", STR_PRODUCT "\0"
+ VALUE "FileVersion", PRG_VERSION
+ VALUE "InternalName", STR_PRODUCT "\0"
+ VALUE "LegalCopyright", STR_COPYRIGHT "\0"
+ VALUE "OriginalFilename", "jbossweb.exe\0"
+ VALUE "ProductName", STR_PRODUCT "\0"
+ VALUE "ProductVersion", PRG_VERSION
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
Deleted: tags/jbosssvc/2.0.8/procrun/src/cmdline.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/cmdline.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/cmdline.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,295 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-#define EXE_SUFFIX L".EXE"
-#define EXE_SUFFIXLEN (sizeof(EXE_SUFFIX) / sizeof(WCHAR) - 1)
-
-#define X86_SUFFIX L".X86"
-#define X64_SUFFIX L".X64"
-#define A64_SUFFIX L".I64"
-
-/* Those two are declared in handles.c */
-extern LPWSTR *_st_sys_argvw;
-extern int _st_sys_argc;
-
-static WCHAR _st_sys_appexe[MAX_PATH];
-/*
- * argv parsing.
- * Parse the argv[0] and split to ExePath and
- * Executable name. Strip the extension ('.exe').
- * Check for command in argv[1] //CMD//Application
- * Parse the options --option value or --option==value
- * break on first argument that doesn't start with '--'
- */
-LPAPXCMDLINE apxCmdlineParse(
- APXHANDLE hPool,
- APXCMDLINEOPT *lpOptions,
- LPCWSTR *lpszCommands)
-{
-
- LPAPXCMDLINE lpCmdline = NULL;
- DWORD l, i = 0, s = 1;
- LPWSTR p;
- WCHAR cmd[4];
- DWORD match;
- BOOL add;
- if (_st_sys_argc < 1)
- return NULL;
-
- l = lstrlenW(_st_sys_argvw[0]);
- if (l < EXE_SUFFIXLEN)
- return NULL;
- if (!(lpCmdline = (LPAPXCMDLINE)apxPoolCalloc(hPool, sizeof(APXCMDLINE))))
- return NULL;
- lpCmdline->hPool = hPool;
- lpCmdline->lpOptions = lpOptions;
- lpCmdline->szExePath = _st_sys_argvw[0];
- p = lpCmdline->szExePath + l;
-
- while (p > lpCmdline->szExePath) {
- if (*p == L'\\') {
- *p++ = L'\0';
- break;
- }
- p--;
- }
- /* Find the path if it wasn't specified in the argv[0] */
- if (p == lpCmdline->szExePath) {
- WCHAR mh[4096];
- LPWSTR m;
- if (GetModuleFileNameW(GetModuleHandle(NULL), mh, 4096)) {
- lpCmdline->szExePath = apxPoolStrdupW(hPool, mh);
- m = lpCmdline->szExePath + lstrlenW(lpCmdline->szExePath);
- while (m > lpCmdline->szExePath) {
- if (*(m--) == L'\\') {
- *(++m) = L'\0';
- break;
- }
- }
- }
- }
- lpCmdline->szExecutable = p;
- p = _st_sys_argvw[0] + l - EXE_SUFFIXLEN;
- if (lstrcmpiW(p, EXE_SUFFIX) == 0)
- *p = L'\0';
- /* Strip CPU specific suffixes */
- l = lstrlenW(_st_sys_argvw[0]);
- if (l > EXE_SUFFIXLEN) {
- p = _st_sys_argvw[0] + l - EXE_SUFFIXLEN;
- if (lstrcmpiW(p, X86_SUFFIX) == 0) {
- *p = L'\0';
- }
- else if (lstrcmpiW(p, X64_SUFFIX) == 0) {
- *p = L'\0';
- }
- else if (lstrcmpiW(p, A64_SUFFIX) == 0) {
- *p = L'\0';
- }
- }
- if (lpszCommands && _st_sys_argc > 1 && lstrlenW(_st_sys_argvw[1]) > 5) {
- if (_st_sys_argvw[1][0] == L'/' &&
- _st_sys_argvw[1][1] == L'/' &&
- _st_sys_argvw[1][5] == L'/') { /* allow max tree char command */
- l = 2;
- while (_st_sys_argvw[1][l] != L'/') {
- cmd[l - 2] = _st_sys_argvw[1][l];
- if (l++ > 3)
- break;
- }
- cmd[l - 2] = L'\0';
- while (lpszCommands[i]) {
- if (lstrcmpW(lpszCommands[i++], cmd) == 0) {
- lpCmdline->dwCmdIndex = i;
- s = 2;
- break;
- }
- }
- if (lpCmdline->dwCmdIndex) {
- _st_sys_argvw[1][l+1] = L'\0';
- lpCmdline->szApplication = &(_st_sys_argvw[1][l+2]);
- if (!lstrlenW(lpCmdline->szApplication))
- lpCmdline->szApplication = _st_sys_argvw[0];
- }
- else {
- apxLogWrite(APXLOG_MARK_ERROR "Unrecognized cmd option %s", cmd);
- s = 2;
- }
- }
- }
- else {
- lpCmdline->szApplication = lpCmdline->szExecutable;
- lpCmdline->dwCmdIndex = 1;
- return lpCmdline;
- }
- for (i = s; i < (DWORD)_st_sys_argc; i++) {
- LPWSTR e = NULL;
- if (_st_sys_argvw[i][0] != L'-' ||
- _st_sys_argvw[i][1] != L'-') {
- if (_st_sys_argvw[i][0] != L'+' ||
- _st_sys_argvw[i][1] != L'+')
- break;
- else
- add = TRUE;
- }
- else
- add = FALSE;
- p = &(_st_sys_argvw[i][2]);
- /* Find if the option has '=' char
- * for --option==value or --option value cases.
- */
- while (*p) {
- if (*p == L'=') {
- *p = L'\0';
- e = p + 1;
- break;
- }
- else
- p++;
- }
- match = 0;
- for (l = 0; lpOptions[l].szName; l++) {
- if (lstrcmpW(lpOptions[l].szName, &(_st_sys_argvw[i][2])) == 0) {
- LPWSTR val;
- /* check if arg is needed */
- if (e)
- val = e;
- else if ((i + 1) < (DWORD)_st_sys_argc)
- val = _st_sys_argvw[++i];
- else {
- lpOptions[l].dwValue = 0;
- lpOptions[l].szValue = NULL;
- lpOptions[l].dwType |= APXCMDOPT_FOUND;
- break;
- }
- if (lpOptions[l].dwType & APXCMDOPT_STR)
- lpOptions[l].szValue = val;
- else if (lpOptions[l].dwType & APXCMDOPT_INT)
- lpOptions[l].dwValue = (DWORD)apxAtoulW(val);
- else if (lpOptions[l].dwType & APXCMDOPT_MSZ) {
- LPWSTR pp;
- BOOL insquote = FALSE, indquote=FALSE;
- DWORD sp = 0;
- LPWSTR ov = lpOptions[l].szValue;
- if (lpOptions[l].dwValue > 2) {
- sp = (lpOptions[l].dwValue - sizeof(WCHAR)) / sizeof(WCHAR);
- }
- lpOptions[l].dwValue = (sp + lstrlenW(val) + 2) * sizeof(WCHAR);
- lpOptions[l].szValue = (LPWSTR)apxPoolCalloc(hPool,
- lpOptions[l].dwValue);
- if (sp) {
- AplMoveMemory(lpOptions[l].szValue, ov, sp * sizeof(WCHAR));
- apxFree(ov);
- }
- pp = val;
- while(*pp) {
- if (*pp == L'\'')
- insquote = !insquote;
- else if (*pp == L'"') {
- indquote = !indquote;
- lpOptions[l].szValue[sp++] = L'"';
- }
- else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
- lpOptions[l].szValue[sp++] = L'\0';
- else
- lpOptions[l].szValue[sp++] = *pp;
- pp++;
- }
- }
- lpOptions[l].dwType |= APXCMDOPT_FOUND;
- if (add)
- lpOptions[l].dwType |= APXCMDOPT_ADD;
- match = l + 1;
- break;
- }
- }
- }
- if (i < (DWORD)_st_sys_argc) {
- lpCmdline->dwArgc = _st_sys_argc - i;
- lpCmdline->lpArgvw = &_st_sys_argvw[i];
- }
- return lpCmdline;
-}
-
-/* Used for future expansion */
-void apxCmdlineFree(
- LPAPXCMDLINE lpCmdline)
-{
-
- apxFree(lpCmdline);
-}
-
-/*
- * Environment variables parsing
- * Each variable is prfixed with PR_
- * for example 'set PR_JVM=auto' has a same meaning as providing '--Jvm auto'
- * on the command line.
- * Multistring varisables are added to the present conf.
- */
-void apxCmdlineLoadEnvVars(
- LPAPXCMDLINE lpCmdline)
-{
- WCHAR szEnv[64];
- int i = 0;
- if (!lpCmdline || !lpCmdline->lpOptions)
- return;
-
- while (lpCmdline->lpOptions[i].szName) {
- DWORD l;
- WCHAR szVar[SIZ_HUGLEN];
- lstrcpyW(szEnv, L"PR_");
- lstrcatW(szEnv, lpCmdline->lpOptions[i].szName);
- l = GetEnvironmentVariableW(szEnv, szVar, SIZ_HUGMAX);
- if (l == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
- apxLogWrite(APXLOG_MARK_ERROR "Error geting environment variable %S",
- szEnv);
- ++i;
- continue;
- }
- if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_STR)) {
- lpCmdline->lpOptions[i].szValue = apxPoolStrdupW(lpCmdline->hPool, szVar);
- lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND;
- }
- else if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_MSZ)) {
- LPWSTR pp;
- BOOL insquote = FALSE, indquote = FALSE;
- DWORD sp = 0;
- lpCmdline->lpOptions[i].szValue = apxPoolCalloc(lpCmdline->hPool,
- (lstrlenW(szVar) + 2) *
- sizeof(WCHAR));
- lstrcpyW(lpCmdline->lpOptions[i].szValue, szVar);
- pp = szVar;
- while(*pp) {
- if (*pp == L'\'')
- insquote = !insquote;
- else if (*pp == L'"') {
- indquote = !indquote;
- lpCmdline->lpOptions[i].szValue[sp++] = L'"';
- }
- else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
- lpCmdline->lpOptions[i].szValue[sp++] = L'\0';
- else
- lpCmdline->lpOptions[i].szValue[sp++] = *pp;
- pp++;
- }
- lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND | APXCMDOPT_ADD;
- }
- ++i;
- }
-
-}
\ No newline at end of file
Copied: tags/jbosssvc/2.0.8/procrun/src/cmdline.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/cmdline.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/cmdline.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/cmdline.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,311 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define EXE_SUFFIX L".EXE"
+#define EXE_SUFFIXLEN (sizeof(EXE_SUFFIX) / sizeof(WCHAR) - 1)
+
+#define X86_SUFFIX L".X86"
+#define X64_SUFFIX L".X64"
+#define A64_SUFFIX L".I64"
+
+/* Those two are declared in handles.c */
+extern LPWSTR *_st_sys_argvw;
+extern int _st_sys_argc;
+
+static WCHAR _st_sys_appexe[MAX_PATH];
+/*
+ * argv parsing.
+ * Parse the argv[0] and split to ExePath and
+ * Executable name. Strip the extension ('.exe').
+ * Check for command in argv[1] //CMD//Application
+ * Parse the options --option value or --option==value
+ * break on first argument that doesn't start with '--'
+ */
+LPAPXCMDLINE apxCmdlineParse(
+ APXHANDLE hPool,
+ APXCMDLINEOPT *lpOptions,
+ LPCWSTR *lpszCommands)
+{
+
+ LPAPXCMDLINE lpCmdline = NULL;
+ DWORD l, i = 0, s = 1;
+ LPWSTR p;
+ WCHAR cmd[4];
+ DWORD match;
+ BOOL add;
+ if (_st_sys_argc < 1)
+ return NULL;
+
+ l = lstrlenW(_st_sys_argvw[0]);
+ if (l < EXE_SUFFIXLEN)
+ return NULL;
+ if (!(lpCmdline = (LPAPXCMDLINE)apxPoolCalloc(hPool, sizeof(APXCMDLINE))))
+ return NULL;
+ lpCmdline->hPool = hPool;
+ lpCmdline->lpOptions = lpOptions;
+ lpCmdline->szExePath = _st_sys_argvw[0];
+ p = lpCmdline->szExePath + l;
+
+ while (p > lpCmdline->szExePath) {
+ if (*p == L'\\') {
+ *p++ = L'\0';
+ break;
+ }
+ p--;
+ }
+ /* Find the path if it wasn't specified in the argv[0] */
+ if (p == lpCmdline->szExePath) {
+ WCHAR mh[4096];
+ LPWSTR m;
+ if (GetModuleFileNameW(GetModuleHandle(NULL), mh, 4096)) {
+ lpCmdline->szExePath = apxPoolStrdupW(hPool, mh);
+ m = lpCmdline->szExePath + lstrlenW(lpCmdline->szExePath);
+ while (m > lpCmdline->szExePath) {
+ if (*(m--) == L'\\') {
+ *(++m) = L'\0';
+ break;
+ }
+ }
+ }
+ }
+ lpCmdline->szExecutable = p;
+ p = _st_sys_argvw[0] + l - EXE_SUFFIXLEN;
+ if (lstrcmpiW(p, EXE_SUFFIX) == 0)
+ *p = L'\0';
+ /* Strip CPU specific suffixes */
+ l = lstrlenW(_st_sys_argvw[0]);
+ if (l > EXE_SUFFIXLEN) {
+ p = _st_sys_argvw[0] + l - EXE_SUFFIXLEN;
+ if (lstrcmpiW(p, X86_SUFFIX) == 0) {
+ *p = L'\0';
+ }
+ else if (lstrcmpiW(p, X64_SUFFIX) == 0) {
+ *p = L'\0';
+ }
+ else if (lstrcmpiW(p, A64_SUFFIX) == 0) {
+ *p = L'\0';
+ }
+ }
+ if (lpszCommands && _st_sys_argc > 1 && lstrlenW(_st_sys_argvw[1]) > 2) {
+ LPWSTR ca = _st_sys_argvw[1];
+ if (ca[0] == L'/' && ca[1] == L'/') {
+ l = 0;
+ ca += 2;
+ while (*ca && *ca != L'/') {
+ cmd[l] = *ca;
+ if (l++ > 3)
+ break;
+ ca++;
+ }
+ cmd[l] = L'\0';
+ while (lpszCommands[i]) {
+ if (lstrcmpW(lpszCommands[i++], cmd) == 0) {
+ lpCmdline->dwCmdIndex = i;
+ break;
+ }
+ }
+ if (lpCmdline->dwCmdIndex) {
+ while (*ca == '/')
+ *(ca++) = L'\0';
+ if (*ca == '\0')
+ lpCmdline->szApplication = _st_sys_argvw[0];
+ else
+ lpCmdline->szApplication = ca;
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "Unrecognized cmd option %S",
+ _st_sys_argvw[1]);
+ return NULL;
+ }
+ s = 2;
+ }
+ }
+ else {
+ lpCmdline->szApplication = lpCmdline->szExecutable;
+ lpCmdline->dwCmdIndex = 1;
+ return lpCmdline;
+ }
+ for (i = s; i < (DWORD)_st_sys_argc; i++) {
+ LPWSTR e = NULL;
+ if (_st_sys_argvw[i][0] != L'-' ||
+ _st_sys_argvw[i][1] != L'-') {
+ if (_st_sys_argvw[i][0] != L'+' ||
+ _st_sys_argvw[i][1] != L'+')
+ break;
+ else
+ add = TRUE;
+ }
+ else
+ add = FALSE;
+ p = &(_st_sys_argvw[i][2]);
+ /* Find if the option has '=' char
+ * for --option==value or --option value cases.
+ */
+ while (*p) {
+ if (*p == L'=') {
+ *p = L'\0';
+ e = p + 1;
+ break;
+ }
+ else
+ p++;
+ }
+ match = 0;
+ for (l = 0; lpOptions[l].szName; l++) {
+ if (lstrcmpW(lpOptions[l].szName, &(_st_sys_argvw[i][2])) == 0) {
+ LPWSTR val;
+ /* check if arg is needed */
+ if (e)
+ val = e;
+ else if ((i + 1) < (DWORD)_st_sys_argc)
+ val = _st_sys_argvw[++i];
+ else {
+ lpOptions[l].dwValue = 0;
+ lpOptions[l].szValue = NULL;
+ lpOptions[l].dwType |= APXCMDOPT_FOUND;
+ break;
+ }
+ if (lpOptions[l].dwType & APXCMDOPT_STR)
+ lpOptions[l].szValue = val;
+ else if (lpOptions[l].dwType & APXCMDOPT_INT)
+ lpOptions[l].dwValue = (DWORD)apxAtoulW(val);
+ else if (lpOptions[l].dwType & APXCMDOPT_MSZ) {
+ LPWSTR pp;
+ BOOL insquote = FALSE, indquote=FALSE;
+ DWORD sp = 0;
+ LPWSTR ov = lpOptions[l].szValue;
+ if (lpOptions[l].dwValue > 2) {
+ sp = (lpOptions[l].dwValue - sizeof(WCHAR)) / sizeof(WCHAR);
+ }
+ lpOptions[l].dwValue = (sp + lstrlenW(val) + 2) * sizeof(WCHAR);
+ lpOptions[l].szValue = (LPWSTR)apxPoolCalloc(hPool,
+ lpOptions[l].dwValue);
+ if (sp) {
+ AplMoveMemory(lpOptions[l].szValue, ov, sp * sizeof(WCHAR));
+ apxFree(ov);
+ }
+ pp = val;
+ while(*pp) {
+ if (*pp == L'\'')
+ insquote = !insquote;
+ else if (*pp == L'"') {
+ indquote = !indquote;
+ lpOptions[l].szValue[sp++] = L'"';
+ }
+ else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
+ lpOptions[l].szValue[sp++] = L'\0';
+ else
+ lpOptions[l].szValue[sp++] = *pp;
+ pp++;
+ }
+ }
+ lpOptions[l].dwType |= APXCMDOPT_FOUND;
+ if (add)
+ lpOptions[l].dwType |= APXCMDOPT_ADD;
+ match = l + 1;
+ break;
+ }
+ }
+ if (match == 0) {
+ /* --unknown option
+ *
+ */
+ apxLogWrite(APXLOG_MARK_ERROR "Unrecognized program option %S",
+ _st_sys_argvw[i]);
+ return NULL;
+ }
+ }
+ if (i < (DWORD)_st_sys_argc) {
+ lpCmdline->dwArgc = _st_sys_argc - i;
+ lpCmdline->lpArgvw = &_st_sys_argvw[i];
+ }
+ return lpCmdline;
+}
+
+/* Used for future expansion */
+void apxCmdlineFree(
+ LPAPXCMDLINE lpCmdline)
+{
+
+ apxFree(lpCmdline);
+}
+
+/*
+ * Environment variables parsing
+ * Each variable is prfixed with PR_
+ * for example 'set PR_JVM=auto' has a same meaning as providing '--Jvm auto'
+ * on the command line.
+ * Multistring varisables are added to the present conf.
+ */
+void apxCmdlineLoadEnvVars(
+ LPAPXCMDLINE lpCmdline)
+{
+ WCHAR szEnv[64];
+ int i = 0;
+ if (!lpCmdline || !lpCmdline->lpOptions)
+ return;
+
+ while (lpCmdline->lpOptions[i].szName) {
+ DWORD l;
+ WCHAR szVar[SIZ_HUGLEN];
+ lstrlcpyW(szEnv, SIZ_HUGLEN, L"PR_");
+ lstrlcatW(szEnv, SIZ_HUGLEN, lpCmdline->lpOptions[i].szName);
+ l = GetEnvironmentVariableW(szEnv, szVar, SIZ_HUGMAX);
+ if (l == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
+ apxLogWrite(APXLOG_MARK_ERROR "Error geting environment variable %S",
+ szEnv);
+ ++i;
+ continue;
+ }
+ if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_STR)) {
+ lpCmdline->lpOptions[i].szValue = apxPoolStrdupW(lpCmdline->hPool, szVar);
+ lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND;
+ }
+ else if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_INT)) {
+ lpCmdline->lpOptions[i].dwValue = (DWORD)apxAtoulW(szVar);
+ lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND;
+ }
+ else if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_MSZ)) {
+ LPWSTR pp;
+ BOOL insquote = FALSE, indquote = FALSE;
+ DWORD sp = 0;
+ lpCmdline->lpOptions[i].dwValue = (lstrlenW(szVar) + 2) * sizeof(WCHAR);
+ lpCmdline->lpOptions[i].szValue = apxPoolCalloc(lpCmdline->hPool,
+ lpCmdline->lpOptions[i].dwValue);
+ pp = szVar;
+ while(*pp) {
+ if (*pp == L'\'')
+ insquote = !insquote;
+ else if (*pp == L'"') {
+ indquote = !indquote;
+ lpCmdline->lpOptions[i].szValue[sp++] = L'"';
+ }
+ else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
+ lpCmdline->lpOptions[i].szValue[sp++] = L'\0';
+ else
+ lpCmdline->lpOptions[i].szValue[sp++] = *pp;
+ pp++;
+ }
+ lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND | APXCMDOPT_ADD;
+ }
+ ++i;
+ }
+
+}
+
Deleted: tags/jbosssvc/2.0.8/procrun/src/handles.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/handles.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/handles.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,686 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-#define ALLOCBLOCK_INVALID 0xdeadbeef
-
-typedef struct APXPOOL APXPOOL;
-typedef APXPOOL* LPAPXPOOL;
-
-typedef struct ALLOCBLOCK {
- DWORD dwSize;
- APXHANDLE lpPool;
- APXMEMWORD lpAlign;
-} ALLOCBLOCK, *LPALLOCBLOCK;
-
-struct APXPOOL {
- TAILQ_HEAD(_lHandles, stAPXHANDLE) lHandles;
- TAILQ_HEAD(_lPools, stAPXHANDLE) lPools;
-};
-
-static SYSTEM_INFO _st_sys_info;
-static APXHANDLE _st_sys_pool = NULL;
-static int _st_sys_init = 0;
-static LPVOID _st_sys_page = NULL;
-LPWSTR *_st_sys_argvw = NULL;
-int _st_sys_argc = 0;
-
-#ifdef _DEBUG
-static INT _heap_count = 0;
-static INT _heap_alloc_count = 0;
-static INT _heap_realloc_count = 0;
-
-HANDLE HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
-{
- _heap_count++;
- return HeapCreate(flOptions, dwInitialSize, dwMaximumSize);
-}
-
-BOOL HeapDESTROY(HANDLE hHeap)
-{
- _heap_count--;
- return HeapDestroy(hHeap);
-}
-
-
-LPVOID HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize)
-{
- _heap_alloc_count++;
- return HeapAlloc(hHeap, dwFlags, nSize);
-}
-
-BOOL HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
-{
- _heap_alloc_count--;
- return HeapFree(hHeap, dwFlags, lpMem);
-}
-
-LPVOID HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes)
-{
-
- _heap_realloc_count++;
- return HeapReAlloc(hHeap, dwFlags, lpMem, dwBytes);
-}
-#endif
-
-static LPVOID __apxPoolAllocCore(APXHANDLE hPool,
- DWORD dwSize, DWORD dwOptions)
-{
- DWORD dwPhysicalSize;
- LPALLOCBLOCK lpBlock;
-
- if (!hPool)
- hPool = _st_sys_pool;
- dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
- lpBlock = HeapALLOC(hPool->hHeap, dwOptions, dwPhysicalSize);
- lpBlock->dwSize = dwPhysicalSize;
- lpBlock->lpPool = hPool;
-
- return ((char *)lpBlock + sizeof(ALLOCBLOCK));
-}
-
-static LPVOID __apxPoolReallocCore(APXHANDLE hPool, LPVOID lpMem,
- DWORD dwSize, DWORD dwOptions)
-{
- DWORD dwPhysicalSize;
- LPALLOCBLOCK lpBlock;
- LPALLOCBLOCK lpOrg;
-
- if (!lpMem)
- return __apxPoolAllocCore(hPool, dwSize, dwOptions);
- lpOrg = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
- if (!hPool)
- hPool = _st_sys_pool;
- /* Trying to realloc something that isn't valid */
- if (lpOrg->lpPool == APXHANDLE_INVALID ||
- lpOrg->lpPool != hPool)
- return NULL;
- dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
- lpBlock = HeapREALLOC(hPool->hHeap, dwOptions, lpOrg, dwPhysicalSize);
- lpBlock->dwSize = dwPhysicalSize;
- lpBlock->lpPool = hPool;
-
- return ((char *)lpBlock + sizeof(ALLOCBLOCK));
-}
-
-static void __apxPoolFreeCore(LPVOID lpMem)
-{
- APXHANDLE hPool;
- LPALLOCBLOCK lpBlock = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
-
- if (lpBlock->lpPool != APXHANDLE_INVALID) {
- hPool = lpBlock->lpPool;
- lpBlock->lpPool = APXHANDLE_INVALID;
- }
- else
- return;
- HeapFREE(hPool->hHeap, 0, lpBlock);
-}
-/*
- *
- */
-static DWORD WINAPI __apxHandleEventThread(LPVOID lpParameter)
-{
- APXHANDLE hHandle = (APXHANDLE)lpParameter;
- DWORD rv = 0;
- while (hHandle->dwType != APXHANDLE_TYPE_INVALID) {
- DWORD dwState;
- dwState = WaitForSingleObject(hHandle->hEventHandle, INFINITE);
- /* the flags can be changed to invalid meaning we are killing
- * this event.
- */
- if (dwState == WAIT_OBJECT_0 &&
- hHandle->dwType != APXHANDLE_TYPE_INVALID) {
- if (hHandle->uMsg && (hHandle->wParam || hHandle->lParam)) {
- APXCALLHOOK *lpCall;
- rv = (*hHandle->fnCallback)(hHandle, hHandle->uMsg,
- hHandle->wParam, hHandle->lParam);
- TAILQ_FOREACH(lpCall, &hHandle->lCallbacks, queue) {
- (*lpCall->fnCallback)(hHandle, hHandle->uMsg,
- hHandle->wParam, hHandle->lParam);
- }
- hHandle->uMsg = 0;
- if (!rv)
- break;
- }
- ResetEvent(hHandle->hEventHandle);
- SwitchToThread();
- }
- else
- break;
- }
- ResetEvent(hHandle->hEventHandle);
- /* This will rise the Thread waiting function */
- return 0;
-}
-
-static BOOL __apxPoolCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- LPAPXPOOL lpPool;
- APXHANDLE hCur;
- if (hObject->dwType != APXHANDLE_TYPE_POOL)
- return FALSE;
- lpPool = APXHANDLE_DATA(hObject);
-
- /* recurse the subpools */
- TAILQ_FOREACH(hCur, &lpPool->lPools, queue) {
- __apxPoolCallback(hCur, uMsg, 0, 0);
- }
- /* call the handles callback */
- for(hCur = TAILQ_FIRST(&lpPool->lHandles) ;
- hCur != NULL ;
- hCur = TAILQ_FIRST(&lpPool->lHandles)) {
- apxCloseHandle(hCur);
- }
- /* if we are closing this pool destroy the private Heap */
- if (uMsg == WM_CLOSE) {
- if (hObject->dwFlags & APXHANDLE_HAS_HEAP)
- HeapDESTROY(hObject->hHeap);
- hObject->dwSize = 0;
- }
- else if (uMsg == WM_CLEAR)
- hObject->dwSize = 0;
-
- return TRUE;
-}
-
-static BOOL __apxHandleCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- BOOL rv = FALSE;
- if (hObject->dwType == APXHANDLE_TYPE_INVALID)
- return FALSE;
- /* Default handler handles only close event */
- if (uMsg != WM_CLOSE)
- return FALSE;
- if (hObject->dwType == APXHANDLE_TYPE_WINHANDLE &&
- !(IS_INVALID_HANDLE(hObject->uData.hWinHandle))) {
- rv = CloseHandle(hObject->uData.hWinHandle);
- hObject->uData.hWinHandle = NULL;
- }
- /* Invalidate the handle */
- hObject->dwType = APXHANDLE_TYPE_INVALID;
-
- if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
- DWORD dwState;
- /* Signal the EventThread to exit */
- SetEvent(hObject->hEventHandle);
- /* Wait for EventThread to Exit */
- dwState = WaitForSingleObject(hObject->hEventThread, 1000);
- SAFE_CLOSE_HANDLE(hObject->hEventHandle);
- if (dwState == WAIT_TIMEOUT)
- TerminateThread(hObject->hEventThread, 0);
- SAFE_CLOSE_HANDLE(hObject->hEventThread);
- /* Reset the evant flag */
- hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
- }
- return rv;
-}
-
-static BOOL __apxCreateSystemPool()
-{
- LPAPXPOOL lpPool;
- HANDLE hHeap;
-
- GetSystemInfo(&_st_sys_info);
- apxGetOsLevel();
- /* First create the shared data segment */
- _st_sys_page = VirtualAlloc(NULL, _st_sys_info.dwAllocationGranularity,
- MEM_RESERVE, PAGE_NOACCESS);
- if (!_st_sys_page)
- return FALSE;
- _st_sys_page = VirtualAlloc(_st_sys_page, _st_sys_info.dwAllocationGranularity,
- MEM_COMMIT, PAGE_READWRITE);
-
- /* Create the main Heap */
- hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
- _st_sys_pool = HeapALLOC(hHeap, HEAP_ZERO_MEMORY,
- APX_ALIGN_DEFAULT(APXHANDLE_SZ + sizeof(APXPOOL)));
- _st_sys_pool->hHeap = hHeap;
- _st_sys_pool->dwType = APXHANDLE_TYPE_INVALID;
- if (IS_INVALID_HANDLE(_st_sys_pool->hHeap))
- return FALSE;
- _st_sys_pool->fnCallback = __apxPoolCallback;
- lpPool = APXHANDLE_DATA(_st_sys_pool);
- /* Initialize the pool and object lists */
- TAILQ_INIT(&lpPool->lHandles);
- TAILQ_INIT(&lpPool->lPools);
- _st_sys_pool->dwType = APXHANDLE_TYPE_POOL;
-
- /** TODO: For each unsupported function make a surrogate */
- _st_sys_argvw = CommandLineToArgvW(GetCommandLineW(), &_st_sys_argc);
-
- return TRUE;
-}
-
-BOOL
-apxHandleManagerInitialize()
-{
- BOOL rv;
- if (_st_sys_init++)
- return TRUE;
- rv = __apxCreateSystemPool();
-
- return rv;
-}
-
-BOOL
-apxHandleManagerDestroy()
-{
- HANDLE hHeap;
-
- if (--_st_sys_init == 0) {
- hHeap = _st_sys_pool->hHeap;
- apxCloseHandle(_st_sys_pool);
- /* Destroy the main Heap */
- HeapDESTROY(hHeap);
- _st_sys_pool = NULL;
- VirtualFree(_st_sys_page, 0, MEM_RELEASE);
- GlobalFree(_st_sys_argvw);
- _st_sys_argvw = NULL;
- _st_sys_argc = 0;
-#ifdef _DEBUG
- apxLogWrite(APXLOG_MARK_DEBUG "Alloc Count %d", _heap_alloc_count);
- apxLogWrite(APXLOG_MARK_DEBUG "Realloc Count %d", _heap_realloc_count);
- apxLogWrite(APXLOG_MARK_DEBUG "Heap Count %d", _heap_count);
-#endif
- return TRUE;
- }
-
- return FALSE;
-}
-
-APXHANDLE
-apxPoolCreate(APXHANDLE hParent, DWORD dwOptions)
-{
- APXHANDLE hHandle;
- LPAPXPOOL lpPool;
- HANDLE hHeap;
-
- if (IS_INVALID_HANDLE(hParent))
- hParent = _st_sys_pool;
- if (hParent->dwType != APXHANDLE_TYPE_POOL) {
- apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
- hParent->dwType);
- return INVALID_HANDLE_VALUE;
- }
- /* Allocate the handle from the parent */
- hHandle = __apxPoolAllocCore(hParent, APXHANDLE_SZ + sizeof(APXPOOL),
- HEAP_ZERO_MEMORY);
-
- if (dwOptions & APXHANDLE_HAS_HEAP) {
- /* Create the private Heap */
- hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
- hHandle->dwFlags |= APXHANDLE_HAS_HEAP;
- }
- else
- hHeap = hParent->hHeap;
- hHandle->hHeap = hHeap;
- hHandle->dwType = APXHANDLE_TYPE_POOL;
- hHandle->hPool = hParent;
- hHandle->fnCallback = __apxPoolCallback;
- lpPool = APXHANDLE_DATA(hHandle);
- TAILQ_INIT(&lpPool->lHandles);
- TAILQ_INIT(&lpPool->lPools);
-
- /* Insert the pool to the head of parent pool */
- lpPool = APXHANDLE_DATA(hParent);
- APXHANDLE_SPINLOCK(hParent);
- TAILQ_INSERT_HEAD(&lpPool->lPools, hHandle, queue);
- ++hParent->dwSize;
- APXHANDLE_SPINUNLOCK(hParent);
-
- return hHandle;
-}
-
-LPVOID
-apxPoolAlloc(APXHANDLE hPool, DWORD dwSize)
-{
- if (IS_INVALID_HANDLE(hPool) ||
- (hPool->dwType != APXHANDLE_TYPE_POOL))
- hPool = _st_sys_pool;
- return __apxPoolAllocCore(hPool, dwSize, 0);
-}
-
-LPVOID
-apxPoolCalloc(APXHANDLE hPool, DWORD dwSize)
-{
- if (IS_INVALID_HANDLE(hPool) ||
- (hPool->dwType != APXHANDLE_TYPE_POOL))
- hPool = _st_sys_pool;
- return __apxPoolAllocCore(hPool, dwSize, HEAP_ZERO_MEMORY);
-}
-
-LPVOID
-apxPoolRealloc(APXHANDLE hPool, LPVOID lpMem, DWORD dwNewSize)
-{
- if (IS_INVALID_HANDLE(hPool) ||
- (hPool->dwType != APXHANDLE_TYPE_POOL))
- hPool = _st_sys_pool;
- return __apxPoolReallocCore(hPool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
-}
-
-LPVOID
-apxAlloc(DWORD dwSize)
-{
- return __apxPoolAllocCore(_st_sys_pool, dwSize, 0);
-}
-
-LPVOID
-apxCalloc(DWORD dwSize)
-{
- return __apxPoolAllocCore(_st_sys_pool, dwSize, HEAP_ZERO_MEMORY);
-}
-
-LPVOID
-apxRealloc(LPVOID lpMem, DWORD dwNewSize)
-{
- return __apxPoolReallocCore(_st_sys_pool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
-}
-
-VOID
-apxFree(LPVOID lpMem)
-{
- if (lpMem)
- __apxPoolFreeCore(lpMem);
-
-}
-
-LPWSTR
-apxPoolWStrdupA(APXHANDLE hPool, LPCSTR szSource)
-{
- if (szSource) {
- LPWSTR szDest;
- DWORD l = lstrlenA(szSource);
- szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
- AsciiToWide(szSource, szDest);
- return szDest;
- }
- else
- return NULL;
-}
-
-LPWSTR apxWStrdupA(LPCTSTR szSource)
-{
- return apxPoolWStrdup(_st_sys_pool, szSource);
-}
-
-LPSTR
-apxPoolStrdupA(APXHANDLE hPool, LPCSTR szSource)
-{
- if (szSource) {
- LPSTR szDest;
- DWORD l = lstrlenA(szSource);
- szDest = apxPoolAlloc(hPool, l + 1);
- lstrcpyA(szDest, szSource);
- return szDest;
- }
- else
- return NULL;
-}
-
-LPWSTR
-apxPoolStrdupW(APXHANDLE hPool, LPCWSTR szSource)
-{
- if (szSource) {
- LPWSTR szDest;
- DWORD l = lstrlenW(szSource);
- szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
- lstrcpyW(szDest, szSource);
- return szDest;
- }
- else
- return NULL;
-}
-
-LPSTR
-apxStrdupA(LPCSTR szSource)
-{
- return apxPoolStrdupA(_st_sys_pool, szSource);
-}
-
-LPWSTR
-apxStrdupW(LPCWSTR szSource)
-{
- return apxPoolStrdupW(_st_sys_pool, szSource);
-}
-
-APXHANDLE
-apxHandleCreate(APXHANDLE hPool, DWORD dwFlags,
- LPVOID lpData, DWORD dwDataSize,
- LPAPXFNCALLBACK fnCallback)
-{
- APXHANDLE hHandle;
- LPAPXPOOL lpPool;
-
- if (IS_INVALID_HANDLE(hPool))
- hPool = _st_sys_pool;
- if (hPool->dwType != APXHANDLE_TYPE_POOL) {
- apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
- hPool->dwType);
- return INVALID_HANDLE_VALUE;
- }
- hHandle = __apxPoolAllocCore(hPool, APXHANDLE_SZ + dwDataSize,
- HEAP_ZERO_MEMORY);
-
- hHandle->hPool = hPool;
- if (fnCallback)
- hHandle->fnCallback = fnCallback;
- else
- hHandle->fnCallback = __apxHandleCallback;
-
- if (dwFlags & APXHANDLE_TYPE_WINHANDLE) {
- hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
- hHandle->dwFlags |= APXHANDLE_TYPE_WINHANDLE;
- hHandle->uData.hWinHandle = lpData;
- }
- else if (dwFlags & APXHANDLE_TYPE_LPTR) {
- hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
- hHandle->dwFlags |= APXHANDLE_TYPE_LPTR;
- hHandle->uData.lpPtr = lpData;
- }
- else if (dwDataSize && lpData) {
- hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
- AplCopyMemory(APXHANDLE_DATA(hHandle), lpData, dwDataSize);
- hHandle->dwSize = dwDataSize;
- }
-
- if (dwFlags & APXHANDLE_HAS_EVENT) {
- /* Create the message event and message wathcing thread */
- hHandle->hEventHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
- hHandle->hEventThread = CreateThread(NULL, 0, __apxHandleEventThread,
- hHandle, 0,
- &(hHandle->hEventThreadId));
- if (IS_INVALID_HANDLE(hHandle->hEventThread)) {
- SAFE_CLOSE_HANDLE(hHandle->hEventHandle);
- }
- else
- hHandle->dwFlags |= APXHANDLE_HAS_EVENT;
- }
- TAILQ_INIT(&hHandle->lCallbacks);
- /* Add the handle to the pool's object list */
- lpPool = APXHANDLE_DATA(hPool);
- APXHANDLE_SPINLOCK(hPool);
- TAILQ_INSERT_HEAD(&lpPool->lHandles, hHandle, queue);
- ++hPool->dwSize;
- APXHANDLE_SPINUNLOCK(hPool);
-
- return hHandle;
-}
-
-BOOL
-apxCloseHandle(APXHANDLE hObject)
-{
- LPAPXPOOL lpPool;
- APXCALLHOOK *lpCall;
-
- if (IS_INVALID_HANDLE(hObject) || hObject->dwType == APXHANDLE_TYPE_INVALID)
- return FALSE;
- /* Call the user callback first */
- (*hObject->fnCallback)(hObject, WM_CLOSE, 0, 0);
- /* Now go through the callback chain */
- TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
- (*lpCall->fnCallback)(hObject, WM_CLOSE, 0, 0);
- TAILQ_REMOVE(&hObject->lCallbacks, lpCall, queue);
- __apxPoolFreeCore(lpCall);
- }
-
- hObject->dwType = APXHANDLE_TYPE_INVALID;
- if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
- DWORD dwState;
-
- SetEvent(hObject->hEventHandle);
- dwState = WaitForSingleObject(hObject->hEventThread, 1000);
- SAFE_CLOSE_HANDLE(hObject->hEventHandle);
- if (dwState == WAIT_TIMEOUT)
- TerminateThread(hObject->hEventThread, 0);
- SAFE_CLOSE_HANDLE(hObject->hEventThread);
-
- hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
- }
-
- /* finaly remove the object from the pool's object list */
- if (!IS_INVALID_HANDLE(hObject->hPool)) {
- lpPool = APXHANDLE_DATA(hObject->hPool);
- APXHANDLE_SPINLOCK(hObject->hPool);
- TAILQ_REMOVE(&lpPool->lHandles, hObject, queue);
- hObject->hPool->dwSize--;
- APXHANDLE_SPINUNLOCK(hObject->hPool);
- __apxPoolFreeCore(hObject);
- }
- return TRUE;
-}
-
-LPVOID
-apxHandleGetUserData(APXHANDLE hObject)
-{
- if (hObject->dwType == APXHANDLE_TYPE_INVALID)
- return NULL;
- if (hObject->dwFlags & APXHANDLE_HAS_USERDATA)
- return APXHANDLE_DATA(hObject);
- else
- return hObject->uData.lpPtr;
-}
-
-LPVOID
-apxHandleSetUserData(APXHANDLE hObject, LPVOID lpData, DWORD dwDataSize)
-{
- if (hObject->dwType == APXHANDLE_TYPE_INVALID)
- return NULL;
- if (hObject->dwFlags & APXHANDLE_HAS_USERDATA && hObject->dwSize > 0) {
- AplCopyMemory(APXHANDLE_DATA(hObject), lpData,
- MIN(hObject->dwSize, dwDataSize));
- return APXHANDLE_DATA(hObject);
- }
- else {
- LPVOID lpOrg = hObject->uData.lpPtr;
- hObject->uData.lpPtr = lpData;
- return lpOrg;
- }
-}
-
-BOOL apxHandleSendMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- BOOL rv = TRUE;
- APXCALLHOOK *lpCall;
- if (hObject->dwType == APXHANDLE_TYPE_INVALID)
- return FALSE;
- /* Serialize requests to the callback */
- APXHANDLE_SPINLOCK(hObject);
- if (hObject->fnCallback)
- rv = (*hObject->fnCallback)(hObject, uMsg, wParam, lParam);
- TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
- (*lpCall->fnCallback)(hObject, uMsg, wParam, lParam);
- }
- APXHANDLE_SPINUNLOCK(hObject);
-
- return rv;
-}
-
-BOOL apxHandlePostMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- if (hObject->dwType == APXHANDLE_TYPE_INVALID)
- return FALSE;
- if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
- /* TODO: Create a thread message queue
- * Right now wait while the event gets nonsignaled
- */
- while (WaitForSingleObject(hObject->hEventHandle, 0) == WAIT_OBJECT_0)
- SwitchToThread();
- APXHANDLE_SPINLOCK(hObject);
- SuspendThread(hObject->hEventThread);
- hObject->uMsg = uMsg;
- hObject->wParam = wParam;
- hObject->lParam = lParam;
- /* Signal the event thread to call the user callback */
- SetEvent(hObject->hEventHandle);
- ResumeThread(hObject->hEventThread);
- APXHANDLE_SPINUNLOCK(hObject);
-
- return TRUE;
- }
- return FALSE;
-}
-
-BOOL apxHandleLock(APXHANDLE hObject, BOOL bLock)
-{
- if (bLock)
- APXHANDLE_SPINLOCK(hObject);
- else
- APXHANDLE_SPINUNLOCK(hObject);
-
- return TRUE;
-}
-
-BOOL apxHandleAddHook(APXHANDLE hObject, DWORD dwWhere,
- LPAPXFNCALLBACK fnCallback)
-{
- APXCALLHOOK *lpCall;
-
- if (hObject->dwType == APXHANDLE_TYPE_INVALID || !fnCallback)
- return FALSE;
- lpCall = (APXCALLHOOK *)__apxPoolAllocCore(hObject->hPool,
- sizeof(APXCALLHOOK), 0);
- if (!lpCall)
- return FALSE;
- lpCall->fnCallback = fnCallback;
- APXHANDLE_SPINLOCK(hObject);
- if (dwWhere == APXHANDLE_HOOK_FIRST) {
- TAILQ_INSERT_HEAD(&hObject->lCallbacks, lpCall, queue);
- }
- else {
- TAILQ_INSERT_TAIL(&hObject->lCallbacks, lpCall, queue);
- }
- APXHANDLE_SPINUNLOCK(hObject);
-
- return TRUE;
-}
-
-DWORD apxHandleWait(APXHANDLE hHandle, DWORD dwMilliseconds, BOOL bKill)
-{
- if (IS_INVALID_HANDLE(hHandle))
- return WAIT_ABANDONED;
- if (hHandle->dwType == APXHANDLE_TYPE_JVM)
- return apxJavaWait(hHandle, dwMilliseconds, bKill);
- else if (hHandle->dwType == APXHANDLE_TYPE_PROCESS)
- return apxProcessWait(hHandle, dwMilliseconds, bKill);
- else
- return WAIT_ABANDONED;
-}
-
Copied: tags/jbosssvc/2.0.8/procrun/src/handles.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/handles.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/handles.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/handles.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,689 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define ALLOCBLOCK_INVALID 0xdeadbeef
+
+typedef struct APXPOOL APXPOOL;
+typedef APXPOOL* LPAPXPOOL;
+
+typedef struct ALLOCBLOCK {
+ DWORD dwSize;
+ APXHANDLE lpPool;
+ APXMEMWORD lpAlign;
+} ALLOCBLOCK, *LPALLOCBLOCK;
+
+struct APXPOOL {
+ TAILQ_HEAD(_lHandles, stAPXHANDLE) lHandles;
+ TAILQ_HEAD(_lPools, stAPXHANDLE) lPools;
+};
+
+static SYSTEM_INFO _st_sys_info;
+static APXHANDLE _st_sys_pool = NULL;
+static int _st_sys_init = 0;
+static LPVOID _st_sys_page = NULL;
+LPWSTR *_st_sys_argvw = NULL;
+int _st_sys_argc = 0;
+
+#ifdef _DEBUG
+static INT _heap_count = 0;
+static INT _heap_alloc_count = 0;
+static INT _heap_realloc_count = 0;
+
+HANDLE HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
+{
+ _heap_count++;
+ return HeapCreate(flOptions, dwInitialSize, dwMaximumSize);
+}
+
+BOOL HeapDESTROY(HANDLE hHeap)
+{
+ _heap_count--;
+ return HeapDestroy(hHeap);
+}
+
+
+LPVOID HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize)
+{
+ _heap_alloc_count++;
+ return HeapAlloc(hHeap, dwFlags, nSize);
+}
+
+BOOL HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
+{
+ _heap_alloc_count--;
+ return HeapFree(hHeap, dwFlags, lpMem);
+}
+
+LPVOID HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes)
+{
+
+ _heap_realloc_count++;
+ return HeapReAlloc(hHeap, dwFlags, lpMem, dwBytes);
+}
+#endif
+
+static LPVOID __apxPoolAllocCore(APXHANDLE hPool,
+ DWORD dwSize, DWORD dwOptions)
+{
+ DWORD dwPhysicalSize;
+ LPALLOCBLOCK lpBlock;
+
+ if (!hPool)
+ hPool = _st_sys_pool;
+ dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
+ lpBlock = HeapALLOC(hPool->hHeap, dwOptions, dwPhysicalSize);
+ lpBlock->dwSize = dwPhysicalSize;
+ lpBlock->lpPool = hPool;
+
+ return ((char *)lpBlock + sizeof(ALLOCBLOCK));
+}
+
+static LPVOID __apxPoolReallocCore(APXHANDLE hPool, LPVOID lpMem,
+ DWORD dwSize, DWORD dwOptions)
+{
+ DWORD dwPhysicalSize;
+ LPALLOCBLOCK lpBlock;
+ LPALLOCBLOCK lpOrg;
+
+ if (!lpMem)
+ return __apxPoolAllocCore(hPool, dwSize, dwOptions);
+ lpOrg = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
+ if (!hPool)
+ hPool = _st_sys_pool;
+ /* Trying to realloc something that isn't valid */
+ if (lpOrg->lpPool == APXHANDLE_INVALID ||
+ lpOrg->lpPool != hPool)
+ return NULL;
+ dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
+ lpBlock = HeapREALLOC(hPool->hHeap, dwOptions, lpOrg, dwPhysicalSize);
+ lpBlock->dwSize = dwPhysicalSize;
+ lpBlock->lpPool = hPool;
+
+ return ((char *)lpBlock + sizeof(ALLOCBLOCK));
+}
+
+static void __apxPoolFreeCore(LPVOID lpMem)
+{
+ APXHANDLE hPool;
+ LPALLOCBLOCK lpBlock = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
+
+ if (lpBlock->lpPool != APXHANDLE_INVALID) {
+ hPool = lpBlock->lpPool;
+ lpBlock->lpPool = APXHANDLE_INVALID;
+ }
+ else
+ return;
+ HeapFREE(hPool->hHeap, 0, lpBlock);
+}
+/*
+ *
+ */
+static DWORD WINAPI __apxHandleEventThread(LPVOID lpParameter)
+{
+ APXHANDLE hHandle = (APXHANDLE)lpParameter;
+ DWORD rv = 0;
+ while (hHandle->dwType != APXHANDLE_TYPE_INVALID) {
+ DWORD dwState;
+ dwState = WaitForSingleObject(hHandle->hEventHandle, INFINITE);
+ /* the flags can be changed to invalid meaning we are killing
+ * this event.
+ */
+ if (dwState == WAIT_OBJECT_0 &&
+ hHandle->dwType != APXHANDLE_TYPE_INVALID) {
+ if (hHandle->uMsg && (hHandle->wParam || hHandle->lParam)) {
+ APXCALLHOOK *lpCall;
+ rv = (*hHandle->fnCallback)(hHandle, hHandle->uMsg,
+ hHandle->wParam, hHandle->lParam);
+ TAILQ_FOREACH(lpCall, &hHandle->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hHandle, hHandle->uMsg,
+ hHandle->wParam, hHandle->lParam);
+ }
+ hHandle->uMsg = 0;
+ if (!rv)
+ break;
+ }
+ ResetEvent(hHandle->hEventHandle);
+ SwitchToThread();
+ }
+ else
+ break;
+ }
+ ResetEvent(hHandle->hEventHandle);
+ /* This will rise the Thread waiting function */
+ return 0;
+}
+
+static BOOL __apxPoolCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXPOOL lpPool;
+ APXHANDLE hCur;
+ if (hObject->dwType != APXHANDLE_TYPE_POOL)
+ return FALSE;
+ lpPool = APXHANDLE_DATA(hObject);
+
+ /* recurse the subpools */
+ TAILQ_FOREACH(hCur, &lpPool->lPools, queue) {
+ __apxPoolCallback(hCur, uMsg, 0, 0);
+ }
+ /* call the handles callback */
+ for(hCur = TAILQ_FIRST(&lpPool->lHandles) ;
+ hCur != NULL ;
+ hCur = TAILQ_FIRST(&lpPool->lHandles)) {
+ apxCloseHandle(hCur);
+ }
+ /* if we are closing this pool destroy the private Heap */
+ if (uMsg == WM_CLOSE) {
+ if (hObject->dwFlags & APXHANDLE_HAS_HEAP)
+ HeapDESTROY(hObject->hHeap);
+ hObject->dwSize = 0;
+ }
+ else if (uMsg == WM_CLEAR)
+ hObject->dwSize = 0;
+
+ return TRUE;
+}
+
+static BOOL __apxHandleCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ BOOL rv = FALSE;
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ /* Default handler handles only close event */
+ if (uMsg != WM_CLOSE)
+ return FALSE;
+ if (hObject->dwType == APXHANDLE_TYPE_WINHANDLE &&
+ !(IS_INVALID_HANDLE(hObject->uData.hWinHandle))) {
+ rv = CloseHandle(hObject->uData.hWinHandle);
+ hObject->uData.hWinHandle = NULL;
+ }
+ /* Invalidate the handle */
+ hObject->dwType = APXHANDLE_TYPE_INVALID;
+
+ if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+ DWORD dwState;
+ /* Signal the EventThread to exit */
+ SetEvent(hObject->hEventHandle);
+ /* Wait for EventThread to Exit */
+ dwState = WaitForSingleObject(hObject->hEventThread, 1000);
+ SAFE_CLOSE_HANDLE(hObject->hEventHandle);
+ if (dwState == WAIT_TIMEOUT)
+ TerminateThread(hObject->hEventThread, 0);
+ SAFE_CLOSE_HANDLE(hObject->hEventThread);
+ /* Reset the evant flag */
+ hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
+ }
+ return rv;
+}
+
+static BOOL __apxCreateSystemPool()
+{
+ LPAPXPOOL lpPool;
+ HANDLE hHeap;
+
+ GetSystemInfo(&_st_sys_info);
+ apxGetOsLevel();
+ /* First create the shared data segment */
+ _st_sys_page = VirtualAlloc(NULL, _st_sys_info.dwAllocationGranularity,
+ MEM_RESERVE, PAGE_NOACCESS);
+ if (!_st_sys_page)
+ return FALSE;
+ _st_sys_page = VirtualAlloc(_st_sys_page, _st_sys_info.dwAllocationGranularity,
+ MEM_COMMIT, PAGE_READWRITE);
+
+ /* Create the main Heap */
+ hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
+ _st_sys_pool = HeapALLOC(hHeap, HEAP_ZERO_MEMORY,
+ APX_ALIGN_DEFAULT(APXHANDLE_SZ + sizeof(APXPOOL)));
+ _st_sys_pool->hHeap = hHeap;
+ _st_sys_pool->dwType = APXHANDLE_TYPE_INVALID;
+ if (IS_INVALID_HANDLE(_st_sys_pool->hHeap))
+ return FALSE;
+ _st_sys_pool->fnCallback = __apxPoolCallback;
+ lpPool = APXHANDLE_DATA(_st_sys_pool);
+ /* Initialize the pool and object lists */
+ TAILQ_INIT(&lpPool->lHandles);
+ TAILQ_INIT(&lpPool->lPools);
+ _st_sys_pool->dwType = APXHANDLE_TYPE_POOL;
+
+ /** TODO: For each unsupported function make a surrogate */
+ _st_sys_argvw = CommandLineToArgvW(GetCommandLineW(), &_st_sys_argc);
+
+ return TRUE;
+}
+
+BOOL
+apxHandleManagerInitialize()
+{
+ BOOL rv;
+ if (_st_sys_init++)
+ return TRUE;
+ rv = __apxCreateSystemPool();
+
+ return rv;
+}
+
+BOOL
+apxHandleManagerDestroy()
+{
+ HANDLE hHeap;
+
+ if (--_st_sys_init == 0) {
+ hHeap = _st_sys_pool->hHeap;
+ apxCloseHandle(_st_sys_pool);
+ /* Destroy the main Heap */
+ HeapDESTROY(hHeap);
+ _st_sys_pool = NULL;
+ VirtualFree(_st_sys_page, 0, MEM_RELEASE);
+ GlobalFree(_st_sys_argvw);
+ _st_sys_argvw = NULL;
+ _st_sys_argc = 0;
+#ifdef _DEBUG
+ apxLogWrite(APXLOG_MARK_DEBUG "Alloc Count %d", _heap_alloc_count);
+ apxLogWrite(APXLOG_MARK_DEBUG "Realloc Count %d", _heap_realloc_count);
+ apxLogWrite(APXLOG_MARK_DEBUG "Heap Count %d", _heap_count);
+#endif
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+APXHANDLE
+apxPoolCreate(APXHANDLE hParent, DWORD dwOptions)
+{
+ APXHANDLE hHandle;
+ LPAPXPOOL lpPool;
+ HANDLE hHeap;
+
+ if (IS_INVALID_HANDLE(hParent))
+ hParent = _st_sys_pool;
+ if (hParent->dwType != APXHANDLE_TYPE_POOL) {
+ apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
+ hParent->dwType);
+ return INVALID_HANDLE_VALUE;
+ }
+ /* Allocate the handle from the parent */
+ hHandle = __apxPoolAllocCore(hParent, APXHANDLE_SZ + sizeof(APXPOOL),
+ HEAP_ZERO_MEMORY);
+
+ if (dwOptions & APXHANDLE_HAS_HEAP) {
+ /* Create the private Heap */
+ hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
+ hHandle->dwFlags |= APXHANDLE_HAS_HEAP;
+ }
+ else
+ hHeap = hParent->hHeap;
+ hHandle->hHeap = hHeap;
+ hHandle->dwType = APXHANDLE_TYPE_POOL;
+ hHandle->hPool = hParent;
+ hHandle->fnCallback = __apxPoolCallback;
+ lpPool = APXHANDLE_DATA(hHandle);
+ TAILQ_INIT(&lpPool->lHandles);
+ TAILQ_INIT(&lpPool->lPools);
+
+ /* Insert the pool to the head of parent pool */
+ lpPool = APXHANDLE_DATA(hParent);
+ APXHANDLE_SPINLOCK(hParent);
+ TAILQ_INSERT_HEAD(&lpPool->lPools, hHandle, queue);
+ ++hParent->dwSize;
+ APXHANDLE_SPINUNLOCK(hParent);
+
+ return hHandle;
+}
+
+LPVOID
+apxPoolAlloc(APXHANDLE hPool, DWORD dwSize)
+{
+ if (IS_INVALID_HANDLE(hPool) ||
+ (hPool->dwType != APXHANDLE_TYPE_POOL))
+ hPool = _st_sys_pool;
+ return __apxPoolAllocCore(hPool, dwSize, 0);
+}
+
+LPVOID
+apxPoolCalloc(APXHANDLE hPool, DWORD dwSize)
+{
+ if (IS_INVALID_HANDLE(hPool) ||
+ (hPool->dwType != APXHANDLE_TYPE_POOL))
+ hPool = _st_sys_pool;
+ return __apxPoolAllocCore(hPool, dwSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxPoolRealloc(APXHANDLE hPool, LPVOID lpMem, DWORD dwNewSize)
+{
+ if (IS_INVALID_HANDLE(hPool) ||
+ (hPool->dwType != APXHANDLE_TYPE_POOL))
+ hPool = _st_sys_pool;
+ return __apxPoolReallocCore(hPool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxAlloc(DWORD dwSize)
+{
+ return __apxPoolAllocCore(_st_sys_pool, dwSize, 0);
+}
+
+LPVOID
+apxCalloc(DWORD dwSize)
+{
+ return __apxPoolAllocCore(_st_sys_pool, dwSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxRealloc(LPVOID lpMem, DWORD dwNewSize)
+{
+ return __apxPoolReallocCore(_st_sys_pool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
+}
+
+VOID
+apxFree(LPVOID lpMem)
+{
+ if (lpMem)
+ __apxPoolFreeCore(lpMem);
+
+}
+
+LPWSTR
+apxPoolWStrdupA(APXHANDLE hPool, LPCSTR szSource)
+{
+ if (szSource) {
+ LPWSTR szDest;
+ int cch = MultiByteToWideChar(CP_UTF8, 0, szSource, -1, NULL, 0);
+ szDest = (LPWSTR)apxPoolAlloc(hPool, cch * sizeof(WCHAR));
+ if (!MultiByteToWideChar(CP_UTF8, 0, szSource, -1, szDest, cch)) {
+ apxFree(szDest);
+ return NULL;
+ }
+ return szDest;
+ }
+ else
+ return NULL;
+}
+
+LPWSTR apxWStrdupA(LPCTSTR szSource)
+{
+ return apxPoolWStrdup(_st_sys_pool, szSource);
+}
+
+LPSTR
+apxPoolStrdupA(APXHANDLE hPool, LPCSTR szSource)
+{
+ if (szSource) {
+ LPSTR szDest;
+ DWORD l = lstrlenA(szSource);
+ szDest = apxPoolAlloc(hPool, l + 1);
+ lstrcpyA(szDest, szSource);
+ return szDest;
+ }
+ else
+ return NULL;
+}
+
+LPWSTR
+apxPoolStrdupW(APXHANDLE hPool, LPCWSTR szSource)
+{
+ if (szSource) {
+ LPWSTR szDest;
+ DWORD l = lstrlenW(szSource);
+ szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
+ lstrcpyW(szDest, szSource);
+ return szDest;
+ }
+ else
+ return NULL;
+}
+
+LPSTR
+apxStrdupA(LPCSTR szSource)
+{
+ return apxPoolStrdupA(_st_sys_pool, szSource);
+}
+
+LPWSTR
+apxStrdupW(LPCWSTR szSource)
+{
+ return apxPoolStrdupW(_st_sys_pool, szSource);
+}
+
+APXHANDLE
+apxHandleCreate(APXHANDLE hPool, DWORD dwFlags,
+ LPVOID lpData, DWORD dwDataSize,
+ LPAPXFNCALLBACK fnCallback)
+{
+ APXHANDLE hHandle;
+ LPAPXPOOL lpPool;
+
+ if (IS_INVALID_HANDLE(hPool))
+ hPool = _st_sys_pool;
+ if (hPool->dwType != APXHANDLE_TYPE_POOL) {
+ apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
+ hPool->dwType);
+ return INVALID_HANDLE_VALUE;
+ }
+ hHandle = __apxPoolAllocCore(hPool, APXHANDLE_SZ + dwDataSize,
+ HEAP_ZERO_MEMORY);
+
+ hHandle->hPool = hPool;
+ if (fnCallback)
+ hHandle->fnCallback = fnCallback;
+ else
+ hHandle->fnCallback = __apxHandleCallback;
+
+ if (dwFlags & APXHANDLE_TYPE_WINHANDLE) {
+ hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+ hHandle->dwFlags |= APXHANDLE_TYPE_WINHANDLE;
+ hHandle->uData.hWinHandle = lpData;
+ }
+ else if (dwFlags & APXHANDLE_TYPE_LPTR) {
+ hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+ hHandle->dwFlags |= APXHANDLE_TYPE_LPTR;
+ hHandle->uData.lpPtr = lpData;
+ }
+ else if (dwDataSize && lpData) {
+ hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+ AplCopyMemory(APXHANDLE_DATA(hHandle), lpData, dwDataSize);
+ hHandle->dwSize = dwDataSize;
+ }
+
+ if (dwFlags & APXHANDLE_HAS_EVENT) {
+ /* Create the message event and message wathcing thread */
+ hHandle->hEventHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
+ hHandle->hEventThread = CreateThread(NULL, 0, __apxHandleEventThread,
+ hHandle, 0,
+ &(hHandle->hEventThreadId));
+ if (IS_INVALID_HANDLE(hHandle->hEventThread)) {
+ SAFE_CLOSE_HANDLE(hHandle->hEventHandle);
+ }
+ else
+ hHandle->dwFlags |= APXHANDLE_HAS_EVENT;
+ }
+ TAILQ_INIT(&hHandle->lCallbacks);
+ /* Add the handle to the pool's object list */
+ lpPool = APXHANDLE_DATA(hPool);
+ APXHANDLE_SPINLOCK(hPool);
+ TAILQ_INSERT_HEAD(&lpPool->lHandles, hHandle, queue);
+ ++hPool->dwSize;
+ APXHANDLE_SPINUNLOCK(hPool);
+
+ return hHandle;
+}
+
+BOOL
+apxCloseHandle(APXHANDLE hObject)
+{
+ LPAPXPOOL lpPool;
+ APXCALLHOOK *lpCall;
+
+ if (IS_INVALID_HANDLE(hObject) || hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ /* Call the user callback first */
+ (*hObject->fnCallback)(hObject, WM_CLOSE, 0, 0);
+ /* Now go through the callback chain */
+ TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hObject, WM_CLOSE, 0, 0);
+ TAILQ_REMOVE(&hObject->lCallbacks, lpCall, queue);
+ __apxPoolFreeCore(lpCall);
+ }
+
+ hObject->dwType = APXHANDLE_TYPE_INVALID;
+ if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+ DWORD dwState;
+
+ SetEvent(hObject->hEventHandle);
+ dwState = WaitForSingleObject(hObject->hEventThread, 1000);
+ SAFE_CLOSE_HANDLE(hObject->hEventHandle);
+ if (dwState == WAIT_TIMEOUT)
+ TerminateThread(hObject->hEventThread, 0);
+ SAFE_CLOSE_HANDLE(hObject->hEventThread);
+
+ hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
+ }
+
+ /* finaly remove the object from the pool's object list */
+ if (!IS_INVALID_HANDLE(hObject->hPool)) {
+ lpPool = APXHANDLE_DATA(hObject->hPool);
+ APXHANDLE_SPINLOCK(hObject->hPool);
+ TAILQ_REMOVE(&lpPool->lHandles, hObject, queue);
+ hObject->hPool->dwSize--;
+ APXHANDLE_SPINUNLOCK(hObject->hPool);
+ __apxPoolFreeCore(hObject);
+ }
+ return TRUE;
+}
+
+LPVOID
+apxHandleGetUserData(APXHANDLE hObject)
+{
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return NULL;
+ if (hObject->dwFlags & APXHANDLE_HAS_USERDATA)
+ return APXHANDLE_DATA(hObject);
+ else
+ return hObject->uData.lpPtr;
+}
+
+LPVOID
+apxHandleSetUserData(APXHANDLE hObject, LPVOID lpData, DWORD dwDataSize)
+{
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return NULL;
+ if (hObject->dwFlags & APXHANDLE_HAS_USERDATA && hObject->dwSize > 0) {
+ AplCopyMemory(APXHANDLE_DATA(hObject), lpData,
+ MIN(hObject->dwSize, dwDataSize));
+ return APXHANDLE_DATA(hObject);
+ }
+ else {
+ LPVOID lpOrg = hObject->uData.lpPtr;
+ hObject->uData.lpPtr = lpData;
+ return lpOrg;
+ }
+}
+
+BOOL apxHandleSendMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ BOOL rv = TRUE;
+ APXCALLHOOK *lpCall;
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ /* Serialize requests to the callback */
+ APXHANDLE_SPINLOCK(hObject);
+ if (hObject->fnCallback)
+ rv = (*hObject->fnCallback)(hObject, uMsg, wParam, lParam);
+ TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hObject, uMsg, wParam, lParam);
+ }
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return rv;
+}
+
+BOOL apxHandlePostMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+ /* TODO: Create a thread message queue
+ * Right now wait while the event gets nonsignaled
+ */
+ while (WaitForSingleObject(hObject->hEventHandle, 0) == WAIT_OBJECT_0)
+ SwitchToThread();
+ APXHANDLE_SPINLOCK(hObject);
+ SuspendThread(hObject->hEventThread);
+ hObject->uMsg = uMsg;
+ hObject->wParam = wParam;
+ hObject->lParam = lParam;
+ /* Signal the event thread to call the user callback */
+ SetEvent(hObject->hEventHandle);
+ ResumeThread(hObject->hEventThread);
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+BOOL apxHandleLock(APXHANDLE hObject, BOOL bLock)
+{
+ if (bLock)
+ APXHANDLE_SPINLOCK(hObject);
+ else
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return TRUE;
+}
+
+BOOL apxHandleAddHook(APXHANDLE hObject, DWORD dwWhere,
+ LPAPXFNCALLBACK fnCallback)
+{
+ APXCALLHOOK *lpCall;
+
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID || !fnCallback)
+ return FALSE;
+ lpCall = (APXCALLHOOK *)__apxPoolAllocCore(hObject->hPool,
+ sizeof(APXCALLHOOK), 0);
+ if (!lpCall)
+ return FALSE;
+ lpCall->fnCallback = fnCallback;
+ APXHANDLE_SPINLOCK(hObject);
+ if (dwWhere == APXHANDLE_HOOK_FIRST) {
+ TAILQ_INSERT_HEAD(&hObject->lCallbacks, lpCall, queue);
+ }
+ else {
+ TAILQ_INSERT_TAIL(&hObject->lCallbacks, lpCall, queue);
+ }
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return TRUE;
+}
+
+DWORD apxHandleWait(APXHANDLE hHandle, DWORD dwMilliseconds, BOOL bKill)
+{
+ if (IS_INVALID_HANDLE(hHandle))
+ return WAIT_ABANDONED;
+ if (hHandle->dwType == APXHANDLE_TYPE_JVM)
+ return apxJavaWait(hHandle, dwMilliseconds, bKill);
+ else if (hHandle->dwType == APXHANDLE_TYPE_PROCESS)
+ return apxProcessWait(hHandle, dwMilliseconds, bKill);
+ else
+ return WAIT_ABANDONED;
+}
+
Deleted: tags/jbosssvc/2.0.8/procrun/src/javajni.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/javajni.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/javajni.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,784 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-#include <jni.h>
-
-#ifndef JNI_VERSION_1_2
-#error -------------------------------------------------------
-#error JAVA 1.1 IS NO LONGER SUPPORTED
-#error -------------------------------------------------------
-#endif
-
-#ifdef JNI_VERSION_1_4
-#define JNI_VERSION_DEFAULT JNI_VERSION_1_4
-#else
-#define JNI_VERSION_DEFAULT JNI_VERSION_1_2
-#endif
-
-/* Standard jvm.dll prototypes
- * since only single jvm can exist per process
- * make those global
- */
-
-DYNOLAD_TYPE_DECLARE(JNI_GetDefaultJavaVMInitArgs, JNICALL, jint)(void *);
-static DYNLOAD_FPTR_DECLARE(JNI_GetDefaultJavaVMInitArgs) = NULL;
-
-DYNOLAD_TYPE_DECLARE(JNI_CreateJavaVM, JNICALL, jint)(JavaVM **, void **, void *);
-static DYNLOAD_FPTR_DECLARE(JNI_CreateJavaVM) = NULL;
-
-DYNOLAD_TYPE_DECLARE(JNI_GetCreatedJavaVMs, JNICALL, jint)(JavaVM **, jsize, jsize *);
-static DYNLOAD_FPTR_DECLARE(JNI_GetCreatedJavaVMs) = NULL;
-
-static HANDLE _st_sys_jvmDllHandle = NULL;
-
-#define JVM_DELETE_CLAZZ(jvm, cl) \
- APXMACRO_BEGIN \
- if ((jvm)->lpEnv && (jvm)->##cl.jClazz) { \
- (*((jvm)->lpEnv))->DeleteGlobalRef((jvm)->lpEnv, (jvm)->##cl.jClazz); \
- (jvm)->##cl.jClazz = NULL; \
- } APXMACRO_END
-
-#define JVM_EXCEPTION_CHECK(jvm) \
- ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv) != JNI_OK)
-
-#ifdef _DEBUG
-#define JVM_EXCEPTION_CLEAR(jvm) \
- APXMACRO_BEGIN \
- if ((jvm)->lpEnv) { \
- if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) { \
- (*((jvm)->lpEnv))->ExceptionDescribe((jvm)->lpEnv); \
- (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv); \
- } \
- } APXMACRO_END
-#else
-#define JVM_EXCEPTION_CLEAR(jvm) \
- APXMACRO_BEGIN \
- if ((jvm)->lpEnv) { \
- if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) { \
- (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv); \
- } \
- } APXMACRO_END
-#endif
-
-#define JNI_LOCAL_UNREF(obj) \
- (*(lpJava->lpEnv))->DeleteLocalRef(lpJava->lpEnv, obj)
-
-#define JNICALL_0(fName) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv))
-
-#define JNICALL_1(fName, a1) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1)))
-
-#define JNICALL_2(fName, a1, a2) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2)))
-
-#define JNICALL_3(fName, a1, a2, a3) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3)))
-
-#define JNICALL_4(fName, a1, a2, a3, a4) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3), (a4)))
-
-typedef struct APXJAVASTDCLAZZ {
- jclass jClazz;
- jmethodID jMethod;
- jobject jObject;
- jarray jArgs;
-} APXJAVASTDCLAZZ, *LPAPXJAVASTDCLAZZ;
-
-typedef struct APXJAVAVM {
- DWORD dwOptions;
- APXJAVASTDCLAZZ clString;
- APXJAVASTDCLAZZ clWorker;
- jint iVersion;
- jsize iVmCount;
- JNIEnv *lpEnv;
- JavaVM *lpJvm;
- /* JVM worker thread info */
- HANDLE hWorkerThread;
- DWORD iWorkerThread;
- DWORD dwWorkerStatus;
-
-} APXJAVAVM, *LPAPXJAVAVM;
-
-#define JAVA_CLASSPATH "-Djava.class.path="
-#define JAVA_CLASSSTRING "java/lang/String"
-
-static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
-{
- jint _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
- (void **)&(lpJava->lpEnv),
- lpJava->iVersion);
- if (_iStatus != JNI_OK) {
- if (_iStatus == JNI_EDETACHED)
- _iStatus = (*(lpJava->lpJvm))->AttachCurrentThread(lpJava->lpJvm,
- (void **)&(lpJava->lpEnv), NULL);
- }
- if (_iStatus != JNI_OK) {
- lpJava->lpEnv = NULL;
- return FALSE;
- }
- else
- return TRUE;
-}
-
-static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
-{
- jint _iStatus = (*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm);
- if (_iStatus != JNI_OK) {
- lpJava->lpEnv = NULL;
- return FALSE;
- }
- else
- return TRUE;
-}
-
-static BOOL __apxLoadJvmDll(LPCWSTR szJvmDllPath)
-{
- UINT errMode;
- LPWSTR dllJvmPath = (LPWSTR)szJvmDllPath;
-
- if (!IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
- return TRUE; /* jvm.dll is already loaded */
-
- if (!dllJvmPath || *dllJvmPath == L'\0')
- dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
- if (!dllJvmPath)
- return FALSE;
- /* Suppress the not found system popup message */
- errMode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
- /* This shuldn't happen, but try to search in %PATH% */
- if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
- _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
- LOAD_WITH_ALTERED_SEARCH_PATH);
- /* Restore the error mode signalization */
- SetErrorMode(errMode);
- if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return FALSE;
- }
- DYNLOAD_FPTR_LOAD(JNI_GetDefaultJavaVMInitArgs, _st_sys_jvmDllHandle);
- DYNLOAD_FPTR_LOAD(JNI_CreateJavaVM, _st_sys_jvmDllHandle);
- DYNLOAD_FPTR_LOAD(JNI_GetCreatedJavaVMs, _st_sys_jvmDllHandle);
-
- if (!DYNLOAD_FPTR(JNI_GetDefaultJavaVMInitArgs) ||
- !DYNLOAD_FPTR(JNI_CreateJavaVM) ||
- !DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- FreeLibrary(_st_sys_jvmDllHandle);
- _st_sys_jvmDllHandle = NULL;
- return FALSE;
- }
-
- /* Real voodo ... */
- return TRUE;
-}
-
-static BOOL __apxJavaJniCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- LPAPXJAVAVM lpJava;
- DWORD dwJvmRet = 0;
-
- lpJava = APXHANDLE_DATA(hObject);
- switch (uMsg) {
- case WM_CLOSE:
- if (lpJava->lpJvm) {
- if (!IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
- if (GetExitCodeThread(lpJava->hWorkerThread, &dwJvmRet) &&
- dwJvmRet == STILL_ACTIVE) {
- TerminateThread(lpJava->hWorkerThread, 5);
- }
- }
- SAFE_CLOSE_HANDLE(lpJava->hWorkerThread);
- __apxJvmAttach(lpJava);
- JVM_DELETE_CLAZZ(lpJava, clWorker);
- JVM_DELETE_CLAZZ(lpJava, clString);
- __apxJvmDetach(lpJava);
- /* Check if this is the jvm loader */
- if (!lpJava->iVmCount && _st_sys_jvmDllHandle) {
-#if 0
- /* Do not destroy if we terminated the worker thread */
- if (dwJvmRet != STILL_ACTIVE)
- (*(lpJava->lpJvm))->DestroyJavaVM(lpJava->lpJvm);
-#endif
- /* Unload JVM dll */
- FreeLibrary(_st_sys_jvmDllHandle);
- _st_sys_jvmDllHandle = NULL;
- }
- lpJava->lpJvm = NULL;
- }
- break;
- default:
- break;
- }
- return TRUE;
-}
-
-APXHANDLE
-apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath)
-{
-
- APXHANDLE hJava;
- LPAPXJAVAVM lpJava;
- jsize iVmCount;
- JavaVM *lpJvm = NULL;
-
- if (!__apxLoadJvmDll(szJvmDllPath))
- return NULL;
- /*
- */
- if (DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)(&lpJvm, 1, &iVmCount) != JNI_OK) {
- return NULL;
- }
- if (iVmCount && !lpJvm)
- return NULL;
-
- hJava = apxHandleCreate(hPool, 0,
- NULL, sizeof(APXJAVAVM),
- __apxJavaJniCallback);
- if (IS_INVALID_HANDLE(hJava))
- return NULL;
- hJava->dwType = APXHANDLE_TYPE_JVM;
- lpJava = APXHANDLE_DATA(hJava);
- lpJava->lpJvm = lpJvm;
- lpJava->iVmCount = iVmCount;
- return hJava;
-}
-
-static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
- LPCSTR lpString,
- JavaVMOption **lppArray,
- DWORD nExtra)
-{
- DWORD i, n = 0, l = 0;
- char *buff;
- LPSTR p;
-
- if (lpString) {
- l = __apxGetMultiSzLengthA(lpString, &n);
- }
- n += nExtra;
- if (IS_INVALID_HANDLE(hPool))
- buff = apxPoolAlloc(hPool, (n + 1) * sizeof(JavaVMOption) + (l + 1));
- else
- buff = apxAlloc((n + 1) * sizeof(JavaVMOption) + (l + 1));
-
- *lppArray = (JavaVMOption *)buff;
- p = (LPSTR)(buff + (n + 1) * sizeof(JavaVMOption));
- if (lpString)
- AplCopyMemory(p, lpString, l + 1);
- for (i = 0; i < (n - nExtra); i++) {
- DWORD qr = apxStrUnQuoteInplaceA(p);
- (*lppArray)[i].optionString = p;
- while (*p)
- p++;
- p++;
- p += qr;
- }
-
- return n;
-}
-
-/* a hook for a function that redirects all VM messages. */
-static jint JNICALL __apxJniVfprintf(FILE *fp, const char *format, va_list args)
-{
- jint rv;
- CHAR sBuf[1024+16];
- rv = wvsprintfA(sBuf, format, args);
- if (apxLogWrite(APXLOG_MARK_INFO "%s", sBuf) == 0)
- fputs(sBuf, stdout);
- return rv;
-}
-
-
-/* ANSI version only */
-BOOL
-apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
- LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
- DWORD dwSs)
-{
- LPAPXJAVAVM lpJava;
- JavaVMInitArgs vmArgs;
- JavaVMOption *lpJvmOptions;
- DWORD i, nOptions, sOptions = 2;
- BOOL rv = FALSE;
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return FALSE;
-
- lpJava = APXHANDLE_DATA(hJava);
-
- if (lpJava->iVmCount) {
- if (!lpJava->lpEnv && !__apxJvmAttach(lpJava)) {
- if (lpJava->iVersion == JNI_VERSION_1_2) {
- apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
- return FALSE;
- }
- else
- lpJava->iVersion = JNI_VERSION_1_2;
- if (!__apxJvmAttach(lpJava)) {
- apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
- return FALSE;
- }
- }
- lpJava->iVersion = JNICALL_0(GetVersion);
- if (lpJava->iVersion < JNI_VERSION_1_2) {
- apxLogWrite(APXLOG_MARK_ERROR "Unsupported JNI version %#08x", lpJava->iVersion);
- return FALSE;
- }
- rv = TRUE;
- }
- else {
- CHAR iB[3][64];
- LPSTR szCp;
- lpJava->iVersion = JNI_VERSION_DEFAULT;
- if (dwMs)
- ++sOptions;
- if (dwMx)
- ++sOptions;
- if (dwSs)
- ++sOptions;
- nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
- &lpJvmOptions, sOptions);
- szCp = apxPoolAlloc(hJava->hPool, sizeof(JAVA_CLASSPATH) + lstrlenA(szClassPath));
- lstrcpyA(szCp, JAVA_CLASSPATH);
- lstrcatA(szCp, szClassPath);
- lpJvmOptions[nOptions - sOptions].optionString = szCp;
- --sOptions;
- /* default JNI error printer */
- lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
- lpJvmOptions[nOptions - sOptions].extraInfo = __apxJniVfprintf;
- --sOptions;
- if (dwMs) {
- wsprintfA(iB[0], "-Xms%dm", dwMs);
- lpJvmOptions[nOptions - sOptions].optionString = iB[0];
- --sOptions;
- }
- if (dwMx) {
- wsprintfA(iB[1], "-Xmx%dm", dwMx);
- lpJvmOptions[nOptions - sOptions].optionString = iB[1];
- --sOptions;
- }
- if (dwSs) {
- wsprintfA(iB[2], "-Xss%dk", dwSs);
- lpJvmOptions[nOptions - sOptions].optionString = iB[2];
- --sOptions;
- }
- for (i = 0; i < nOptions; i++) {
- apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", i,
- lpJvmOptions[i].optionString);
- }
- vmArgs.options = lpJvmOptions;
- vmArgs.nOptions = nOptions;
- vmArgs.version = lpJava->iVersion;
- vmArgs.ignoreUnrecognized = JNI_FALSE;
- if (DYNLOAD_FPTR(JNI_CreateJavaVM)(&(lpJava->lpJvm),
- (void **)&(lpJava->lpEnv),
- &vmArgs) != JNI_OK) {
- apxLogWrite(APXLOG_MARK_ERROR "CreateJavaVM Failed");
- rv = FALSE;
- }
- else
- rv = TRUE;
- apxFree(szCp);
- apxFree(lpJvmOptions);
- }
- /* Load standard classes */
- if (rv) {
- jclass jClazz = JNICALL_1(FindClass, JAVA_CLASSSTRING);
- if (!jClazz) {
- apxLogWrite(APXLOG_MARK_ERROR "FindClass " JAVA_CLASSSTRING " failed");
- goto cleanup;
- }
- lpJava->clString.jClazz = JNICALL_1(NewGlobalRef, jClazz);
- JNI_LOCAL_UNREF(jClazz);
-
- return TRUE;
- }
- else
- return FALSE;
-
-cleanup:
- JVM_EXCEPTION_CLEAR(lpJava);
- return FALSE;
-}
-
-BOOL
-apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName,
- LPCSTR szMethodName,
- LPCVOID lpArguments)
-{
- LPWSTR *lpArgs = NULL;
- DWORD nArgs;
- LPAPXJAVAVM lpJava;
- jclass jClazz;
-
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return FALSE;
- lpJava = APXHANDLE_DATA(hJava);
- if (!__apxJvmAttach(lpJava))
- return FALSE;
-
- /* Find the class */
- jClazz = JNICALL_1(FindClass, szClassName);
- if (!jClazz) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "FindClass %s failed", szClassName);
- return FALSE;
- }
- /* Make the class global so that worker thread can attach */
- lpJava->clWorker.jClazz = JNICALL_1(NewGlobalRef, jClazz);
- JNI_LOCAL_UNREF(jClazz);
-
- if (szMethodName)
- lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
- lpJava->clWorker.jClazz,
- szMethodName, "([Ljava/lang/String;)V");
- else
- lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
- lpJava->clWorker.jClazz,
- "main", "([Ljava/lang/String;)V");
- if (!lpJava->clWorker.jMethod) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Static method 'void main(String[])' in Class %s not found", szClassName);
- return FALSE;
- }
- nArgs = apxMultiSzToArrayW(hJava->hPool, lpArguments, &lpArgs);
- if (nArgs) {
- DWORD i;
- lpJava->clWorker.jArgs = JNICALL_3(NewObjectArray, nArgs,
- lpJava->clString.jClazz, NULL);
- for (i = 0; i < nArgs; i++) {
- jstring arg = JNICALL_2(NewString, lpArgs[i], lstrlenW(lpArgs[i]));
- JNICALL_3(SetObjectArrayElement, lpJava->clWorker.jArgs, i, arg);
- apxLogWrite(APXLOG_MARK_DEBUG "argv[%d] = %S", i, lpArgs[i]);
- }
- }
- apxFree(lpArgs);
- return TRUE;
-}
-
-
-/* Main java application worker thread
- * It will launch Java main and wait until
- * it finishes.
- */
-static DWORD WINAPI __apxJavaWorkerThread(LPVOID lpParameter)
-{
-#define WORKER_EXIT(x) { rv = x; goto finished; }
- DWORD rv = 0;
- LPAPXJAVAVM lpJava;
- APXHANDLE hJava = (APXHANDLE)lpParameter;
- /* This shouldn't happen */
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- WORKER_EXIT(0);
- lpJava = APXHANDLE_DATA(hJava);
- /* Check if we have a class and a method */
- if (!lpJava->clWorker.jClazz || !lpJava->clWorker.jMethod)
- WORKER_EXIT(2);
- if (!__apxJvmAttach(lpJava))
- WORKER_EXIT(3);
- lpJava->dwWorkerStatus = 1;
- JNICALL_3(CallStaticVoidMethod,
- lpJava->clWorker.jClazz,
- lpJava->clWorker.jMethod,
- lpJava->clWorker.jArgs);
-
- JVM_EXCEPTION_CLEAR(lpJava);
- __apxJvmDetach(lpJava);
-finished:
- lpJava->dwWorkerStatus = 0;
- apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished");
- ExitThread(rv);
- /* never gets here but keep the compiler happy */
- return 0;
-}
-
-
-BOOL
-apxJavaStart(APXHANDLE hJava)
-{
-
- LPAPXJAVAVM lpJava;
-
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return FALSE;
- lpJava = APXHANDLE_DATA(hJava);
-
- lpJava->hWorkerThread = CreateThread(NULL, 0, __apxJavaWorkerThread,
- hJava, CREATE_SUSPENDED,
- &lpJava->iWorkerThread);
- if (IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return FALSE;
- }
- ResumeThread(lpJava->hWorkerThread);
- /* Give some time to initialize the thread */
- Sleep(1000);
- return TRUE;
-}
-
-DWORD
-apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill)
-{
- DWORD rv;
- LPAPXJAVAVM lpJava;
-
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return FALSE;
- lpJava = APXHANDLE_DATA(hJava);
-
- if (!lpJava->dwWorkerStatus && lpJava->hWorkerThread)
- return WAIT_OBJECT_0;
- rv = WaitForSingleObject(lpJava->hWorkerThread, dwMilliseconds);
- if (rv == WAIT_TIMEOUT && bKill) {
- __apxJavaJniCallback(hJava, WM_CLOSE, 0, 0);
- }
-
- return rv;
-}
-
-LPVOID
-apxJavaCreateClassV(APXHANDLE hJava, LPCSTR szClassName,
- LPCSTR szSignature, va_list lpArgs)
-{
- LPAPXJAVAVM lpJava;
- jclass clazz;
- jmethodID ccont;
- jobject cinst;
-
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return NULL;
- lpJava = APXHANDLE_DATA(hJava);
- if (!__apxJvmAttach(lpJava))
- return NULL;
-
- clazz = JNICALL_1(FindClass, szClassName);
- if (clazz == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass %s", szClassName);
- return NULL;
- }
-
- ccont = JNICALL_3(GetMethodID, clazz, "<init>", szSignature);
- if (ccont == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Could not find Constructor %s for %s",
- szSignature, szClassName);
- return NULL;
- }
-
- cinst = JNICALL_3(NewObjectV, clazz, ccont, lpArgs);
- if (cinst == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Could not create instance of %s",
- szClassName);
- return NULL;
- }
-
- return cinst;
-}
-
-LPVOID
-apxJavaCreateClass(APXHANDLE hJava, LPCSTR szClassName,
- LPCSTR szSignature, ...)
-{
- LPVOID rv;
- va_list args;
-
- va_start(args, szSignature);
- rv = apxJavaCreateClassV(hJava, szClassName, szSignature, args);
- va_end(args);
-
- return rv;
-}
-
-LPVOID
-apxJavaCreateStringA(APXHANDLE hJava, LPCSTR szString)
-{
- LPAPXJAVAVM lpJava;
- jstring str;
-
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return NULL;
- lpJava = APXHANDLE_DATA(hJava);
-
- str = JNICALL_1(NewStringUTF, szString);
- if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %s",
- szString);
- return NULL;
- }
-
- return str;
-}
-
-LPVOID
-apxJavaCreateStringW(APXHANDLE hJava, LPCWSTR szString)
-{
- LPAPXJAVAVM lpJava;
- jstring str;
-
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return NULL;
- lpJava = APXHANDLE_DATA(hJava);
-
- str = JNICALL_2(NewString, szString, lstrlenW(szString));
- if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %S",
- szString);
- return NULL;
- }
-
- return str;
-}
-
-jvalue
-apxJavaCallStaticMethodV(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
- LPCSTR szSignature, va_list lpArgs)
-{
- LPAPXJAVAVM lpJava;
- jmethodID method;
- jvalue rv;
- LPCSTR s = szSignature;
- rv.l = 0;
- if (hJava->dwType != APXHANDLE_TYPE_JVM)
- return rv;
- lpJava = APXHANDLE_DATA(hJava);
-
- while (*s && *s != ')')
- ++s;
- if (*s != ')') {
- return rv;
- }
- else
- ++s;
- method = JNICALL_3(GetStaticMethodID, lpClass, szMethodName, szSignature);
- if (method == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Could not find method %s with signature %s",
- szMethodName, szSignature);
- return rv;
- }
- switch (*s) {
- case 'V':
- JNICALL_3(CallStaticVoidMethodV, lpClass, method, lpArgs);
- break;
- case 'L':
- case '[':
- rv.l = JNICALL_3(CallStaticObjectMethodV, lpClass, method, lpArgs);
- break;
- case 'Z':
- rv.z = JNICALL_3(CallStaticBooleanMethodV, lpClass, method, lpArgs);
- break;
- case 'B':
- rv.b = JNICALL_3(CallStaticByteMethodV, lpClass, method, lpArgs);
- break;
- case 'C':
- rv.c = JNICALL_3(CallStaticCharMethodV, lpClass, method, lpArgs);
- break;
- case 'S':
- rv.i = JNICALL_3(CallStaticShortMethodV, lpClass, method, lpArgs);
- break;
- case 'I':
- rv.i = JNICALL_3(CallStaticIntMethodV, lpClass, method, lpArgs);
- break;
- case 'J':
- rv.j = JNICALL_3(CallStaticLongMethodV, lpClass, method, lpArgs);
- break;
- case 'F':
- rv.f = JNICALL_3(CallStaticFloatMethodV, lpClass, method, lpArgs);
- break;
- case 'D':
- rv.d = JNICALL_3(CallStaticDoubleMethodV, lpClass, method, lpArgs);
- break;
- default:
- apxLogWrite(APXLOG_MARK_ERROR "Invalid signature %s for method %s",
- szSignature, szMethodName);
- return rv;
- break;
- }
-
- return rv;
-}
-
-jvalue
-apxJavaCallStaticMethod(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
- LPCSTR szSignature, ...)
-{
- jvalue rv;
- va_list args;
-
- va_start(args, szSignature);
- rv = apxJavaCallStaticMethodV(hJava, lpClass, szMethodName, szSignature, args);
- va_end(args);
-
- return rv;
-}
-
-/* Call the Java:
- * System.setOut(new PrintStream(new FileOutputStream(filename)));
- */
-BOOL
-apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut, LPCWSTR szFilename)
-{
- LPAPXJAVAVM lpJava;
- jobject fs;
- jobject ps;
- jstring fn;
- jclass sys;
-
- if (hJava->dwType != APXHANDLE_TYPE_JVM || !szFilename)
- return FALSE;
- lpJava = APXHANDLE_DATA(hJava);
- if (!__apxJvmAttach(lpJava))
- return FALSE;
-
- if ((fn = apxJavaCreateStringW(hJava, szFilename)) == NULL)
- return FALSE;
- if ((fs = apxJavaCreateClass(hJava, "java/io/FileOutputStream",
- "(Ljava/lang/String;Z)V", fn, JNI_TRUE)) == NULL)
- return FALSE;
- if ((ps = apxJavaCreateClass(hJava, "java/io/PrintStream",
- "(Ljava/io/OutputStream;)V", fs)) == NULL)
- return FALSE;
- sys = JNICALL_1(FindClass, "java/lang/System");
- if (sys == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass java/lang/System");
- return FALSE;
- }
-
- if (setErrorOrOut)
- apxJavaCallStaticMethod(hJava, sys, "setErr", "(Ljava/io/PrintStream;)V", ps);
- else
- apxJavaCallStaticMethod(hJava, sys, "setOut", "(Ljava/io/PrintStream;)V", ps);
-
- if (JVM_EXCEPTION_CHECK(lpJava)) {
- JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Error calling set method for java/lang/System");
- return FALSE;
- }
- else
- return TRUE;
-
-}
Copied: tags/jbosssvc/2.0.8/procrun/src/javajni.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/javajni.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/javajni.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/javajni.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,970 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#include <jni.h>
+
+#ifndef JNI_VERSION_1_2
+#error -------------------------------------------------------
+#error JAVA 1.1 IS NO LONGER SUPPORTED
+#error -------------------------------------------------------
+#endif
+
+#ifdef JNI_VERSION_1_4
+#define JNI_VERSION_DEFAULT JNI_VERSION_1_4
+#else
+#define JNI_VERSION_DEFAULT JNI_VERSION_1_2
+#endif
+
+/* Standard jvm.dll prototypes
+ * since only single jvm can exist per process
+ * make those global
+ */
+
+DYNOLAD_TYPE_DECLARE(JNI_GetDefaultJavaVMInitArgs, JNICALL, jint)(void *);
+static DYNLOAD_FPTR_DECLARE(JNI_GetDefaultJavaVMInitArgs) = NULL;
+
+DYNOLAD_TYPE_DECLARE(JNI_CreateJavaVM, JNICALL, jint)(JavaVM **, void **, void *);
+static DYNLOAD_FPTR_DECLARE(JNI_CreateJavaVM) = NULL;
+
+DYNOLAD_TYPE_DECLARE(JNI_GetCreatedJavaVMs, JNICALL, jint)(JavaVM **, jsize, jsize *);
+static DYNLOAD_FPTR_DECLARE(JNI_GetCreatedJavaVMs) = NULL;
+
+static HANDLE _st_sys_jvmDllHandle = NULL;
+static JavaVM *_st_sys_jvm = NULL;
+
+DYNOLAD_TYPE_DECLARE(SetDllDirectoryW, WINAPI, BOOL)(LPCWSTR);
+static DYNLOAD_FPTR_DECLARE(SetDllDirectoryW) = NULL;
+
+#define JVM_DELETE_CLAZZ(jvm, cl) \
+ APXMACRO_BEGIN \
+ if ((jvm)->lpEnv && (jvm)->cl.jClazz) { \
+ (*((jvm)->lpEnv))->DeleteGlobalRef((jvm)->lpEnv, (jvm)->cl.jClazz); \
+ (jvm)->cl.jClazz = NULL; \
+ } APXMACRO_END
+
+#define JVM_EXCEPTION_CHECK(jvm) \
+ ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv) != JNI_OK)
+
+#ifdef _DEBUG
+#define JVM_EXCEPTION_CLEAR(jvm) \
+ APXMACRO_BEGIN \
+ if ((jvm)->lpEnv) { \
+ if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) { \
+ (*((jvm)->lpEnv))->ExceptionDescribe((jvm)->lpEnv); \
+ (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv); \
+ } \
+ } APXMACRO_END
+#else
+#define JVM_EXCEPTION_CLEAR(jvm) \
+ APXMACRO_BEGIN \
+ if ((jvm)->lpEnv) { \
+ if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) { \
+ (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv); \
+ } \
+ } APXMACRO_END
+#endif
+
+#define JNI_LOCAL_UNREF(obj) \
+ (*(lpJava->lpEnv))->DeleteLocalRef(lpJava->lpEnv, obj)
+
+#define JNICALL_0(fName) \
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv))
+
+#define JNICALL_1(fName, a1) \
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1)))
+
+#define JNICALL_2(fName, a1, a2) \
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1), (a2)))
+
+#define JNICALL_3(fName, a1, a2, a3) \
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1), (a2), (a3)))
+
+#define JNICALL_4(fName, a1, a2, a3, a4) \
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1), (a2), (a3), (a4)))
+
+typedef struct APXJAVASTDCLAZZ {
+ CHAR sClazz[1024];
+ CHAR sMethod[512];
+ jclass jClazz;
+ jmethodID jMethod;
+ jobject jObject;
+ jarray jArgs;
+} APXJAVASTDCLAZZ, *LPAPXJAVASTDCLAZZ;
+
+typedef struct APXJAVAVM {
+ DWORD dwOptions;
+ APXJAVASTDCLAZZ clString;
+ APXJAVASTDCLAZZ clWorker;
+ jint iVersion;
+ jsize iVmCount;
+ JNIEnv *lpEnv;
+ JavaVM *lpJvm;
+ /* JVM worker thread info */
+ HANDLE hWorkerThread;
+ DWORD iWorkerThread;
+ DWORD dwWorkerStatus;
+
+} APXJAVAVM, *LPAPXJAVAVM;
+
+#define JAVA_CLASSPATH "-Djava.class.path="
+#define JAVA_CLASSPATH_W L"-Djava.class.path="
+#define JAVA_CLASSSTRING "java/lang/String"
+
+static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
+{
+ jint _iStatus;
+
+ if (!_st_sys_jvm)
+ return FALSE;
+ _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
+ (void **)&(lpJava->lpEnv),
+ lpJava->iVersion);
+ if (_iStatus != JNI_OK) {
+ if (_iStatus == JNI_EDETACHED)
+ _iStatus = (*(lpJava->lpJvm))->AttachCurrentThread(lpJava->lpJvm,
+ (void **)&(lpJava->lpEnv), NULL);
+ }
+ if (_iStatus != JNI_OK) {
+ lpJava->lpEnv = NULL;
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
+{
+ if (!_st_sys_jvm)
+ return FALSE;
+ if ((*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm) != JNI_OK) {
+ lpJava->lpEnv = NULL;
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+static BOOL __apxLoadJvmDll(LPCWSTR szJvmDllPath)
+{
+ UINT errMode;
+ LPWSTR dllJvmPath = (LPWSTR)szJvmDllPath;
+ DYNLOAD_FPTR_DECLARE(SetDllDirectoryW);
+
+ if (!IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+ return TRUE; /* jvm.dll is already loaded */
+
+ if (!dllJvmPath || *dllJvmPath == L'\0')
+ dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
+ if (!dllJvmPath)
+ return FALSE;
+ /* Suppress the not found system popup message */
+ errMode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
+ /* This shuldn't happen, but try to search in %PATH% */
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
+ LOAD_WITH_ALTERED_SEARCH_PATH);
+
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+ WCHAR jreBinPath[SIZ_PATHLEN];
+ DWORD i, l = 0;
+
+ lstrlcpyW(jreBinPath, SIZ_PATHLEN, dllJvmPath);
+ DYNLOAD_FPTR_ADDRESS(SetDllDirectoryW, KERNEL32);
+ for (i = lstrlenW(jreBinPath); i > 0, l < 2; i--) {
+ if (jreBinPath[i] == L'\\' || jreBinPath[i] == L'/') {
+ jreBinPath[i] = L'\0';
+ DYNLOAD_CALL(SetDllDirectoryW)(jreBinPath);
+ l++;
+ }
+ }
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
+ LOAD_WITH_ALTERED_SEARCH_PATH);
+ }
+ /* Restore the error mode signalization */
+ SetErrorMode(errMode);
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ DYNLOAD_FPTR_LOAD(JNI_GetDefaultJavaVMInitArgs, _st_sys_jvmDllHandle);
+ DYNLOAD_FPTR_LOAD(JNI_CreateJavaVM, _st_sys_jvmDllHandle);
+ DYNLOAD_FPTR_LOAD(JNI_GetCreatedJavaVMs, _st_sys_jvmDllHandle);
+
+ if (!DYNLOAD_FPTR(JNI_GetDefaultJavaVMInitArgs) ||
+ !DYNLOAD_FPTR(JNI_CreateJavaVM) ||
+ !DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ FreeLibrary(_st_sys_jvmDllHandle);
+ _st_sys_jvmDllHandle = NULL;
+ return FALSE;
+ }
+
+ /* Real voodo ... */
+ return TRUE;
+}
+
+static BOOL __apxJavaJniCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXJAVAVM lpJava;
+ DWORD dwJvmRet = 0;
+
+ lpJava = APXHANDLE_DATA(hObject);
+ switch (uMsg) {
+ case WM_CLOSE:
+ if (_st_sys_jvm && lpJava->lpJvm) {
+ if (!IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
+ if (GetExitCodeThread(lpJava->hWorkerThread, &dwJvmRet) &&
+ dwJvmRet == STILL_ACTIVE) {
+ TerminateThread(lpJava->hWorkerThread, 5);
+ }
+ }
+ SAFE_CLOSE_HANDLE(lpJava->hWorkerThread);
+ __apxJvmAttach(lpJava);
+ JVM_DELETE_CLAZZ(lpJava, clWorker);
+ JVM_DELETE_CLAZZ(lpJava, clString);
+ __apxJvmDetach(lpJava);
+ /* Check if this is the jvm loader */
+ if (!lpJava->iVmCount && _st_sys_jvmDllHandle) {
+ /* Unload JVM dll */
+ FreeLibrary(_st_sys_jvmDllHandle);
+ _st_sys_jvmDllHandle = NULL;
+ }
+ lpJava->lpJvm = NULL;
+ }
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+APXHANDLE
+apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath)
+{
+
+ APXHANDLE hJava;
+ LPAPXJAVAVM lpJava;
+ jsize iVmCount;
+ JavaVM *lpJvm = NULL;
+
+ if (!__apxLoadJvmDll(szJvmDllPath))
+ return NULL;
+ /*
+ */
+ if (DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)(&lpJvm, 1, &iVmCount) != JNI_OK) {
+ return NULL;
+ }
+ if (iVmCount && !lpJvm)
+ return NULL;
+
+ hJava = apxHandleCreate(hPool, 0,
+ NULL, sizeof(APXJAVAVM),
+ __apxJavaJniCallback);
+ if (IS_INVALID_HANDLE(hJava))
+ return NULL;
+ hJava->dwType = APXHANDLE_TYPE_JVM;
+ lpJava = APXHANDLE_DATA(hJava);
+ lpJava->lpJvm = lpJvm;
+ lpJava->iVmCount = iVmCount;
+ if (!_st_sys_jvm)
+ _st_sys_jvm = lpJvm;
+ return hJava;
+}
+
+static DWORD WINAPI __apxJavaDestroyThread(LPVOID lpParameter)
+{
+ JavaVM *lpJvm = (JavaVM *)lpParameter;
+ (*lpJvm)->DestroyJavaVM(lpJvm);
+ return 0;
+}
+
+BOOL
+apxDestroyJvm(DWORD dwTimeout)
+{
+ if (_st_sys_jvm) {
+ DWORD tid;
+ HANDLE hWaiter;
+ BOOL rv = FALSE;
+ JavaVM *lpJvm = _st_sys_jvm;
+
+ _st_sys_jvm = NULL;
+ (*lpJvm)->DetachCurrentThread(lpJvm);
+ hWaiter = CreateThread(NULL, 0, __apxJavaDestroyThread,
+ (void *)lpJvm, 0, &tid);
+ if (IS_INVALID_HANDLE(hWaiter)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ if (WaitForSingleObject(hWaiter, dwTimeout) == WAIT_OBJECT_0)
+ rv = TRUE;
+ CloseHandle(hWaiter);
+ return rv;
+ }
+ else
+ return FALSE;
+}
+
+static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
+ LPCSTR lpString,
+ JavaVMOption **lppArray,
+ DWORD nExtra)
+{
+ DWORD i, n = 0, l = 0;
+ char *buff;
+ LPSTR p;
+
+ if (lpString) {
+ l = __apxGetMultiSzLengthA(lpString, &n);
+ }
+ n += nExtra;
+ if (IS_INVALID_HANDLE(hPool))
+ buff = apxPoolAlloc(hPool, (n + 1) * sizeof(JavaVMOption) + (l + 1));
+ else
+ buff = apxAlloc((n + 1) * sizeof(JavaVMOption) + (l + 1));
+
+ *lppArray = (JavaVMOption *)buff;
+ p = (LPSTR)(buff + (n + 1) * sizeof(JavaVMOption));
+ if (lpString)
+ AplCopyMemory(p, lpString, l + 1);
+ for (i = 0; i < (n - nExtra); i++) {
+ DWORD qr = apxStrUnQuoteInplaceA(p);
+ (*lppArray)[i].optionString = p;
+ while (*p)
+ p++;
+ p++;
+ p += qr;
+ }
+
+ return n;
+}
+
+/* a hook for a function that redirects all VM messages. */
+static jint JNICALL __apxJniVfprintf(FILE *fp, const char *format, va_list args)
+{
+ jint rv;
+ CHAR sBuf[1024+16];
+ rv = wvsprintfA(sBuf, format, args);
+ if (apxLogWrite(APXLOG_MARK_INFO "%s", sBuf) == 0)
+ fputs(sBuf, stdout);
+ return rv;
+}
+
+
+/* ANSI version only */
+BOOL
+apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
+ LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
+ DWORD dwSs, DWORD bJniVfprintf)
+{
+ LPAPXJAVAVM lpJava;
+ JavaVMInitArgs vmArgs;
+ JavaVMOption *lpJvmOptions;
+ DWORD i, nOptions, sOptions = 0;
+ BOOL rv = FALSE;
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+
+ lpJava = APXHANDLE_DATA(hJava);
+
+ if (lpJava->iVmCount) {
+ if (!lpJava->lpEnv && !__apxJvmAttach(lpJava)) {
+ if (lpJava->iVersion == JNI_VERSION_1_2) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
+ return FALSE;
+ }
+ else
+ lpJava->iVersion = JNI_VERSION_1_2;
+ if (!__apxJvmAttach(lpJava)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
+ return FALSE;
+ }
+ }
+ lpJava->iVersion = JNICALL_0(GetVersion);
+ if (lpJava->iVersion < JNI_VERSION_1_2) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unsupported JNI version %#08x", lpJava->iVersion);
+ return FALSE;
+ }
+ rv = TRUE;
+ }
+ else {
+ CHAR iB[3][64];
+ LPSTR szCp;
+ lpJava->iVersion = JNI_VERSION_DEFAULT;
+ if (dwMs)
+ ++sOptions;
+ if (dwMx)
+ ++sOptions;
+ if (dwSs)
+ ++sOptions;
+ if (bJniVfprintf)
+ ++sOptions;
+ if (szClassPath && *szClassPath)
+ ++sOptions;
+ nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
+ &lpJvmOptions, sOptions);
+ if (szClassPath && *szClassPath) {
+ szCp = apxPoolAlloc(hJava->hPool, sizeof(JAVA_CLASSPATH) + lstrlenA(szClassPath));
+ lstrcpyA(szCp, JAVA_CLASSPATH);
+ lstrcatA(szCp, szClassPath);
+ lpJvmOptions[nOptions - sOptions].optionString = szCp;
+ --sOptions;
+ }
+ if (bJniVfprintf) {
+ /* default JNI error printer */
+ lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
+ lpJvmOptions[nOptions - sOptions].extraInfo = __apxJniVfprintf;
+ --sOptions;
+ }
+ if (dwMs) {
+ wsprintfA(iB[0], "-Xms%dm", dwMs);
+ lpJvmOptions[nOptions - sOptions].optionString = iB[0];
+ --sOptions;
+ }
+ if (dwMx) {
+ wsprintfA(iB[1], "-Xmx%dm", dwMx);
+ lpJvmOptions[nOptions - sOptions].optionString = iB[1];
+ --sOptions;
+ }
+ if (dwSs) {
+ wsprintfA(iB[2], "-Xss%dk", dwSs);
+ lpJvmOptions[nOptions - sOptions].optionString = iB[2];
+ --sOptions;
+ }
+ for (i = 0; i < nOptions; i++) {
+ apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", i,
+ lpJvmOptions[i].optionString);
+ }
+ vmArgs.options = lpJvmOptions;
+ vmArgs.nOptions = nOptions;
+ vmArgs.version = lpJava->iVersion;
+ vmArgs.ignoreUnrecognized = JNI_FALSE;
+ if (DYNLOAD_FPTR(JNI_CreateJavaVM)(&(lpJava->lpJvm),
+ (void **)&(lpJava->lpEnv),
+ &vmArgs) != JNI_OK) {
+ apxLogWrite(APXLOG_MARK_ERROR "CreateJavaVM Failed");
+ rv = FALSE;
+ }
+ else {
+ rv = TRUE;
+ if (!_st_sys_jvm)
+ _st_sys_jvm = lpJava->lpJvm;
+ }
+ apxFree(szCp);
+ apxFree(lpJvmOptions);
+ }
+ /* Load standard classes */
+ if (rv) {
+ jclass jClazz = JNICALL_1(FindClass, JAVA_CLASSSTRING);
+ if (!jClazz) {
+ apxLogWrite(APXLOG_MARK_ERROR "FindClass " JAVA_CLASSSTRING " failed");
+ goto cleanup;
+ }
+ lpJava->clString.jClazz = JNICALL_1(NewGlobalRef, jClazz);
+ JNI_LOCAL_UNREF(jClazz);
+
+ return TRUE;
+ }
+ else
+ return FALSE;
+
+cleanup:
+ JVM_EXCEPTION_CLEAR(lpJava);
+ return FALSE;
+}
+
+/* ANSI version only */
+DWORD
+apxJavaCmdInitialize(APXHANDLE hPool, LPCWSTR szClassPath, LPCWSTR szClass,
+ LPCWSTR szOptions, DWORD dwMs, DWORD dwMx,
+ DWORD dwSs, LPCWSTR szCmdArgs, LPWSTR **lppArray)
+{
+
+ DWORD i, nJVM, nCmd, nTotal, lJVM, lCmd;
+ LPWSTR p;
+
+ /* Calculate the number of all arguments */
+ nTotal = 0;
+ if (szClassPath)
+ ++nTotal;
+ if (szClass)
+ ++nTotal;
+ lJVM = __apxGetMultiSzLengthW(szOptions, &nJVM);
+ nTotal += nJVM;
+ lCmd = __apxGetMultiSzLengthW(szCmdArgs, &nCmd);
+ nTotal += nCmd;
+ if (dwMs)
+ ++nTotal;
+ if (dwMx)
+ ++nTotal;
+ if (dwSs)
+ ++nTotal;
+
+ if (nTotal == 0)
+ return 0;
+
+ /* Allocate the array to store all arguments' pointers
+ */
+ *lppArray = (LPWSTR *)apxPoolAlloc(hPool, (nTotal + 2) * sizeof(LPWSTR));
+
+ /* Process JVM options */
+ if (nJVM && lJVM) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lJVM + 1) * sizeof(WCHAR));
+ AplCopyMemory(p, szOptions, (lJVM + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+ for (i = 0; i < nJVM; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ }
+
+ /* Process the 3 extra JVM options */
+ if (dwMs) {
+ p = (LPWSTR)apxPoolAlloc(hPool, 64 * sizeof(WCHAR));
+ wsprintfW(p, L"-Xms%dm", dwMs);
+ (*lppArray)[i++] = p;
+ }
+ if (dwMx) {
+ p = (LPWSTR)apxPoolAlloc(hPool, 64 * sizeof(WCHAR));
+ wsprintfW(p, L"-Xmx%dm", dwMx);
+ (*lppArray)[i++] = p;
+ }
+ if (dwSs) {
+ p = (LPWSTR)apxPoolAlloc(hPool, 64 * sizeof(WCHAR));
+ wsprintfW(p, L"-Xss%dk", dwSs);
+ (*lppArray)[i++] = p;
+ }
+
+ /* Process the classpath and class */
+ if (szClassPath) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lstrlenW(JAVA_CLASSPATH_W) + lstrlenW(szClassPath)) * sizeof(WCHAR));
+ lstrcpyW(p, JAVA_CLASSPATH_W);
+ lstrcatW(p, szClassPath);
+ (*lppArray)[i++] = p;
+ }
+ if (szClass) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lstrlenW(szClass)) * sizeof(WCHAR));
+ lstrcpyW(p, szClass);
+ (*lppArray)[i++] = p;
+ }
+
+ /* Process command arguments */
+ if (nCmd && lCmd) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lCmd + 1) * sizeof(WCHAR));
+ AplCopyMemory(p, szCmdArgs, (lCmd + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+ for (; i < nTotal; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ }
+
+ (*lppArray)[++i] = NULL;
+
+ return nTotal;
+}
+
+
+BOOL
+apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName,
+ LPCSTR szMethodName,
+ LPCVOID lpArguments)
+{
+ LPWSTR *lpArgs = NULL;
+ DWORD nArgs;
+ LPAPXJAVAVM lpJava;
+ jclass jClazz;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+ if (!__apxJvmAttach(lpJava))
+ return FALSE;
+
+ /* Find the class */
+ jClazz = JNICALL_1(FindClass, szClassName);
+ if (!jClazz) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "FindClass %s failed", szClassName);
+ return FALSE;
+ }
+ /* Make the class global so that worker thread can attach */
+ lpJava->clWorker.jClazz = JNICALL_1(NewGlobalRef, jClazz);
+ JNI_LOCAL_UNREF(jClazz);
+
+ if (!szMethodName)
+ szMethodName = "main";
+ lstrlcpyA(lpJava->clWorker.sClazz, 1024, szClassName);
+ lstrlcpyA(lpJava->clWorker.sMethod, 512, szMethodName);
+ lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
+ lpJava->clWorker.jClazz,
+ szMethodName, "([Ljava/lang/String;)V");
+ if (!lpJava->clWorker.jMethod) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Method 'static void %s(String[])' not found in Class %s",
+ szMethodName, szClassName);
+ return FALSE;
+ }
+ nArgs = apxMultiSzToArrayW(hJava->hPool, lpArguments, &lpArgs);
+ lpJava->clWorker.jArgs = JNICALL_3(NewObjectArray, nArgs,
+ lpJava->clString.jClazz, NULL);
+ if (nArgs) {
+ DWORD i;
+ for (i = 0; i < nArgs; i++) {
+ jstring arg = JNICALL_2(NewString, lpArgs[i], lstrlenW(lpArgs[i]));
+ JNICALL_3(SetObjectArrayElement, lpJava->clWorker.jArgs, i, arg);
+ apxLogWrite(APXLOG_MARK_DEBUG "argv[%d] = %S", i, lpArgs[i]);
+ }
+ }
+ apxFree(lpArgs);
+ return TRUE;
+}
+
+/* Main java application worker thread
+ * It will launch Java main and wait until
+ * it finishes.
+ */
+static DWORD WINAPI __apxJavaWorkerThread(LPVOID lpParameter)
+{
+#define WORKER_EXIT(x) { rv = x; goto finished; }
+ DWORD rv = 0;
+ LPAPXJAVAVM lpJava;
+ APXHANDLE hJava = (APXHANDLE)lpParameter;
+ /* This shouldn't happen */
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ WORKER_EXIT(0);
+ lpJava = APXHANDLE_DATA(hJava);
+ /* Check if we have a class and a method */
+ if (!lpJava->clWorker.jClazz || !lpJava->clWorker.jMethod)
+ WORKER_EXIT(2);
+ if (!__apxJvmAttach(lpJava))
+ WORKER_EXIT(3);
+ apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread started %s:%s",
+ lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
+ lpJava->dwWorkerStatus = 1;
+ JNICALL_3(CallStaticVoidMethod,
+ lpJava->clWorker.jClazz,
+ lpJava->clWorker.jMethod,
+ lpJava->clWorker.jArgs);
+
+ JVM_EXCEPTION_CLEAR(lpJava);
+ __apxJvmDetach(lpJava);
+ apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread %s:%s finished",
+ lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
+finished:
+ lpJava->dwWorkerStatus = 0;
+ apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished %s:%s",
+ lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
+ ExitThread(rv);
+ /* never gets here but keep the compiler happy */
+ return 0;
+}
+
+
+BOOL
+apxJavaStart(APXHANDLE hJava)
+{
+
+ LPAPXJAVAVM lpJava;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ lpJava->hWorkerThread = CreateThread(NULL, 0, __apxJavaWorkerThread,
+ hJava, CREATE_SUSPENDED,
+ &lpJava->iWorkerThread);
+ if (IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ ResumeThread(lpJava->hWorkerThread);
+ /* Give some time to initialize the thread */
+ Sleep(1000);
+ return TRUE;
+}
+
+DWORD
+apxJavaSetOptions(APXHANDLE hJava, DWORD dwOptions)
+{
+ DWORD dwOrgOptions;
+ LPAPXJAVAVM lpJava;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return 0;
+ lpJava = APXHANDLE_DATA(hJava);
+ dwOrgOptions = lpJava->dwOptions;
+ lpJava->dwOptions = dwOptions;
+ return dwOrgOptions;
+}
+
+DWORD
+apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill)
+{
+ DWORD rv;
+ LPAPXJAVAVM lpJava;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ if (!lpJava->dwWorkerStatus && lpJava->hWorkerThread)
+ return WAIT_OBJECT_0;
+ rv = WaitForSingleObject(lpJava->hWorkerThread, dwMilliseconds);
+ if (rv == WAIT_TIMEOUT && bKill) {
+ __apxJavaJniCallback(hJava, WM_CLOSE, 0, 0);
+ }
+
+ return rv;
+}
+
+LPVOID
+apxJavaCreateClassV(APXHANDLE hJava, LPCSTR szClassName,
+ LPCSTR szSignature, va_list lpArgs)
+{
+ LPAPXJAVAVM lpJava;
+ jclass clazz;
+ jmethodID ccont;
+ jobject cinst;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return NULL;
+ lpJava = APXHANDLE_DATA(hJava);
+ if (!__apxJvmAttach(lpJava))
+ return NULL;
+
+ clazz = JNICALL_1(FindClass, szClassName);
+ if (clazz == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass %s", szClassName);
+ return NULL;
+ }
+
+ ccont = JNICALL_3(GetMethodID, clazz, "<init>", szSignature);
+ if (ccont == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not find Constructor %s for %s",
+ szSignature, szClassName);
+ return NULL;
+ }
+
+ cinst = JNICALL_3(NewObjectV, clazz, ccont, lpArgs);
+ if (cinst == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not create instance of %s",
+ szClassName);
+ return NULL;
+ }
+
+ return cinst;
+}
+
+LPVOID
+apxJavaCreateClass(APXHANDLE hJava, LPCSTR szClassName,
+ LPCSTR szSignature, ...)
+{
+ LPVOID rv;
+ va_list args;
+
+ va_start(args, szSignature);
+ rv = apxJavaCreateClassV(hJava, szClassName, szSignature, args);
+ va_end(args);
+
+ return rv;
+}
+
+LPVOID
+apxJavaCreateStringA(APXHANDLE hJava, LPCSTR szString)
+{
+ LPAPXJAVAVM lpJava;
+ jstring str;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return NULL;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ str = JNICALL_1(NewStringUTF, szString);
+ if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %s",
+ szString);
+ return NULL;
+ }
+
+ return str;
+}
+
+LPVOID
+apxJavaCreateStringW(APXHANDLE hJava, LPCWSTR szString)
+{
+ LPAPXJAVAVM lpJava;
+ jstring str;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return NULL;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ str = JNICALL_2(NewString, szString, lstrlenW(szString));
+ if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %S",
+ szString);
+ return NULL;
+ }
+
+ return str;
+}
+
+jvalue
+apxJavaCallStaticMethodV(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
+ LPCSTR szSignature, va_list lpArgs)
+{
+ LPAPXJAVAVM lpJava;
+ jmethodID method;
+ jvalue rv;
+ LPCSTR s = szSignature;
+ rv.l = 0;
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return rv;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ while (*s && *s != ')')
+ ++s;
+ if (*s != ')') {
+ return rv;
+ }
+ else
+ ++s;
+ method = JNICALL_3(GetStaticMethodID, lpClass, szMethodName, szSignature);
+ if (method == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not find method %s with signature %s",
+ szMethodName, szSignature);
+ return rv;
+ }
+ switch (*s) {
+ case 'V':
+ JNICALL_3(CallStaticVoidMethodV, lpClass, method, lpArgs);
+ break;
+ case 'L':
+ case '[':
+ rv.l = JNICALL_3(CallStaticObjectMethodV, lpClass, method, lpArgs);
+ break;
+ case 'Z':
+ rv.z = JNICALL_3(CallStaticBooleanMethodV, lpClass, method, lpArgs);
+ break;
+ case 'B':
+ rv.b = JNICALL_3(CallStaticByteMethodV, lpClass, method, lpArgs);
+ break;
+ case 'C':
+ rv.c = JNICALL_3(CallStaticCharMethodV, lpClass, method, lpArgs);
+ break;
+ case 'S':
+ rv.i = JNICALL_3(CallStaticShortMethodV, lpClass, method, lpArgs);
+ break;
+ case 'I':
+ rv.i = JNICALL_3(CallStaticIntMethodV, lpClass, method, lpArgs);
+ break;
+ case 'J':
+ rv.j = JNICALL_3(CallStaticLongMethodV, lpClass, method, lpArgs);
+ break;
+ case 'F':
+ rv.f = JNICALL_3(CallStaticFloatMethodV, lpClass, method, lpArgs);
+ break;
+ case 'D':
+ rv.d = JNICALL_3(CallStaticDoubleMethodV, lpClass, method, lpArgs);
+ break;
+ default:
+ apxLogWrite(APXLOG_MARK_ERROR "Invalid signature %s for method %s",
+ szSignature, szMethodName);
+ return rv;
+ break;
+ }
+
+ return rv;
+}
+
+jvalue
+apxJavaCallStaticMethod(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
+ LPCSTR szSignature, ...)
+{
+ jvalue rv;
+ va_list args;
+
+ va_start(args, szSignature);
+ rv = apxJavaCallStaticMethodV(hJava, lpClass, szMethodName, szSignature, args);
+ va_end(args);
+
+ return rv;
+}
+
+/* Call the Java:
+ * System.setOut(new PrintStream(new FileOutputStream(filename)));
+ */
+BOOL
+apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut, LPCWSTR szFilename)
+{
+ LPAPXJAVAVM lpJava;
+ jobject fs;
+ jobject ps;
+ jstring fn;
+ jclass sys;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM || !szFilename)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+ if (!__apxJvmAttach(lpJava))
+ return FALSE;
+
+ if ((fn = apxJavaCreateStringW(hJava, szFilename)) == NULL)
+ return FALSE;
+ if ((fs = apxJavaCreateClass(hJava, "java/io/FileOutputStream",
+ "(Ljava/lang/String;Z)V", fn, JNI_TRUE)) == NULL)
+ return FALSE;
+ if ((ps = apxJavaCreateClass(hJava, "java/io/PrintStream",
+ "(Ljava/io/OutputStream;)V", fs)) == NULL)
+ return FALSE;
+ sys = JNICALL_1(FindClass, "java/lang/System");
+ if (sys == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass java/lang/System");
+ return FALSE;
+ }
+
+ if (setErrorOrOut)
+ apxJavaCallStaticMethod(hJava, sys, "setErr", "(Ljava/io/PrintStream;)V", ps);
+ else
+ apxJavaCallStaticMethod(hJava, sys, "setOut", "(Ljava/io/PrintStream;)V", ps);
+
+ if (JVM_EXCEPTION_CHECK(lpJava)) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Error calling set method for java/lang/System");
+ return FALSE;
+ }
+ else
+ return TRUE;
+
+}
+
Deleted: tags/jbosssvc/2.0.8/procrun/src/log.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/log.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/log.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,410 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-#define LINE_SEP "\n"
-
-static LPCSTR _log_level[] = {
- "[debug] ",
- "[info] ",
- "[warn] ",
- "[error] ",
- NULL
-};
-
-typedef struct apx_logfile_st {
- HANDLE hFile;
- DWORD dwLogLevel;
- BOOL bRotate;
- SYSTEMTIME sysTime;
- WCHAR szPath[MAX_PATH + 1];
- WCHAR szPrefix[MAX_PATH];
-} apx_logfile_st;
-
-/* Per-application master log file */
-static apx_logfile_st *_st_sys_loghandle = NULL;
-
-static apx_logfile_st _st_sys_errhandle = { NULL, APXLOG_LEVEL_WARN, FALSE};
-
-
-LPWSTR apxLogFile(
- APXHANDLE hPool,
- LPCWSTR szPath,
- LPCWSTR szPrefix,
- LPCWSTR szName)
-{
- LPWSTR sRet;
- WCHAR sPath[MAX_PATH+1];
- WCHAR sName[MAX_PATH+1];
- SYSTEMTIME sysTime;
-
- GetLocalTime(&sysTime);
- if (!szPath) {
- if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
- return INVALID_HANDLE_VALUE;
- lstrcatW(sPath, L"\\LogFiles\\");
- if (!szPrefix)
- lstrcatW(sPath, L"Apache");
- else
- lstrcatW(sPath, szPrefix);
- wsprintfW(sName, L"\\%s%04d%02d%02d.log",
- szName,
- sysTime.wYear,
- sysTime.wMonth,
- sysTime.wDay);
- }
- else {
- lstrcpyW(sPath, szPath);
- if (szPrefix)
- wsprintfW(sName, L"\\%s", szPrefix);
- else
- wsprintfW(sName, L"\\%s%04d%02d%02d.log",
- szName,
- sysTime.wYear,
- sysTime.wMonth,
- sysTime.wDay);
- }
- sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
- /* Set default level to info */
- CreateDirectoryW(sPath, NULL);
-
- lstrcpyW(sRet, sPath);
- lstrcatW(sRet, sName);
-
- return sRet;
-}
-
-/* Open the log file
- * TODO: format like standard apache error.log
- * Add the EventLogger
- */
-HANDLE apxLogOpen(
- APXHANDLE hPool,
- LPCWSTR szPath,
- LPCWSTR szPrefix)
-{
-
- WCHAR sPath[MAX_PATH+1];
- WCHAR sName[MAX_PATH+1];
- SYSTEMTIME sysTime;
- apx_logfile_st *h;
-
- GetLocalTime(&sysTime);
- if (!szPath) {
- if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
- return INVALID_HANDLE_VALUE;
- lstrcatW(sPath, L"\\LogFiles\\");
- if (!szPrefix)
- lstrcatW(sPath, L"Apache");
- else
- lstrcatW(sPath, szPrefix);
- wsprintfW(sName, L"\\%04d%02d%02d.log",
- sysTime.wYear,
- sysTime.wMonth,
- sysTime.wDay);
- }
- else {
- lstrcpyW(sPath, szPath);
- if (szPrefix)
- wsprintfW(sName, L"\\%s", szPrefix);
- else
- wsprintfW(sName, L"\\jakarta_service_%04d%02d%02d.log",
- sysTime.wYear,
- sysTime.wMonth,
- sysTime.wDay);
- }
- if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st))))
- return NULL;
- /* Set default level to info */
- h->dwLogLevel = APXLOG_LEVEL_INFO;
- CreateDirectoryW(sPath, NULL);
-
- h->sysTime = sysTime;
- lstrcpyW(h->szPath, sPath);
- lstrcatW(sPath, sName);
- if (szPrefix)
- lstrcpyW(h->szPrefix, szPrefix);
-
- h->hFile = CreateFileW(sPath,
- GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
- NULL);
- /* Set this file as system log file */
- if (!_st_sys_loghandle)
- _st_sys_loghandle = h;
-
- return (HANDLE)h;
-}
-
-void apxLogLevelSet(HANDLE hFile, DWORD dwLevel)
-{
- apx_logfile_st *lf = (apx_logfile_st *)hFile;
- if (IS_INVALID_HANDLE(lf))
- lf = _st_sys_loghandle;
- if (IS_INVALID_HANDLE(lf))
- return;
- if (dwLevel < 4)
- lf->dwLogLevel = dwLevel;
-}
-
-void apxLogRotateSet(HANDLE hFile, BOOL doRotate)
-{
- apx_logfile_st *lf = (apx_logfile_st *)hFile;
- if (IS_INVALID_HANDLE(lf))
- lf = _st_sys_loghandle;
- if (IS_INVALID_HANDLE(lf))
- return;
- lf->bRotate = doRotate;
-}
-
-void apxLogLevelSetW(HANDLE hFile,
- LPCWSTR szLevel)
-{
- apx_logfile_st *lf = (apx_logfile_st *)hFile;
-
- if (IS_INVALID_HANDLE(lf))
- lf = _st_sys_loghandle;
- if (IS_INVALID_HANDLE(lf))
- return;
- if (szLevel) {
- if (!lstrcmpiW(szLevel, L"error"))
- lf->dwLogLevel = APXLOG_LEVEL_ERROR;
- else if (!lstrcmpiW(szLevel, L"warn"))
- lf->dwLogLevel = APXLOG_LEVEL_WARN;
- else if (!lstrcmpiW(szLevel, L"info"))
- lf->dwLogLevel = APXLOG_LEVEL_INFO;
- else if (!lstrcmpiW(szLevel, L"debug"))
- lf->dwLogLevel = APXLOG_LEVEL_DEBUG;
- }
-}
-
-static BOOL apx_log_rotate(apx_logfile_st *l,
- LPSYSTEMTIME lpCtime)
-{
- WCHAR sPath[MAX_PATH+1];
-
- /* rotate on daily basis */
- if (l->sysTime.wDay == lpCtime->wDay)
- return TRUE;
- FlushFileBuffers(l->hFile);
- CloseHandle(l->hFile);
- l->sysTime = *lpCtime;
-
- wsprintfW(sPath, L"%s\\%s%04d%02d%02d.log",
- l->szPath,
- l->szPrefix,
- l->sysTime.wYear,
- l->sysTime.wMonth,
- l->sysTime.wDay);
- l->hFile = CreateFileW(sPath,
- GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
- NULL);
- if (IS_INVALID_HANDLE(l->hFile))
- return FALSE;
- else
- return TRUE;
-}
-
-int
-apxLogWrite(
- HANDLE hFile,
- DWORD dwLevel,
- BOOL bTimeStamp,
- LPCSTR szFile,
- DWORD dwLine,
- LPCSTR szFormat,
- ...)
-{
- va_list args;
- CHAR buffer[1024+32];
- LPSTR szBp;
- int len = 0;
- LPCSTR f = szFile;
- CHAR sb[MAX_PATH+1];
- DWORD wr;
- DWORD err;
- BOOL dolock = TRUE;
- apx_logfile_st *lf = (apx_logfile_st *)hFile;
-
- if (IS_INVALID_HANDLE(lf))
- lf = _st_sys_loghandle;
- if (IS_INVALID_HANDLE(lf)) {
- lf = &_st_sys_errhandle;
- lf->hFile = GetStdHandle(STD_ERROR_HANDLE);
- dolock = FALSE;
- }
- if (dwLevel < lf->dwLogLevel)
- return 0;
- err = GetLastError(); /* save the last Error code */
- if (f) {
- f = (szFile + lstrlenA(szFile) - 1);
- while(f != szFile && '\\' != *f && '/' != *f)
- f--;
- if(f != szFile)
- f++;
- }
- lstrcpyA(buffer, _log_level[dwLevel]);
- if (!dolock)
- lstrcatA(buffer, "\n");
- szBp = &buffer[lstrlenA(buffer)];
- if (!szFormat) {
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- szBp,
- 1000,
- NULL);
- }
- else {
- va_start(args, szFormat);
- wvsprintfA(szBp, szFormat, args);
- va_end(args);
- }
- len = lstrlenA(buffer);
- if (len > 0) {
- /* Remove trailing line separator */
- if (buffer[len - 1] == '\n') {
- buffer[len - 1] = '\0';
- --len;
- }
- if (!IS_INVALID_HANDLE(lf->hFile)) {
- SYSTEMTIME t;
- GetLocalTime(&t);
- if (lf->bRotate) {
- if (!apx_log_rotate(lf, &t))
- return 0;
- }
- if (dolock) {
- APX_LOGLOCK(lf->hFile);
- }
- if (bTimeStamp) {
- wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
- t.wYear, t.wMonth, t.wDay,
- t.wHour, t.wMinute, t.wSecond);
- WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
- }
- if (f) {
- wsprintfA(sb, "[%-4d %s] ", dwLine, f);
- WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
- }
-
- WriteFile(lf->hFile, buffer, len, &wr, NULL);
- /* Terminate the line */
- WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
-#ifdef _DEBUG_FULL
- FlushFileBuffers(lf->hFile);
-#endif
- if (dolock) {
- APX_LOGUNLOCK(lf->hFile);
- }
- }
-#ifdef _DEBUG_FULL
- {
- char tid[1024 + 16];
- wsprintfA(tid, "[%04X] %s", GetCurrentThreadId(), buffer);
- OutputDebugStringA(tid);
- }
-#endif
- }
- /* Restore the last Error code */
- SetLastError(err);
- return len;
-}
-
-void apxLogClose(
- HANDLE hFile)
-{
- apx_logfile_st *lf = (apx_logfile_st *)hFile;
-
- if (IS_INVALID_HANDLE(lf))
- lf = _st_sys_loghandle;
- if (IS_INVALID_HANDLE(lf))
- return;
-
- FlushFileBuffers(lf->hFile);
- CloseHandle(lf->hFile);
- if (lf == _st_sys_loghandle)
- _st_sys_loghandle = NULL;
- apxFree(lf);
-}
-
-int
-apxDisplayError(
- BOOL bDisplay,
- LPCSTR szFile,
- DWORD dwLine,
- LPCSTR szFormat,
- ...)
-{
- va_list args;
- CHAR buffer[1024+16];
- CHAR sysbuf[2048];
- int len = 0, nRet;
- LPCSTR f = szFile;
- DWORD err = GetLastError(); /* save the last Error code */
- if (f) {
- f = (szFile + lstrlenA(szFile) - 1);
- while(f != szFile && '\\' != *f && '/' != *f)
- f--;
- if(f != szFile)
- f++;
- }
- sysbuf[0] = '\0';
- if (err != ERROR_SUCCESS) {
- len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- sysbuf,
- 1000,
- NULL);
- sysbuf[len] = 0;
- }
- if (szFormat) {
- va_start(args, szFormat);
- wvsprintfA(buffer, szFormat, args);
- va_end(args);
- if (f) {
- CHAR sb[MAX_PATH+1];
- wsprintfA(sb, "\n%s (%d)", f, dwLine);
- lstrcatA(sysbuf, sb);
- }
- lstrcatA(sysbuf, "\n");
- lstrcatA(sysbuf, buffer);
- }
- len = lstrlenA(sysbuf);
-#ifdef _DEBUG_FULL
- OutputDebugStringA(sysbuf);
-#endif
- if (len > 0 && bDisplay) {
- nRet = MessageBoxA(NULL, sysbuf,
- "Application System Error",
- MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
- }
- /* Restore the last Error code */
- SetLastError(err);
- return len;
-}
Copied: tags/jbosssvc/2.0.8/procrun/src/log.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/log.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/log.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/log.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,419 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+#include <stdio.h>
+
+#define LINE_SEP "\n"
+#define LOGF_EXT L".%04d-%02d-%02d.log"
+
+static LPCSTR _log_level[] = {
+ "[debug] ",
+ "[info] ",
+ "[warn] ",
+ "[error] ",
+ NULL
+};
+
+typedef struct apx_logfile_st {
+ HANDLE hFile;
+ DWORD dwLogLevel;
+ BOOL bRotate;
+ SYSTEMTIME sysTime;
+ WCHAR szPath[SIZ_PATHLEN];
+ WCHAR szPrefix[MAX_PATH];
+} apx_logfile_st;
+
+/* Per-application master log file */
+static apx_logfile_st *_st_sys_loghandle = NULL;
+
+static apx_logfile_st _st_sys_errhandle = { NULL, APXLOG_LEVEL_WARN, FALSE};
+
+
+LPWSTR apxLogFile(
+ APXHANDLE hPool,
+ LPCWSTR szPath,
+ LPCWSTR szPrefix,
+ LPCWSTR szName,
+ BOOL bTimeStamp)
+{
+ LPWSTR sRet;
+ WCHAR sPath[SIZ_PATHLEN];
+ WCHAR sName[SIZ_PATHLEN];
+ SYSTEMTIME sysTime;
+
+ GetLocalTime(&sysTime);
+ if (!szPath) {
+ if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
+ return INVALID_HANDLE_VALUE;
+ lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\Apache");
+ }
+ else {
+ lstrlcpyW(sPath, MAX_PATH, szPath);
+ }
+ if (!szPrefix)
+ szPrefix = L"";
+ if (!szName)
+ szName = L"";
+ if (bTimeStamp)
+ wsprintfW(sName,
+ L"\\%s%s" LOGF_EXT,
+ szPrefix,
+ szName,
+ sysTime.wYear,
+ sysTime.wMonth,
+ sysTime.wDay);
+ else
+ wsprintfW(sName,
+ L"\\%s%s",
+ szPrefix,
+ szName);
+
+ sRet = apxPoolAlloc(hPool, (SIZ_PATHLEN) * sizeof(WCHAR));
+ /* Set default level to info */
+ CreateDirectoryW(sPath, NULL);
+
+ lstrlcpyW(sRet, SIZ_PATHMAX, sPath);
+ lstrlcatW(sRet, SIZ_PATHMAX, sName);
+
+ return sRet;
+}
+
+/* Open the log file
+ * TODO: format like standard apache error.log
+ * Add the EventLogger
+ */
+HANDLE apxLogOpen(
+ APXHANDLE hPool,
+ LPCWSTR szPath,
+ LPCWSTR szPrefix)
+{
+
+ WCHAR sPath[SIZ_PATHLEN];
+ WCHAR sName[SIZ_PATHLEN];
+ SYSTEMTIME sysTime;
+ apx_logfile_st *h;
+
+ GetLocalTime(&sysTime);
+ if (!szPath) {
+ if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
+ return INVALID_HANDLE_VALUE;
+ lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\Apache");
+ }
+ else {
+ lstrlcpyW(sPath, MAX_PATH, szPath);
+ }
+ if (!szPrefix)
+ szPrefix = L"commons-daemon";
+ wsprintfW(sName, L"\\%s" LOGF_EXT,
+ szPrefix,
+ sysTime.wYear,
+ sysTime.wMonth,
+ sysTime.wDay);
+ if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st))))
+ return NULL;
+ /* Set default level to info */
+ h->dwLogLevel = APXLOG_LEVEL_INFO;
+ CreateDirectoryW(sPath, NULL);
+
+ h->sysTime = sysTime;
+ lstrlcpyW(h->szPath, MAX_PATH, sPath);
+ lstrlcatW(sPath, MAX_PATH, sName);
+ lstrlcpyW(h->szPrefix, MAX_PATH, szPrefix);
+
+ h->hFile = CreateFileW(sPath,
+ GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN,
+ NULL);
+ /* Set this file as system log file */
+ if (!_st_sys_loghandle)
+ _st_sys_loghandle = h;
+
+ return (HANDLE)h;
+}
+
+void apxLogLevelSet(HANDLE hFile, DWORD dwLevel)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+ if (dwLevel < 4)
+ lf->dwLogLevel = dwLevel;
+}
+
+void apxLogRotateSet(HANDLE hFile, BOOL doRotate)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+ lf->bRotate = doRotate;
+}
+
+void apxLogLevelSetW(HANDLE hFile,
+ LPCWSTR szLevel)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+ if (szLevel) {
+ if (!lstrcmpiW(szLevel, L"error"))
+ lf->dwLogLevel = APXLOG_LEVEL_ERROR;
+ else if (!lstrcmpiW(szLevel, L"warn"))
+ lf->dwLogLevel = APXLOG_LEVEL_WARN;
+ else if (!lstrcmpiW(szLevel, L"info"))
+ lf->dwLogLevel = APXLOG_LEVEL_INFO;
+ else if (!lstrcmpiW(szLevel, L"debug"))
+ lf->dwLogLevel = APXLOG_LEVEL_DEBUG;
+ }
+}
+
+static BOOL apx_log_rotate(apx_logfile_st *l,
+ LPSYSTEMTIME lpCtime)
+{
+ WCHAR sPath[SIZ_PATHLEN];
+
+ /* rotate on daily basis */
+ if (l->sysTime.wDay == lpCtime->wDay)
+ return TRUE;
+ FlushFileBuffers(l->hFile);
+ CloseHandle(l->hFile);
+ l->sysTime = *lpCtime;
+
+ wsprintfW(sPath, L"%s\\%s" LOGF_EXT,
+ l->szPath,
+ l->szPrefix,
+ l->sysTime.wYear,
+ l->sysTime.wMonth,
+ l->sysTime.wDay);
+ l->hFile = CreateFileW(sPath,
+ GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN,
+ NULL);
+ if (IS_INVALID_HANDLE(l->hFile))
+ return FALSE;
+ else
+ return TRUE;
+}
+
+int
+apxLogWrite(
+ HANDLE hFile,
+ DWORD dwLevel,
+ BOOL bTimeStamp,
+ LPCSTR szFile,
+ DWORD dwLine,
+ LPCSTR szFormat,
+ ...)
+{
+ va_list args;
+ CHAR buffer[1024+32];
+ LPSTR szBp;
+ int len = 0;
+ LPCSTR f = szFile;
+ CHAR sb[SIZ_PATHLEN];
+ DWORD wr;
+ DWORD err;
+ BOOL dolock = TRUE;
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+ err = GetLastError(); /* save the last Error code */
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf)) {
+ lf = &_st_sys_errhandle;
+ lf->hFile = GetStdHandle(STD_ERROR_HANDLE);
+ dolock = FALSE;
+ }
+ if (dwLevel < lf->dwLogLevel)
+ return 0;
+ if (f) {
+ f = (szFile + lstrlenA(szFile) - 1);
+ while(f != szFile && '\\' != *f && '/' != *f)
+ f--;
+ if(f != szFile)
+ f++;
+ }
+ szBp = &buffer[0];
+ if (!szFormat) {
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ szBp,
+ 1000,
+ NULL);
+ }
+ else {
+ va_start(args, szFormat);
+ wvsprintfA(szBp, szFormat, args);
+ va_end(args);
+ }
+ len = lstrlenA(buffer);
+ if (len > 0) {
+ /* Remove trailing line separator */
+ if (buffer[len - 1] == '\n') {
+ buffer[len - 1] = '\0';
+ --len;
+ }
+ if (!IS_INVALID_HANDLE(lf->hFile)) {
+ SYSTEMTIME t;
+ GetLocalTime(&t);
+ if (lf->bRotate) {
+ if (!apx_log_rotate(lf, &t))
+ return 0;
+ }
+ if (dolock) {
+ APX_LOGLOCK(lf->hFile);
+ }
+ if (bTimeStamp) {
+ wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
+ t.wYear, t.wMonth, t.wDay,
+ t.wHour, t.wMinute, t.wSecond);
+ WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+ }
+ WriteFile(lf->hFile, _log_level[dwLevel],
+ strlen(_log_level[dwLevel]), &wr, NULL);
+ if (f && lf->dwLogLevel == APXLOG_LEVEL_DEBUG) {
+ wsprintfA(sb, "(%10s:%-4d) ", f, dwLine);
+ WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+ }
+ WriteFile(lf->hFile, buffer, len, &wr, NULL);
+
+ /* Terminate the line */
+ WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
+#ifdef _DEBUG_FULL
+ FlushFileBuffers(lf->hFile);
+#endif
+ if (dolock) {
+ APX_LOGUNLOCK(lf->hFile);
+ }
+ }
+#ifdef _DEBUG_FULL
+ {
+ char tid[1024 + 16];
+ wsprintfA(tid, "[%04d] %s", GetCurrentThreadId(), buffer);
+ OutputDebugStringA(tid);
+ }
+#endif
+ }
+ /* Restore the last Error code */
+ SetLastError(err);
+ return len;
+}
+
+void apxLogClose(
+ HANDLE hFile)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+
+ FlushFileBuffers(lf->hFile);
+ CloseHandle(lf->hFile);
+ if (lf == _st_sys_loghandle)
+ _st_sys_loghandle = NULL;
+ apxFree(lf);
+}
+
+int
+apxDisplayError(
+ BOOL bDisplay,
+ LPCSTR szFile,
+ DWORD dwLine,
+ LPCSTR szFormat,
+ ...)
+{
+ va_list args;
+ CHAR buffer[SIZ_HUGLEN];
+ CHAR sysbuf[SIZ_HUGLEN];
+ int len = 0, nRet;
+ LPCSTR f = szFile;
+ DWORD err = GetLastError(); /* save the last Error code */
+ if (f) {
+ f = (szFile + lstrlenA(szFile) - 1);
+ while(f != szFile && '\\' != *f && '/' != *f)
+ f--;
+ if(f != szFile)
+ f++;
+ }
+ sysbuf[0] = '\0';
+ if (err != ERROR_SUCCESS) {
+ len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ sysbuf,
+ SIZ_DESLEN,
+ NULL);
+ if (len > 0) {
+ sysbuf[len] = '\0';
+ if (sysbuf[len - 1] == '\n') {
+ sysbuf[len - 1] = '\0';
+ --len;
+ }
+ }
+ else
+ sysbuf[0] = '\0';
+ }
+ if (szFormat) {
+ va_start(args, szFormat);
+ wvsprintfA(buffer, szFormat, args);
+ va_end(args);
+ if (f) {
+ CHAR sb[SIZ_PATHLEN];
+ wsprintfA(sb, "%s (%d)", f, dwLine);
+ lstrcatA(sysbuf, sb);
+ }
+ lstrlcatA(sysbuf, SIZ_HUGLEN, "\n");
+ lstrlcatA(sysbuf, SIZ_HUGLEN, buffer);
+ }
+ len = lstrlenA(sysbuf);
+#ifdef _DEBUG_FULL
+ OutputDebugStringA(sysbuf);
+#endif
+ if (len > 0) {
+ if (bDisplay) {
+ nRet = MessageBoxA(NULL, sysbuf,
+ "Application System Error",
+ MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
+ }
+ else {
+ fputs(sysbuf, stderr);
+ fputc('\n', stderr);
+ fflush(stderr);
+ }
+ }
+ /* Restore the last Error code */
+ SetLastError(err);
+ return len;
+}
Deleted: tags/jbosssvc/2.0.8/procrun/src/mclib.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/mclib.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/mclib.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,294 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Andrew Hume of AT&T Bell Laboratories.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-typedef UINT word; /* "word" used for optimal copy speed */
-#define wsize sizeof(UINT)
-#define wmask (wsize - 1)
-
-LPVOID AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill)
-{
-
- SIZE_T t;
-#ifdef WIN64
- UINT64 c;
-#else
- UINT c;
-#endif
- LPBYTE dst;
-
- dst = Destination;
- /*
- * If not enough words, just fill bytes. A length >= 2 words
- * guarantees that at least one of them is `complete' after
- * any necessary alignment. For instance:
- *
- * |-----------|-----------|-----------|
- * |00|01|02|03|04|05|06|07|08|09|0A|00|
- * ^---------------------^
- * dst dst+length-1
- *
- * but we use a minimum of 3 here since the overhead of the code
- * to do word writes is substantial.
- */
- if (Length < 3 * wsize) {
- while (Length != 0) {
- *dst++ = Fill;
- --Length;
- }
- return (Destination);
- }
-
- if ((c = Fill) != 0) { /* Fill the word. */
- c = (c << 8) | c; /* u_int is 16 bits. */
- c = (c << 16) | c; /* u_int is 32 bits. */
-#ifdef WIN64
- c = (c << 32) | c; /* u_int is 64 bits. */
-#endif
- }
- /* Align destination by filling in bytes. */
- if ((t = (SIZE_T)dst & wmask) != 0) {
- t = wsize - t;
- Length -= t;
- do {
- *dst++ = Fill;
- } while (--t != 0);
- }
-
- /* Fill words. Length was >= 2*words so we know t >= 1 here. */
- t = Length / wsize;
- do {
-#ifdef WIN64
- *(UINT64 *)dst = c;
-#else
- *(UINT *)dst = c;
-#endif
- dst += wsize;
- } while (--t != 0);
-
- /* Mop up trailing bytes, if any. */
- t = Length & wmask;
- if (t != 0)
- do {
- *dst++ = Fill;
- } while (--t != 0);
- return (Destination);
-}
-
-void AplZeroMemory(PVOID Destination, SIZE_T Length)
-{
-
- SIZE_T t;
- LPBYTE dst;
-
- dst = Destination;
- /*
- * If not enough words, just fill bytes. A length >= 2 words
- * guarantees that at least one of them is `complete' after
- * any necessary alignment. For instance:
- *
- * |-----------|-----------|-----------|
- * |00|01|02|03|04|05|06|07|08|09|0A|00|
- * ^---------------------^
- * dst dst+length-1
- *
- * but we use a minimum of 3 here since the overhead of the code
- * to do word writes is substantial.
- */
- if (Length < 3 * wsize) {
- while (Length != 0) {
- *dst++ = 0;
- --Length;
- }
- return;
- }
-
- /* Align destination by filling in bytes. */
- if ((t = (SIZE_T)dst & wmask) != 0) {
- t = wsize - t;
- Length -= t;
- do {
- *dst++ = 0;
- } while (--t != 0);
- }
-
- /* Fill words. Length was >= 2*words so we know t >= 1 here. */
- t = Length / wsize;
- do {
- *(UINT *)dst = 0;
- dst += wsize;
- } while (--t != 0);
-
- /* Mop up trailing bytes, if any. */
- t = Length & wmask;
- if (t != 0)
- do {
- *dst++ = 0;
- } while (--t != 0);
-}
-
-LPVOID AplCopyMemory(PVOID Destination, const VOID* Source, SIZE_T Length)
-{
- char *dst = Destination;
- const char *src = Source;
- SIZE_T t;
-
- if (Length == 0 || dst == src) /* nothing to do */
- goto done;
-
- /*
- * Macros: loop-t-times; and loop-t-times, t>0
- */
-#define TLOOP(s) if (t) TLOOP1(s)
-#define TLOOP1(s) do { s; } while (--t)
-
- if ((SIZE_T)dst < (SIZE_T)src) {
- /*
- * Copy forward.
- */
- t = (int)(SIZE_T)src; /* only need low bits */
- if ((t | (int)(SIZE_T)dst) & wmask) {
- /*
- * Try to align operands. This cannot be done
- * unless the low bits match.
- */
- if ((t ^ (int)(SIZE_T)dst) & wmask || Length < wsize)
- t = Length;
- else
- t = wsize - (t & wmask);
- Length -= t;
- TLOOP1(*dst++ = *src++);
- }
- /*
- * Copy whole words, then mop up any trailing bytes.
- */
- t = Length / wsize;
- TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
- t = Length & wmask;
- TLOOP(*dst++ = *src++);
- } else {
- /*
- * Copy backwards. Otherwise essentially the same.
- * Alignment works as before, except that it takes
- * (t&wmask) bytes to align, not wsize-(t&wmask).
- */
- src += Length;
- dst += Length;
- t = (int)(SIZE_T)src;
- if ((t | (int)(SIZE_T)dst) & wmask) {
- if ((t ^ (int)(SIZE_T)dst) & wmask || Length <= wsize)
- t = Length;
- else
- t &= wmask;
- Length -= t;
- TLOOP1(*--dst = *--src);
- }
- t = Length / wsize;
- TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
- t = Length & wmask;
- TLOOP(*--dst = *--src);
- }
-done:
- return (Destination);
-}
-
-
-INT
-AplMemCmp(LPCVOID lpA, LPCVOID lpB, SIZE_T nBytes)
-{
- if (nBytes != 0) {
- const BYTE *p1 = lpA, *p2 = lpB;
-
- do {
- if (*p1++ != *p2++)
- return (*--p1 - *--p2);
- } while (--nBytes != 0);
- }
- return 0;
-}
-
-/*
- * Find the first occurrence of lpFind in lpMem.
- * dwLen: The length of lpFind
- * dwSize: The length of lpMem
- */
-LPBYTE
-ApcMemSearch(LPCVOID lpMem, LPCVOID lpFind, SIZE_T dwLen, SIZE_T dwSize)
-{
- BYTE c, sc;
- SIZE_T cnt = 0;
- const BYTE *s = lpMem, *find = lpFind;
-
- if ((c = *find++) != 0) {
- do {
- do {
- sc = *s++;
- if (cnt++ > dwSize)
- return NULL;
- } while (sc != c);
- } while (AplMemCmp(s, find, dwLen - 1) != 0);
- s--;
- }
- return (LPBYTE)s;
-}
-
-LPSTR
-AplRindexA(LPCSTR lpStr, int ch)
-{
- LPSTR save;
-
- for (save = NULL;; ++lpStr) {
- if (*lpStr == ch)
- save = (LPSTR)lpStr;
- if (!*lpStr)
- return save;
- }
- /* NOTREACHED */
-}
Copied: tags/jbosssvc/2.0.8/procrun/src/mclib.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/mclib.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/mclib.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/mclib.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,409 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Copyright (c) 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Andrew Hume of AT&T Bell Laboratories.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+typedef UINT word; /* "word" used for optimal copy speed */
+#define wsize sizeof(UINT)
+#define wmask (wsize - 1)
+
+LPVOID AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill)
+{
+
+ SIZE_T t;
+#ifdef WIN64
+ UINT64 c;
+#else
+ UINT c;
+#endif
+ LPBYTE dst;
+
+ dst = Destination;
+ /*
+ * If not enough words, just fill bytes. A length >= 2 words
+ * guarantees that at least one of them is `complete' after
+ * any necessary alignment. For instance:
+ *
+ * |-----------|-----------|-----------|
+ * |00|01|02|03|04|05|06|07|08|09|0A|00|
+ * ^---------------------^
+ * dst dst+length-1
+ *
+ * but we use a minimum of 3 here since the overhead of the code
+ * to do word writes is substantial.
+ */
+ if (Length < 3 * wsize) {
+ while (Length != 0) {
+ *dst++ = Fill;
+ --Length;
+ }
+ return (Destination);
+ }
+
+ if ((c = Fill) != 0) { /* Fill the word. */
+ c = (c << 8) | c; /* u_int is 16 bits. */
+ c = (c << 16) | c; /* u_int is 32 bits. */
+#ifdef WIN64
+ c = (c << 32) | c; /* u_int is 64 bits. */
+#endif
+ }
+ /* Align destination by filling in bytes. */
+ if ((t = (SIZE_T)dst & wmask) != 0) {
+ t = wsize - t;
+ Length -= t;
+ do {
+ *dst++ = Fill;
+ } while (--t != 0);
+ }
+
+ /* Fill words. Length was >= 2*words so we know t >= 1 here. */
+ t = Length / wsize;
+ do {
+#ifdef WIN64
+ *(UINT64 *)dst = c;
+#else
+ *(UINT *)dst = c;
+#endif
+ dst += wsize;
+ } while (--t != 0);
+
+ /* Mop up trailing bytes, if any. */
+ t = Length & wmask;
+ if (t != 0)
+ do {
+ *dst++ = Fill;
+ } while (--t != 0);
+ return (Destination);
+}
+
+void AplZeroMemory(PVOID Destination, SIZE_T Length)
+{
+
+ SIZE_T t;
+ LPBYTE dst;
+
+ dst = Destination;
+ /*
+ * If not enough words, just fill bytes. A length >= 2 words
+ * guarantees that at least one of them is `complete' after
+ * any necessary alignment. For instance:
+ *
+ * |-----------|-----------|-----------|
+ * |00|01|02|03|04|05|06|07|08|09|0A|00|
+ * ^---------------------^
+ * dst dst+length-1
+ *
+ * but we use a minimum of 3 here since the overhead of the code
+ * to do word writes is substantial.
+ */
+ if (Length < 3 * wsize) {
+ while (Length != 0) {
+ *dst++ = 0;
+ --Length;
+ }
+ return;
+ }
+
+ /* Align destination by filling in bytes. */
+ if ((t = (SIZE_T)dst & wmask) != 0) {
+ t = wsize - t;
+ Length -= t;
+ do {
+ *dst++ = 0;
+ } while (--t != 0);
+ }
+
+ /* Fill words. Length was >= 2*words so we know t >= 1 here. */
+ t = Length / wsize;
+ do {
+ *(UINT *)dst = 0;
+ dst += wsize;
+ } while (--t != 0);
+
+ /* Mop up trailing bytes, if any. */
+ t = Length & wmask;
+ if (t != 0)
+ do {
+ *dst++ = 0;
+ } while (--t != 0);
+}
+
+LPVOID AplCopyMemory(PVOID Destination, const VOID* Source, SIZE_T Length)
+{
+ char *dst = Destination;
+ const char *src = Source;
+ SIZE_T t;
+
+ if (Length == 0 || dst == src) /* nothing to do */
+ goto done;
+
+ /*
+ * Macros: loop-t-times; and loop-t-times, t>0
+ */
+#define TLOOP(s) if (t) TLOOP1(s)
+#define TLOOP1(s) do { s; } while (--t)
+
+ if ((SIZE_T)dst < (SIZE_T)src) {
+ /*
+ * Copy forward.
+ */
+ t = (int)(SIZE_T)src; /* only need low bits */
+ if ((t | (int)(SIZE_T)dst) & wmask) {
+ /*
+ * Try to align operands. This cannot be done
+ * unless the low bits match.
+ */
+ if ((t ^ (int)(SIZE_T)dst) & wmask || Length < wsize)
+ t = Length;
+ else
+ t = wsize - (t & wmask);
+ Length -= t;
+ TLOOP1(*dst++ = *src++);
+ }
+ /*
+ * Copy whole words, then mop up any trailing bytes.
+ */
+ t = Length / wsize;
+ TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
+ t = Length & wmask;
+ TLOOP(*dst++ = *src++);
+ } else {
+ /*
+ * Copy backwards. Otherwise essentially the same.
+ * Alignment works as before, except that it takes
+ * (t&wmask) bytes to align, not wsize-(t&wmask).
+ */
+ src += Length;
+ dst += Length;
+ t = (int)(SIZE_T)src;
+ if ((t | (int)(SIZE_T)dst) & wmask) {
+ if ((t ^ (int)(SIZE_T)dst) & wmask || Length <= wsize)
+ t = Length;
+ else
+ t &= wmask;
+ Length -= t;
+ TLOOP1(*--dst = *--src);
+ }
+ t = Length / wsize;
+ TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
+ t = Length & wmask;
+ TLOOP(*--dst = *--src);
+ }
+done:
+ return (Destination);
+}
+
+
+INT
+AplMemCmp(LPCVOID lpA, LPCVOID lpB, SIZE_T nBytes)
+{
+ if (nBytes != 0) {
+ const BYTE *p1 = lpA, *p2 = lpB;
+
+ do {
+ if (*p1++ != *p2++)
+ return (*--p1 - *--p2);
+ } while (--nBytes != 0);
+ }
+ return 0;
+}
+
+/*
+ * Find the first occurrence of lpFind in lpMem.
+ * dwLen: The length of lpFind
+ * dwSize: The length of lpMem
+ */
+LPBYTE
+ApcMemSearch(LPCVOID lpMem, LPCVOID lpFind, SIZE_T dwLen, SIZE_T dwSize)
+{
+ BYTE c, sc;
+ SIZE_T cnt = 0;
+ const BYTE *s = lpMem, *find = lpFind;
+
+ if ((c = *find++) != 0) {
+ do {
+ do {
+ sc = *s++;
+ if (cnt++ > dwSize)
+ return NULL;
+ } while (sc != c);
+ } while (AplMemCmp(s, find, dwLen - 1) != 0);
+ s--;
+ }
+ return (LPBYTE)s;
+}
+
+LPSTR
+AplRindexA(LPCSTR lpStr, int ch)
+{
+ LPSTR save;
+
+ for (save = NULL;; ++lpStr) {
+ if (*lpStr == ch)
+ save = (LPSTR)lpStr;
+ if (!*lpStr)
+ return save;
+ }
+ /* NOTREACHED */
+}
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+LPSTR
+lstrlcatA(LPSTR dst, int siz, LPCSTR src)
+{
+ LPSTR d = dst;
+ LPCSTR s = src;
+ int n = siz;
+ int dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return NULL;
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return dst;
+}
+
+LPWSTR
+lstrlcatW(LPWSTR dst, int siz, LPCWSTR src)
+{
+ LPWSTR d = dst;
+ LPCWSTR s = src;
+ int n = siz;
+ int dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return NULL;
+ while (*s != L'\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = L'\0';
+
+ return dst;
+}
+
+LPSTR
+lstrlcpyA(LPSTR dst, int siz, LPCSTR src)
+{
+ LPSTR d = dst;
+ LPCSTR s = src;
+ int n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return d;
+}
+
+LPWSTR
+lstrlcpyW(LPWSTR dst, int siz, LPCWSTR src)
+{
+ LPWSTR d = dst;
+ LPCWSTR s = src;
+ int n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == L'\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = L'\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return d;
+}
Deleted: tags/jbosssvc/2.0.8/procrun/src/private.h
===================================================================
--- trunk/utils/windows/native/service/procrun/src/private.h 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/private.h 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,274 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _PRIVATE_H_INCLUDED_
-#define _PRIVATE_H_INCLUDED_
-
-#include "mclib.h"
-
-#ifdef _DEBUG
-
-HANDLE HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
-BOOL HeapDESTROY(HANDLE hHeap);
-
-LPVOID HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize);
-BOOL HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
-LPVOID HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
-
-#else
-
-#define HeapCREATE HeapCreate
-#define HeapDESTROY HeapDestroy
-#define HeapALLOC HeapAlloc
-#define HeapFREE HeapFree
-#define HeapREALLOC HeapReAlloc
-
-#endif
-
-/*
- * Tail queue declarations.
- */
-#define TAILQ_HEAD(name, type) \
-struct name { \
- struct type *tqh_first; /* first element */ \
- struct type **tqh_last; /* addr of last next element */ \
-}
-
-#define TAILQ_HEAD_INITIALIZER(head) \
- { NULL, &(head).tqh_first }
-
-#define TAILQ_ENTRY(type) \
-struct { \
- struct type *tqe_next; /* next element */ \
- struct type **tqe_prev; /* address of previous next element */ \
-}
-
-/*
- * Tail queue functions.
- */
-#define TAILQ_CONCAT(head1, head2, field) do { \
- if (!TAILQ_EMPTY(head2)) { \
- *(head1)->tqh_last = (head2)->tqh_first; \
- (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
- (head1)->tqh_last = (head2)->tqh_last; \
- TAILQ_INIT((head2)); \
- } \
-} while (0)
-
-#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
-
-#define TAILQ_FIRST(head) ((head)->tqh_first)
-
-#define TAILQ_FOREACH(var, head, field) \
- for ((var) = TAILQ_FIRST((head)); \
- (var); \
- (var) = TAILQ_NEXT((var), field))
-
-#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
- for ((var) = TAILQ_LAST((head), headname); \
- (var); \
- (var) = TAILQ_PREV((var), headname, field))
-
-#define TAILQ_INIT(head) do { \
- TAILQ_FIRST((head)) = NULL; \
- (head)->tqh_last = &TAILQ_FIRST((head)); \
-} while (0)
-
-#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
- if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
- TAILQ_NEXT((elm), field)->field.tqe_prev = \
- &TAILQ_NEXT((elm), field); \
- else { \
- (head)->tqh_last = &TAILQ_NEXT((elm), field); \
- } \
- TAILQ_NEXT((listelm), field) = (elm); \
- (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
-} while (0)
-
-#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
- (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
- TAILQ_NEXT((elm), field) = (listelm); \
- *(listelm)->field.tqe_prev = (elm); \
- (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
-} while (0)
-
-#define TAILQ_INSERT_HEAD(head, elm, field) do { \
- if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
- TAILQ_FIRST((head))->field.tqe_prev = \
- &TAILQ_NEXT((elm), field); \
- else \
- (head)->tqh_last = &TAILQ_NEXT((elm), field); \
- TAILQ_FIRST((head)) = (elm); \
- (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
-} while (0)
-
-#define TAILQ_INSERT_TAIL(head, elm, field) do { \
- TAILQ_NEXT((elm), field) = NULL; \
- (elm)->field.tqe_prev = (head)->tqh_last; \
- *(head)->tqh_last = (elm); \
- (head)->tqh_last = &TAILQ_NEXT((elm), field); \
-} while (0)
-
-#define TAILQ_LAST(head, headname) \
- (*(((struct headname *)((head)->tqh_last))->tqh_last))
-
-#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
-
-#define TAILQ_PREV(elm, headname, field) \
- (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
-
-#define TAILQ_REMOVE(head, elm, field) do { \
- if ((TAILQ_NEXT((elm), field)) != NULL) \
- TAILQ_NEXT((elm), field)->field.tqe_prev = \
- (elm)->field.tqe_prev; \
- else { \
- (head)->tqh_last = (elm)->field.tqe_prev; \
- } \
- *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
-} while (0)
-
-/** Some usefull macros */
-
-#define APXHANDLE_SPINLOCK(h) \
- APXMACRO_BEGIN \
- while (InterlockedCompareExchange(&((h)->lvSpin), 1, 0) != 0) { \
- Sleep(10); \
- SwitchToThread(); \
- } \
- APXMACRO_END
-
-#define APXHANDLE_SPINUNLOCK(h) \
- APXMACRO_BEGIN \
- InterlockedExchange(&((h)->lvSpin), 0); \
- APXMACRO_END
-
-#define APX_SPINLOCK(lock) \
- APXMACRO_BEGIN \
- while (InterlockedCompareExchange(&(lock), 1, 0) != 0) \
- SwitchToThread(); \
- APXMACRO_END
-
-#define APX_SPINUNLOCK(lock) \
- APXMACRO_BEGIN \
- InterlockedExchange(&(lock), 0); \
- APXMACRO_END
-
-/*
- * Define a union with types which are likely to have the longest
- * *relevant* CPU-specific memory word alignment restrictions...
- */
-typedef union APXMEMWORD {
- void *vp;
- void (*fp)(void);
- char *cp;
- long l;
- double d;
-} APXMEMWORD;
-
-typedef struct APXCALLHOOK APXCALLHOOK;
-
-struct APXCALLHOOK {
-
- LPAPXFNCALLBACK fnCallback;
- TAILQ_ENTRY(APXCALLHOOK) queue;
-};
-
-struct stAPXHANDLE {
- /** The type of the handle */
- DWORD dwType;
- /** Handle Flags */
- DWORD dwFlags;
- /** Handle user data size */
- DWORD dwSize;
- /** parameters for event callback */
- WPARAM wParam;
- LPARAM lParam;
- UINT uMsg;
- /** main callback function (using default if not specified) */
- LPAPXFNCALLBACK fnCallback;
- /** callback functions hook list */
- TAILQ_HEAD(_lCallbacks, APXCALLHOOK) lCallbacks;
- /** allocation pool */
- APXHANDLE hPool;
- /** interlocking value */
- LONG volatile lvSpin;
-
- /** message event handle */
- HANDLE hEventHandle;
- /** message event thread */
- HANDLE hEventThread;
- /** message event thread id */
- DWORD hEventThreadId;
- /** private local heap */
- HANDLE hHeap;
- /** list enty for pool */
- TAILQ_ENTRY(stAPXHANDLE) queue;
- /** small userdata pointer */
- union {
- LPVOID lpPtr;
- HANDLE hWinHandle;
- double dValue;
- void (*fpValue)();
- } uData;
-
- APXMEMWORD stAlign;
-};
-
-#define APXHANDLE_DATA(h) ((void *)((char*)(h) + sizeof(stAPXHANDLE)))
-#define APXHANDLE_SZ sizeof(stAPXHANDLE)
-
-extern APX_OSLEVEL _st_apx_oslevel;
-
-#define APX_GET_OSLEVEL() ((_st_apx_oslevel == APX_WINVER_UNK) ? apxGetOsLevel() : _st_apx_oslevel)
-
-#ifdef _DEBUG
-void ErrorMessage(LPCTSTR szError, BOOL bFatal);
-#else
-#define ErrorMessage(szError, bFatal) ((void)0)
-#endif
-/* zero separated, double zero terminated string */
-struct APXMULTISZ {
- DWORD dwAllocated; /* length including terminators */
- DWORD dwInsert; /* next insert position */
-};
-
-typedef struct APXREGENUM {
- HKEY hServicesKey;
- DWORD dwIndex; /* current enum index */
- DWORD cSubKeys; /* number of subkeys */
- DWORD cbMaxSubKey; /* longest subkey size */
- DWORD cchMaxClass; /* longest class string */
- DWORD cValues; /* number of values for key */
- DWORD cchMaxValue; /* longest value name */
- DWORD cbMaxValueData; /* longest value data */
-
-} APXREGENUM, *LPAPXREGENUM;
-
-BOOL apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry);
-
-BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription);
-BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
- DWORD dwDescriptionLength);
-BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
- DWORD dwUserLength);
-
-DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount);
-DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount);
-LPSTR __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName);
-LPWSTR __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName);
-
-
-#endif /* _PRIVATE_H_INCLUDED_ */
Copied: tags/jbosssvc/2.0.8/procrun/src/private.h (from rev 2689, trunk/utils/windows/native/service/procrun/src/private.h)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/private.h (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/private.h 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,269 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVATE_H_INCLUDED_
+#define _PRIVATE_H_INCLUDED_
+
+#include "mclib.h"
+
+#ifdef _DEBUG
+
+HANDLE HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
+BOOL HeapDESTROY(HANDLE hHeap);
+
+LPVOID HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize);
+BOOL HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
+LPVOID HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
+
+#else
+
+#define HeapCREATE HeapCreate
+#define HeapDESTROY HeapDestroy
+#define HeapALLOC HeapAlloc
+#define HeapFREE HeapFree
+#define HeapREALLOC HeapReAlloc
+
+#endif
+
+/*
+ * Tail queue declarations.
+ */
+#define TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+}
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_CONCAT(head1, head2, field) do { \
+ if (!TAILQ_EMPTY(head2)) { \
+ *(head1)->tqh_last = (head2)->tqh_first; \
+ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
+ (head1)->tqh_last = (head2)->tqh_last; \
+ TAILQ_INIT((head2)); \
+ } \
+} while (0)
+
+#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
+
+#define TAILQ_FIRST(head) ((head)->tqh_first)
+
+#define TAILQ_FOREACH(var, head, field) \
+ for ((var) = TAILQ_FIRST((head)); \
+ (var); \
+ (var) = TAILQ_NEXT((var), field))
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for ((var) = TAILQ_LAST((head), headname); \
+ (var); \
+ (var) = TAILQ_PREV((var), headname, field))
+
+#define TAILQ_INIT(head) do { \
+ TAILQ_FIRST((head)) = NULL; \
+ (head)->tqh_last = &TAILQ_FIRST((head)); \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
+ TAILQ_NEXT((elm), field)->field.tqe_prev = \
+ &TAILQ_NEXT((elm), field); \
+ else { \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+ } \
+ TAILQ_NEXT((listelm), field) = (elm); \
+ (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
+} while (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ TAILQ_NEXT((elm), field) = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
+ TAILQ_FIRST((head))->field.tqe_prev = \
+ &TAILQ_NEXT((elm), field); \
+ else \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+ TAILQ_FIRST((head)) = (elm); \
+ (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
+} while (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ TAILQ_NEXT((elm), field) = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+} while (0)
+
+#define TAILQ_LAST(head, headname) \
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
+
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+
+#define TAILQ_PREV(elm, headname, field) \
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+
+#define TAILQ_REMOVE(head, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field)) != NULL) \
+ TAILQ_NEXT((elm), field)->field.tqe_prev = \
+ (elm)->field.tqe_prev; \
+ else { \
+ (head)->tqh_last = (elm)->field.tqe_prev; \
+ } \
+ *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
+} while (0)
+
+/** Some usefull macros */
+
+#define APXHANDLE_SPINLOCK(h) \
+ APXMACRO_BEGIN \
+ while (InterlockedCompareExchange(&((h)->lvSpin), 1, 0) != 0) { \
+ Sleep(10); \
+ SwitchToThread(); \
+ } \
+ APXMACRO_END
+
+#define APXHANDLE_SPINUNLOCK(h) \
+ APXMACRO_BEGIN \
+ InterlockedExchange(&((h)->lvSpin), 0); \
+ APXMACRO_END
+
+#define APX_SPINLOCK(lock) \
+ APXMACRO_BEGIN \
+ while (InterlockedCompareExchange(&(lock), 1, 0) != 0) \
+ SwitchToThread(); \
+ APXMACRO_END
+
+#define APX_SPINUNLOCK(lock) \
+ APXMACRO_BEGIN \
+ InterlockedExchange(&(lock), 0); \
+ APXMACRO_END
+
+/*
+ * Define a union with types which are likely to have the longest
+ * *relevant* CPU-specific memory word alignment restrictions...
+ */
+typedef union APXMEMWORD {
+ void *vp;
+ void (*fp)(void);
+ char *cp;
+ long l;
+ double d;
+} APXMEMWORD;
+
+typedef struct APXCALLHOOK APXCALLHOOK;
+
+struct APXCALLHOOK {
+
+ LPAPXFNCALLBACK fnCallback;
+ TAILQ_ENTRY(APXCALLHOOK) queue;
+};
+
+struct stAPXHANDLE {
+ /** The type of the handle */
+ DWORD dwType;
+ /** Handle Flags */
+ DWORD dwFlags;
+ /** Handle user data size */
+ DWORD dwSize;
+ /** parameters for event callback */
+ WPARAM wParam;
+ LPARAM lParam;
+ UINT uMsg;
+ /** main callback function (using default if not specified) */
+ LPAPXFNCALLBACK fnCallback;
+ /** callback functions hook list */
+ TAILQ_HEAD(_lCallbacks, APXCALLHOOK) lCallbacks;
+ /** allocation pool */
+ APXHANDLE hPool;
+ /** interlocking value */
+ LONG volatile lvSpin;
+
+ /** message event handle */
+ HANDLE hEventHandle;
+ /** message event thread */
+ HANDLE hEventThread;
+ /** message event thread id */
+ DWORD hEventThreadId;
+ /** private local heap */
+ HANDLE hHeap;
+ /** list enty for pool */
+ TAILQ_ENTRY(stAPXHANDLE) queue;
+ /** small userdata pointer */
+ union {
+ LPVOID lpPtr;
+ HANDLE hWinHandle;
+ double dValue;
+ void (*fpValue)();
+ } uData;
+
+ APXMEMWORD stAlign;
+};
+
+#define APXHANDLE_DATA(h) ((void *)((char*)(h) + sizeof(stAPXHANDLE)))
+#define APXHANDLE_SZ sizeof(stAPXHANDLE)
+
+extern APX_OSLEVEL _st_apx_oslevel;
+
+#define APX_GET_OSLEVEL() ((_st_apx_oslevel == APX_WINVER_UNK) ? apxGetOsLevel() : _st_apx_oslevel)
+
+/* zero separated, double zero terminated string */
+struct APXMULTISZ {
+ DWORD dwAllocated; /* length including terminators */
+ DWORD dwInsert; /* next insert position */
+};
+
+typedef struct APXREGENUM {
+ HKEY hServicesKey;
+ DWORD dwIndex; /* current enum index */
+ DWORD cSubKeys; /* number of subkeys */
+ DWORD cbMaxSubKey; /* longest subkey size */
+ DWORD cchMaxClass; /* longest class string */
+ DWORD cValues; /* number of values for key */
+ DWORD cchMaxValue; /* longest value name */
+ DWORD cbMaxValueData; /* longest value data */
+
+} APXREGENUM, *LPAPXREGENUM;
+
+BOOL apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry);
+
+BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription);
+BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
+ DWORD dwDescriptionLength);
+BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
+ DWORD dwUserLength);
+
+DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount);
+DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount);
+LPSTR __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName);
+LPWSTR __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName);
+
+
+#endif /* _PRIVATE_H_INCLUDED_ */
Deleted: tags/jbosssvc/2.0.8/procrun/src/registry.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/registry.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/registry.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,1112 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-static LPCWSTR REGSERVICE_ROOT = L"SYSTEM\\CurrentControlSet\\Services\\";
-static LPCWSTR REGSOFTWARE_ROOT = L"SOFTWARE\\";
-static LPCWSTR REGSERVICE_START = L"Start";
-static LPCWSTR REGSERVICE_USER = L"ObjectName";
-static LPCWSTR REGPARAMS = L"Parameters";
-static LPCWSTR REGDESCRIPTION = L"Description";
-static LPCWSTR REGSEPARATOR = L"\\";
-static LPCWSTR REGAPACHE_ROOT = L"Apache Software Foundation";
-/* predefined java keys */
-static LPCWSTR JRE_REGKEY = L"SOFTWARE\\JavaSoft\\Java Runtime Environment\\";
-static LPCWSTR JDK_REGKEY = L"SOFTWARE\\JavaSoft\\Java Development Kit\\";
-static LPCWSTR JAVA_CURRENT = L"CurrentVersion";
-static LPCWSTR JAVA_RUNTIME = L"RuntimeLib";
-static LPCWSTR JAVA_HOME = L"JAVA_HOME";
-static LPCWSTR JAVAHOME = L"JavaHome";
-static LPCWSTR CONTROL_REGKEY = L"SYSTEM\\CurrentControlSet\\Control";
-static LPCWSTR REGTIMEOUT = L"WaitToKillServiceTimeout";
-
-#define REG_CAN_CREATE(r) \
- ((r)->samOptions & KEY_CREATE_SUB_KEY)
-
-#define REG_CAN_WRITE(r) \
- ((r)->samOptions & KEY_SET_VALUE)
-
-
-#define REG_GET_KEY(r, w, k) \
- APXMACRO_BEGIN \
- switch(w) { \
- case APXREG_SOFTWARE: k = (r)->hRootKey; break; \
- case APXREG_PARAMSOFTWARE: k = (r)->hRparamKey; break; \
- case APXREG_SERVICE: k = (r)->hServKey; break; \
- case APXREG_PARAMSERVICE: k = (r)->hSparamKey; break; \
- case APXREG_USER: k = (r)->hUserKey; break; \
- case APXREG_PARAMUSER: k = (r)->hUparamKey; break; \
- default: k = NULL; break; \
- } APXMACRO_END
-
-
-typedef struct APXREGISTRY APXREGISTRY;
-typedef APXREGISTRY* LPAPXREGISTRY;
-typedef struct APXREGSUBKEY APXREGSUBKEY;
-
-struct APXREGSUBKEY {
- APXHANDLE hRegistry;
- HKEY hKey;
- LPCTSTR syKeyName;
- TAILQ_ENTRY(APXREGSUBKEY);
-};
-
-struct APXREGISTRY {
- HKEY hRootKey; /* root key */
- HKEY hServKey; /* service key */
- HKEY hUserKey; /* user key */
- HKEY hCurrKey; /* Current opened key */
- LPVOID pCurrVal; /* Current value, overwitten on a next call */
- HKEY hRparamKey; /* root\\Parameters */
- HKEY hSparamKey; /* service\\Parameters */
- HKEY hUparamKey; /* service\\Parameters */
- REGSAM samOptions;
- /** list enty for opened subkeys */
- TAILQ_HEAD(_lSubkeys, APXREGSUBKEY) lSubkeys;
-
-};
-
-#define SAFE_CLOSE_KEY(k) \
- if ((k) != NULL && (k) != INVALID_HANDLE_VALUE) { \
- RegCloseKey((k)); \
- (k) = NULL; \
- }
-
-static BOOL __apxRegistryCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- LPAPXREGISTRY lpReg;
-
- lpReg = APXHANDLE_DATA(hObject);
- switch (uMsg) {
- case WM_CLOSE:
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- SAFE_CLOSE_KEY(lpReg->hRparamKey);
- SAFE_CLOSE_KEY(lpReg->hSparamKey);
- SAFE_CLOSE_KEY(lpReg->hUparamKey);
- SAFE_CLOSE_KEY(lpReg->hRootKey);
- SAFE_CLOSE_KEY(lpReg->hServKey);
- SAFE_CLOSE_KEY(lpReg->hUserKey);
- break;
- default:
- break;
- }
- return TRUE;
-}
-
-LPSTR __apxGetRegistrySzA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName)
-{
- LPSTR szRet;
- DWORD rc;
- DWORD dwType;
- DWORD dwSize;
-
- rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
- if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
- return NULL;
- }
- if (!(szRet = apxPoolAlloc(hPool, dwSize)))
- return NULL;
- RegQueryValueExA(hKey, szValueName, NULL, &dwType, (LPBYTE)szRet, &dwSize);
-
- return szRet;
-}
-
-LPWSTR __apxGetRegistrySzW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
-{
- LPWSTR wsRet;
- DWORD rc;
- DWORD dwType;
- DWORD dwSize;
-
- rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
- if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
- return NULL;
- }
- if (!(wsRet = apxPoolAlloc(hPool, dwSize * sizeof(WCHAR))))
- return NULL;
- RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)wsRet, &dwSize);
-
- return wsRet;
-}
-
-BOOL __apxGetRegistryStrW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
- LPWSTR lpRetval, DWORD dwMaxLen)
-{
- DWORD rc;
- DWORD dwType;
- DWORD dwSize = dwMaxLen;
-
- rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)lpRetval, &dwSize);
- if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
- lpRetval = L'\0';
- return FALSE;
- }
- else
- return TRUE;
-}
-
-LPBYTE __apxGetRegistryBinaryA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName,
- LPDWORD lpdwLength)
-{
- LPBYTE lpRet;
- DWORD rc;
- DWORD dwType;
- DWORD dwSize;
-
- rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
- if (rc != ERROR_SUCCESS || dwSize == 0) {
- return NULL;
- }
- if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
- return NULL;
- RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpRet, &dwSize);
- if (lpdwLength)
- *lpdwLength = dwSize;
- return lpRet;
-}
-
-LPBYTE __apxGetRegistryBinaryW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
- LPDWORD lpdwLength)
-{
- LPBYTE lpRet;
- DWORD rc;
- DWORD dwType;
- DWORD dwSize;
-
- rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
- if (rc != ERROR_SUCCESS || dwSize == 0) {
- return NULL;
- }
- if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
- return NULL;
- RegQueryValueExW(hKey, wsValueName, NULL, &dwType, lpRet, &dwSize);
- if (lpdwLength)
- *lpdwLength = dwSize;
-
- return lpRet;
-}
-
-DWORD __apxGetRegistryDwordW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
-{
- DWORD dwRet;
- DWORD rc;
- DWORD dwType;
- DWORD dwSize = sizeof(DWORD);
-
- rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)&dwRet, &dwSize);
- if (rc != ERROR_SUCCESS || dwType != REG_DWORD) {
- return 0xFFFFFFFF;
- }
-
- return dwRet;
-}
-
-
-APXHANDLE
-apxCreateRegistryW(APXHANDLE hPool, REGSAM samDesired,
- LPCWSTR szRoot,
- LPCWSTR szKeyName,
- DWORD dwOptions)
-{
- APXHANDLE hRegistry;
- LPAPXREGISTRY lpReg;
- /* maximum key length is 512 characters. */
- WCHAR buff[SIZ_BUFLEN];
- LONG rc = ERROR_SUCCESS;
- HKEY hRootKey = NULL;
- HKEY hUserKey = NULL;
- HKEY hServKey = NULL;
- HKEY hRparamKey = NULL;
- HKEY hSparamKey = NULL;
- HKEY hUparamKey = NULL;
-
- if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
- return NULL;
- if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
- return NULL;
-
- /* make the HKLM\\SOFTWARE key */
- lstrcpyW(buff, REGSOFTWARE_ROOT);
- if (szRoot)
- lstrcatW(buff, szRoot);
- else
- lstrcatW(buff, REGAPACHE_ROOT);
- lstrcatW(buff, REGSEPARATOR);
- lstrcatW(buff, szKeyName);
- /* Open or create the root key */
- if (dwOptions & APXREG_SOFTWARE) {
- if (samDesired & KEY_CREATE_SUB_KEY)
- rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, buff, 0, NULL, 0,
- samDesired, NULL,
- &hRootKey, NULL);
- else
- rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
- samDesired, &hRootKey);
- if (rc != ERROR_SUCCESS) {
- hRootKey = NULL;
- goto cleanup;
- }
- /* Open or create the root parameters key */
- if (samDesired & KEY_CREATE_SUB_KEY)
- rc = RegCreateKeyExW(hRootKey, REGPARAMS, 0, NULL, 0,
- samDesired, NULL,
- &hRparamKey, NULL);
- else
- rc = RegOpenKeyExW(hRootKey, REGPARAMS, 0,
- samDesired, &hRparamKey);
- if (rc != ERROR_SUCCESS) {
- hRparamKey = NULL;
- goto cleanup;
- }
- }
-
- if (dwOptions & APXREG_USER) {
- /* Open or create the users root key */
- if (samDesired & KEY_CREATE_SUB_KEY)
- rc = RegCreateKeyExW(HKEY_CURRENT_USER, buff, 0, NULL, 0,
- samDesired, NULL,
- &hUserKey, NULL);
- else
- rc = RegOpenKeyExW(HKEY_CURRENT_USER, buff, 0,
- samDesired, &hUserKey);
- if (rc != ERROR_SUCCESS) {
- hUserKey = NULL;
- goto cleanup;
- }
- /* Open or create the users parameters key */
- if (samDesired & KEY_CREATE_SUB_KEY)
- rc = RegCreateKeyExW(hUserKey, REGPARAMS, 0, NULL, 0,
- samDesired, NULL,
- &hUparamKey, NULL);
- else
- rc = RegOpenKeyExW(hUserKey, REGPARAMS, 0,
- samDesired, &hUparamKey);
- if (rc != ERROR_SUCCESS) {
- hUparamKey = NULL;
- goto cleanup;
- }
- }
- /* Check if we need a service key */
- if (dwOptions & APXREG_SERVICE) {
- lstrcpyW(buff, REGSERVICE_ROOT);
- lstrcatW(buff, szKeyName);
- /* Service has to be created allready */
- rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
- samDesired, &hServKey);
- if (rc != ERROR_SUCCESS) {
- hServKey = NULL;
- goto cleanup;
- }
- /* Open or create the root parameters key */
- if (samDesired & KEY_CREATE_SUB_KEY)
- rc = RegCreateKeyExW(hServKey, REGPARAMS, 0, NULL, 0,
- samDesired, NULL,
- &hSparamKey, NULL);
- else
- rc = RegOpenKeyExW(hServKey, REGPARAMS, 0,
- samDesired, &hSparamKey);
- if (rc != ERROR_SUCCESS) {
- hSparamKey = NULL;
- goto cleanup;
- }
- }
- hRegistry = apxHandleCreate(hPool, 0,
- NULL, sizeof(APXREGISTRY),
- __apxRegistryCallback);
- if (IS_INVALID_HANDLE(hRegistry))
- return NULL;
- hRegistry->dwType = APXHANDLE_TYPE_REGISTRY;
- lpReg = APXHANDLE_DATA(hRegistry);
- lpReg->samOptions = samDesired;
- lpReg->hRootKey = hRootKey;
- lpReg->hUserKey = hUserKey;
- lpReg->hServKey = hServKey;
- lpReg->hRparamKey = hRparamKey;
- lpReg->hUparamKey = hUparamKey;
- lpReg->hSparamKey = hSparamKey;
- TAILQ_INIT(&lpReg->lSubkeys);
-
- SetLastError(rc);
- return hRegistry;
-
-cleanup:
- SAFE_CLOSE_KEY(hRparamKey);
- SAFE_CLOSE_KEY(hSparamKey);
- SAFE_CLOSE_KEY(hUparamKey);
- SAFE_CLOSE_KEY(hRootKey);
- SAFE_CLOSE_KEY(hServKey);
- SAFE_CLOSE_KEY(hUserKey);
-
- SetLastError(rc);
- return NULL;
-}
-
-APXHANDLE
-apxCreateRegistryA(APXHANDLE hPool, REGSAM samDesired,
- LPCSTR szRoot,
- LPCSTR szKeyName,
- DWORD dwOptions)
-{
- WCHAR wcRoot[SIZ_RESLEN];
- WCHAR wcKey[SIZ_RESLEN];
- LPWSTR wsRoot = NULL;
- if (szRoot) {
- AsciiToWide(szRoot, wcRoot);
- wsRoot = wcRoot;
- }
- AsciiToWide(szKeyName, wcKey);
- return apxCreateRegistryW(hPool, samDesired, wsRoot, wcKey, dwOptions);
-}
-
-LPSTR
-apxRegistryGetStringA(APXHANDLE hRegistry, DWORD dwFrom,
- LPCSTR szSubkey, LPCSTR szValueName)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return NULL;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return NULL;
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegOpenKeyExA(hKey, szSubkey, 0,
- lpReg->samOptions, &hSub) != ERROR_SUCCESS)
- return NULL;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- lpReg->pCurrVal = __apxGetRegistrySzA(hRegistry->hPool, hKey, szValueName);
-
- return lpReg->pCurrVal;
-}
-
-LPWSTR
-apxRegistryGetStringW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return NULL;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return NULL;
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegOpenKeyExW(hKey, szSubkey, 0,
- lpReg->samOptions, &hSub) != ERROR_SUCCESS)
- return NULL;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- lpReg->pCurrVal = __apxGetRegistrySzW(hRegistry->hPool, hKey, szValueName);
-
- return lpReg->pCurrVal;
-}
-
-LPBYTE
-apxRegistryGetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
- LPCSTR szSubkey, LPCSTR szValueName,
- LPBYTE lpData, LPDWORD lpdwLength)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return NULL;
- lpReg = APXHANDLE_DATA(hRegistry);
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return NULL;
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegOpenKeyExA(hKey, szSubkey, 0,
- lpReg->samOptions, &hSub) != ERROR_SUCCESS)
- return NULL;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (lpData && lpdwLength && *lpdwLength) {
- DWORD rc, dwType = REG_BINARY;
- rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
- if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
- ErrorMessage(NULL, FALSE);
- return NULL;
- }
- lpReg->pCurrVal = lpData;
- }
- else {
- lpReg->pCurrVal = __apxGetRegistryBinaryA(hRegistry->hPool, hKey, szValueName, lpdwLength);
- }
-
- return lpReg->pCurrVal;
-}
-
-LPBYTE
-apxRegistryGetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName,
- LPBYTE lpData, LPDWORD lpdwLength)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return NULL;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return NULL;
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegOpenKeyExW(hKey, szSubkey, 0,
- lpReg->samOptions, &hSub) != ERROR_SUCCESS)
- return NULL;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (lpData && lpdwLength && *lpdwLength) {
- DWORD rc, dwType = REG_BINARY;
- rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
- if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
- return NULL;
- }
- lpReg->pCurrVal = lpData;
- }
- else {
- lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
- }
- return lpReg->pCurrVal;
-}
-
-DWORD
-apxRegistryGetNumberW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwRval, rl;
- DWORD rc, dwType = REG_DWORD;
-
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return 0;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return 0;
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegOpenKeyExW(hKey, szSubkey, 0,
- lpReg->samOptions, &hSub) != ERROR_SUCCESS)
- return 0;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- rl = sizeof(DWORD);
- rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (LPBYTE)&dwRval, &rl);
- if (rc != ERROR_SUCCESS || dwType != REG_DWORD)
- return 0;
- else
- return dwRval;
-}
-
-LPWSTR
-apxRegistryGetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName,
- LPWSTR lpData, LPDWORD lpdwLength)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return NULL;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return NULL;
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegOpenKeyExW(hKey, szSubkey, 0,
- lpReg->samOptions, &hSub) != ERROR_SUCCESS)
- return NULL;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (lpData && lpdwLength && *lpdwLength) {
- DWORD rc, dwType = REG_MULTI_SZ;
- rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (BYTE *)lpData, lpdwLength);
- if (rc != ERROR_SUCCESS || dwType != REG_MULTI_SZ) {
- return NULL;
- }
- lpReg->pCurrVal = lpData;
- }
- else {
- lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
- if (lpReg->pCurrVal && lpdwLength)
- *lpdwLength = *lpdwLength * sizeof(WCHAR);
- }
- return lpReg->pCurrVal;
-}
-
-BOOL
-apxRegistrySetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
- LPCSTR szSubkey, LPCSTR szValueName,
- const LPBYTE lpData, DWORD dwLength)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwType = REG_BINARY;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return FALSE;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return FALSE;
-
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegCreateKeyExA(hKey, szSubkey, 0,
- NULL, 0, lpReg->samOptions,
- NULL, &hSub, NULL) != ERROR_SUCCESS)
- return FALSE;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (RegSetValueExA(hKey, szValueName, 0, dwType,
- lpData, dwLength) != ERROR_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-
-BOOL
-apxRegistrySetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName,
- const LPBYTE lpData, DWORD dwLength)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwType = REG_BINARY;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return FALSE;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return FALSE;
-
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegCreateKeyExW(hKey, szSubkey, 0,
- NULL, 0, lpReg->samOptions,
- NULL, &hSub, NULL) != ERROR_SUCCESS)
- return FALSE;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (RegSetValueExW(hKey, szValueName, 0, dwType,
- lpData, dwLength) != ERROR_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-
-BOOL
-apxRegistrySetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName,
- LPCWSTR lpData, DWORD dwLength)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwType = REG_MULTI_SZ;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return FALSE;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return FALSE;
-
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegCreateKeyExW(hKey, szSubkey, 0,
- NULL, 0, lpReg->samOptions,
- NULL, &hSub, NULL) != ERROR_SUCCESS)
- return FALSE;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (RegSetValueExW(hKey, szValueName, 0, dwType,
- (const BYTE *)lpData, dwLength) != ERROR_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-
-BOOL
-apxRegistrySetStrA(APXHANDLE hRegistry, DWORD dwFrom,
- LPCSTR szSubkey, LPCSTR szValueName,
- LPCSTR szValue)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwType = REG_SZ;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return FALSE;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return FALSE;
-
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegCreateKeyExA(hKey, szSubkey, 0,
- NULL, 0, lpReg->samOptions,
- NULL, &hSub, NULL) != ERROR_SUCCESS)
- return FALSE;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (!szValue || !lstrlenA(szValue)) {
- if (RegDeleteValueA(hKey, szValueName) != ERROR_SUCCESS)
- return FALSE;
- }
- else if (RegSetValueExA(hKey, szValueName, 0, dwType,
- (LPBYTE)szValue, lstrlenA(szValue)) != ERROR_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-
-BOOL
-apxRegistrySetStrW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName,
- LPCWSTR szValue)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwType = REG_SZ;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return FALSE;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return FALSE;
-
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegCreateKeyExW(hKey, szSubkey, 0,
- NULL, 0, lpReg->samOptions,
- NULL, &hSub, NULL) != ERROR_SUCCESS)
- return FALSE;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (!szValue || !lstrlenW(szValue)) {
- if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
- return FALSE;
- }
- else if (RegSetValueExW(hKey, szValueName, 0, dwType,
- (LPBYTE)szValue,
- lstrlenW(szValue) * sizeof(WCHAR)) != ERROR_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-
-BOOL
-apxRegistrySetNumW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName,
- DWORD dwValue)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwType = REG_DWORD;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return FALSE;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return FALSE;
-
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegCreateKeyExW(hKey, szSubkey, 0,
- NULL, 0, lpReg->samOptions,
- NULL, &hSub, NULL) != ERROR_SUCCESS)
- return FALSE;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (RegSetValueExW(hKey, szValueName, 0, dwType,
- (LPBYTE)&dwValue,
- sizeof(DWORD)) != ERROR_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-
-
-BOOL
-apxRegistryDeleteW(APXHANDLE hRegistry, DWORD dwFrom,
- LPCWSTR szSubkey, LPCWSTR szValueName)
-{
- LPAPXREGISTRY lpReg;
- HKEY hKey, hSub = NULL;
- DWORD dwType = REG_SZ;
- if (IS_INVALID_HANDLE(hRegistry) ||
- hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
- return FALSE;
- lpReg = APXHANDLE_DATA(hRegistry);
-
- REG_GET_KEY(lpReg, dwFrom, hKey);
- if (!hKey)
- return FALSE;
-
- if (szSubkey) {
- SAFE_CLOSE_KEY(lpReg->hCurrKey);
- if (RegOpenKeyExW(hKey, szSubkey, 0,
- lpReg->samOptions, &hSub) != ERROR_SUCCESS)
- return FALSE;
- lpReg->hCurrKey = hSub;
- hKey = hSub;
- }
- if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
- return FALSE;
-
- return TRUE;
-}
-
-
-BOOL
-apxDeleteRegistryW(LPCWSTR szRoot,
- LPCWSTR szKeyName,
- BOOL bDeleteEmpty)
-{
- WCHAR buff[SIZ_BUFLEN];
- BOOL rv;
-
- if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
- return FALSE;
- if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
- return FALSE;
-
- lstrcpyW(buff, REGSOFTWARE_ROOT);
- if (szRoot)
- lstrcatW(buff, szRoot);
- else
- lstrcatW(buff, REGAPACHE_ROOT);
- lstrcatW(buff, REGSEPARATOR);
- lstrcatW(buff, szKeyName);
-
- rv = SHDeleteKeyW(HKEY_LOCAL_MACHINE, buff);
- rv += SHDeleteKeyW(HKEY_CURRENT_USER, buff);
-
- if (bDeleteEmpty) {
- lstrcpyW(buff, REGSOFTWARE_ROOT);
- if (szRoot)
- lstrcatW(buff, szRoot);
- else
- lstrcatW(buff, REGAPACHE_ROOT);
-
- SHDeleteEmptyKeyW(HKEY_LOCAL_MACHINE, buff);
- SHDeleteEmptyKeyW(HKEY_CURRENT_USER, buff);
- }
- return rv;
-}
-
-BOOL
-apxDeleteRegistryA(LPCSTR szRoot,
- LPCSTR szKeyName,
- BOOL bDeleteEmpty)
-{
- WCHAR wcRoot[SIZ_RESLEN];
- WCHAR wcKey[SIZ_RESLEN];
- LPWSTR wsRoot = NULL;
- if (szRoot) {
- AsciiToWide(szRoot, wcRoot);
- wsRoot = wcRoot;
- }
- AsciiToWide(szKeyName, wcKey);
-
- return apxDeleteRegistryW(wsRoot, wcKey, bDeleteEmpty);
-}
-
-
-LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre)
-{
- LPWSTR wsJhome, off;
- DWORD err, dwLen;
- HKEY hKey;
- WCHAR wsBuf[SIZ_BUFLEN];
- WCHAR wsKey[SIZ_RESLEN];
-#if 1 /* XXX: Add that customizable using function call arg */
- if (!bPreferJre && (wsJhome = __apxGetEnvironmentVariableW(hPool, JAVA_HOME)))
- return wsJhome;
-#endif
- lstrcpyW(wsKey, JAVA_CURRENT);
- if (bPreferJre)
- lstrcpyW(wsBuf, JRE_REGKEY);
- else
- lstrcpyW(wsBuf, JDK_REGKEY);
- dwLen = lstrlenW(wsBuf);
- off = &wsBuf[dwLen];
- dwLen = SIZ_RESMAX;
- if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
- 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
- return NULL;
- }
- if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
- (LPBYTE)off,
- &dwLen)) != ERROR_SUCCESS) {
- RegCloseKey(hKey);
- return NULL;
- }
- RegCloseKey(hKey);
- if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
- 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
- return NULL;
- }
- wsJhome = __apxGetRegistrySzW(hPool, hKey, JAVAHOME);
- if (wsJhome)
- SetEnvironmentVariableW(JAVA_HOME, wsJhome);
- RegCloseKey(hKey);
-
- return wsJhome;
-}
-
-LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool)
-{
- LPWSTR wsRtlib, off;
- DWORD err, dwLen = SIZ_RESLEN;
- HKEY hKey;
- WCHAR wsBuf[SIZ_BUFLEN];
-
- lstrcpyW(wsBuf, JRE_REGKEY);
-
- dwLen = lstrlenW(wsBuf);
- off = &wsBuf[dwLen];
- dwLen = SIZ_RESLEN;
- if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
- 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
- return NULL;
- }
- if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
- (LPBYTE)off,
- &dwLen)) != ERROR_SUCCESS) {
- RegCloseKey(hKey);
- return NULL;
- }
- RegCloseKey(hKey);
- if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
- 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
- return NULL;
- }
- wsRtlib = __apxGetRegistrySzW(hPool, hKey, JAVA_RUNTIME);
- RegCloseKey(hKey);
-
- return wsRtlib;
-}
-
-/* Service Registry helper functions */
-
-BOOL apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry)
-{
- DWORD rc, dwLength = SIZ_RESLEN;
-
- if (IS_INVALID_HANDLE(lpEnum->hServicesKey)) {
- rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, REGSERVICE_ROOT, 0,
- KEY_READ, &(lpEnum->hServicesKey));
- if (rc != ERROR_SUCCESS) {
- return FALSE;
- }
- rc = RegQueryInfoKeyW(lpEnum->hServicesKey,
- NULL,
- NULL,
- NULL,
- &lpEnum->cSubKeys,
- &lpEnum->cbMaxSubKey,
- &lpEnum->cchMaxClass,
- &lpEnum->cValues,
- &lpEnum->cchMaxValue,
- &lpEnum->cbMaxValueData,
- NULL,
- NULL);
- /* TODO: add dynamic maxsubkey length */
- if (rc != ERROR_SUCCESS || lpEnum->cbMaxSubKey > SIZ_RESLEN) {
- SAFE_CLOSE_KEY(lpEnum->hServicesKey);
- return FALSE;
- }
- }
- if (lpEnum->dwIndex >= lpEnum->cSubKeys) {
- SAFE_CLOSE_KEY(lpEnum->hServicesKey);
- return FALSE;
- }
- rc = RegEnumKeyExW(lpEnum->hServicesKey,
- lpEnum->dwIndex++,
- lpEntry->szServiceName,
- &dwLength,
- NULL,
- NULL,
- NULL,
- NULL);
- if (rc != ERROR_SUCCESS) {
- SAFE_CLOSE_KEY(lpEnum->hServicesKey);
- return FALSE;
- }
- else {
- HKEY hKey;
- rc = RegOpenKeyExW(lpEnum->hServicesKey, lpEntry->szServiceName,
- 0, KEY_READ, &hKey);
- if (rc != ERROR_SUCCESS) {
- SAFE_CLOSE_KEY(lpEnum->hServicesKey);
- return FALSE;
- }
- __apxGetRegistryStrW(NULL, hKey, REGDESCRIPTION,
- lpEntry->szServiceDescription, SIZ_DESLEN);
- __apxGetRegistryStrW(NULL, hKey, REGSERVICE_USER,
- lpEntry->szObjectName, SIZ_RESLEN);
- lpEntry->dwStart = __apxGetRegistryDwordW(NULL, hKey, REGSERVICE_START);
- RegCloseKey(hKey);
-
- }
- return TRUE;
-}
-
-/* We could use the ChangeServiceConfig2 on WIN2K+
- * For now use the registry.
- */
-BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription)
-{
- HKEY hKey;
- WCHAR wcName[SIZ_RESLEN];
- DWORD rc;
-
- if (lstrlenW(szServiceName) > SIZ_RESMAX)
- return FALSE;
- lstrcpyW(wcName, REGSERVICE_ROOT);
- lstrcatW(wcName, szServiceName);
-
- rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_WRITE, &hKey);
- if (rc != ERROR_SUCCESS) {
- return FALSE;
- }
-
- rc = RegSetValueExW(hKey, REGDESCRIPTION, 0, REG_SZ, (CONST BYTE *)szDescription,
- lstrlenW(szDescription) * sizeof(WCHAR));
- SAFE_CLOSE_KEY(hKey);
-
- return rc = ERROR_SUCCESS;
-}
-
-BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
- DWORD dwDescriptionLength)
-{
- HKEY hKey;
- WCHAR wcName[SIZ_RESLEN];
- DWORD rc, l = dwDescriptionLength * sizeof(WCHAR);
- DWORD t = REG_SZ;
- if (lstrlenW(szServiceName) > SIZ_RESMAX)
- return FALSE;
- lstrcpyW(wcName, REGSERVICE_ROOT);
- lstrcatW(wcName, szServiceName);
-
- rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
- if (rc != ERROR_SUCCESS) {
- return FALSE;
- }
- rc = RegQueryValueExW(hKey, REGDESCRIPTION, NULL, &t, (BYTE *)szDescription,
- &l);
- SAFE_CLOSE_KEY(hKey);
- if (rc == ERROR_SUCCESS && t == REG_SZ)
- return TRUE;
- else
- return FALSE;
-}
-
-BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
- DWORD dwUserLength)
-{
- HKEY hKey;
- WCHAR wcName[SIZ_RESLEN];
- DWORD rc, l = dwUserLength * sizeof(WCHAR);
- DWORD t = REG_SZ;
- if (lstrlenW(szServiceName) > SIZ_RESMAX)
- return FALSE;
- lstrcpyW(wcName, REGSERVICE_ROOT);
- lstrcatW(wcName, szServiceName);
-
- rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
- if (rc != ERROR_SUCCESS) {
- return FALSE;
- }
- rc = RegQueryValueExW(hKey, REGSERVICE_USER, NULL, &t, (BYTE *)szUser,
- &l);
- SAFE_CLOSE_KEY(hKey);
- if (rc == ERROR_SUCCESS && t == REG_SZ)
- return TRUE;
- else
- return FALSE;
-}
-
-DWORD apxGetMaxServiceTimeout(APXHANDLE hPool)
-{
- DWORD maxTimeout = 20000;
- LPWSTR wsMaxTimeout;
- DWORD err;
- HKEY hKey;
- WCHAR wsBuf[SIZ_BUFLEN];
-
- lstrcpyW(wsBuf, CONTROL_REGKEY);
-
- if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
- 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
- return maxTimeout;
- }
- wsMaxTimeout = __apxGetRegistrySzW(hPool, hKey, REGTIMEOUT);
- RegCloseKey(hKey);
-
- if (wsMaxTimeout[0]) {
- maxTimeout = (DWORD)apxAtoulW(wsMaxTimeout);
- }
- apxFree(wsMaxTimeout);
-
- return maxTimeout;
-}
Copied: tags/jbosssvc/2.0.8/procrun/src/registry.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/registry.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/registry.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/registry.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,1160 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+static LPCWSTR REGSERVICE_ROOT = L"SYSTEM\\CurrentControlSet\\Services\\";
+static LPCWSTR REGSOFTWARE_ROOT = L"SOFTWARE\\";
+static LPCWSTR REGSERVICE_START = L"Start";
+static LPCWSTR REGSERVICE_USER = L"ObjectName";
+static LPCWSTR REGPARAMS = L"Parameters";
+static LPCWSTR REGDESCRIPTION = L"Description";
+static LPCWSTR REGSEPARATOR = L"\\";
+static LPCWSTR REGAPACHE_ROOT = L"Apache Software Foundation";
+/* predefined java keys */
+static LPCWSTR JRE_REGKEY = L"SOFTWARE\\JavaSoft\\Java Runtime Environment\\";
+static LPCWSTR JDK_REGKEY = L"SOFTWARE\\JavaSoft\\Java Development Kit\\";
+static LPCWSTR JAVA_CURRENT = L"CurrentVersion";
+static LPCWSTR JAVA_RUNTIME = L"RuntimeLib";
+static LPCWSTR JAVA_HOME = L"JAVA_HOME";
+static LPCWSTR JAVAHOME = L"JavaHome";
+static LPCWSTR CONTROL_REGKEY = L"SYSTEM\\CurrentControlSet\\Control";
+static LPCWSTR REGTIMEOUT = L"WaitToKillServiceTimeout";
+
+#define REG_CAN_CREATE(r) \
+ ((r)->samOptions & KEY_CREATE_SUB_KEY)
+
+#define REG_CAN_WRITE(r) \
+ ((r)->samOptions & KEY_SET_VALUE)
+
+
+#define REG_GET_KEY(r, w, k) \
+ APXMACRO_BEGIN \
+ switch(w) { \
+ case APXREG_SOFTWARE: k = (r)->hRootKey; break; \
+ case APXREG_PARAMSOFTWARE: k = (r)->hRparamKey; break; \
+ case APXREG_SERVICE: k = (r)->hServKey; break; \
+ case APXREG_PARAMSERVICE: k = (r)->hSparamKey; break; \
+ case APXREG_USER: k = (r)->hUserKey; break; \
+ case APXREG_PARAMUSER: k = (r)->hUparamKey; break; \
+ default: k = NULL; break; \
+ } APXMACRO_END
+
+
+typedef struct APXREGISTRY APXREGISTRY;
+typedef APXREGISTRY* LPAPXREGISTRY;
+typedef struct APXREGSUBKEY APXREGSUBKEY;
+
+struct APXREGSUBKEY {
+ APXHANDLE hRegistry;
+ HKEY hKey;
+ LPCTSTR syKeyName;
+ TAILQ_ENTRY(APXREGSUBKEY);
+};
+
+struct APXREGISTRY {
+ HKEY hRootKey; /* root key */
+ HKEY hServKey; /* service key */
+ HKEY hUserKey; /* user key */
+ HKEY hCurrKey; /* Current opened key */
+ LPVOID pCurrVal; /* Current value, overwitten on a next call */
+ HKEY hRparamKey; /* root\\Parameters */
+ HKEY hSparamKey; /* service\\Parameters */
+ HKEY hUparamKey; /* service\\Parameters */
+ REGSAM samOptions;
+ /** list enty for opened subkeys */
+ TAILQ_HEAD(_lSubkeys, APXREGSUBKEY) lSubkeys;
+
+};
+
+#define SAFE_CLOSE_KEY(k) \
+ if ((k) != NULL && (k) != INVALID_HANDLE_VALUE) { \
+ RegCloseKey((k)); \
+ (k) = NULL; \
+ }
+
+static BOOL __apxRegistryCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXREGISTRY lpReg;
+
+ lpReg = APXHANDLE_DATA(hObject);
+ switch (uMsg) {
+ case WM_CLOSE:
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ SAFE_CLOSE_KEY(lpReg->hRparamKey);
+ SAFE_CLOSE_KEY(lpReg->hSparamKey);
+ SAFE_CLOSE_KEY(lpReg->hUparamKey);
+ SAFE_CLOSE_KEY(lpReg->hRootKey);
+ SAFE_CLOSE_KEY(lpReg->hServKey);
+ SAFE_CLOSE_KEY(lpReg->hUserKey);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+LPSTR __apxGetRegistrySzA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName)
+{
+ LPSTR szRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+ return NULL;
+ }
+ if (!(szRet = apxPoolAlloc(hPool, dwSize)))
+ return NULL;
+ RegQueryValueExA(hKey, szValueName, NULL, &dwType, (LPBYTE)szRet, &dwSize);
+
+ return szRet;
+}
+
+LPWSTR __apxGetRegistrySzW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
+{
+ LPWSTR wsRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+ return NULL;
+ }
+ if (!(wsRet = apxPoolAlloc(hPool, dwSize * sizeof(WCHAR))))
+ return NULL;
+ RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)wsRet, &dwSize);
+
+ return wsRet;
+}
+
+BOOL __apxGetRegistryStrW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
+ LPWSTR lpRetval, DWORD dwMaxLen)
+{
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize = dwMaxLen;
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)lpRetval, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+ lpRetval = L'\0';
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+LPBYTE __apxGetRegistryBinaryA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName,
+ LPDWORD lpdwLength)
+{
+ LPBYTE lpRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwSize == 0) {
+ return NULL;
+ }
+ if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
+ return NULL;
+ RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpRet, &dwSize);
+ if (lpdwLength)
+ *lpdwLength = dwSize;
+ return lpRet;
+}
+
+LPBYTE __apxGetRegistryBinaryW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
+ LPDWORD lpdwLength)
+{
+ LPBYTE lpRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwSize == 0) {
+ return NULL;
+ }
+ if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
+ return NULL;
+ RegQueryValueExW(hKey, wsValueName, NULL, &dwType, lpRet, &dwSize);
+ if (lpdwLength)
+ *lpdwLength = dwSize;
+
+ return lpRet;
+}
+
+DWORD __apxGetRegistryDwordW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
+{
+ DWORD dwRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize = sizeof(DWORD);
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)&dwRet, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_DWORD) {
+ return 0xFFFFFFFF;
+ }
+
+ return dwRet;
+}
+
+
+APXHANDLE
+apxCreateRegistryW(APXHANDLE hPool, REGSAM samDesired,
+ LPCWSTR szRoot,
+ LPCWSTR szKeyName,
+ DWORD dwOptions)
+{
+ APXHANDLE hRegistry;
+ LPAPXREGISTRY lpReg;
+ /* maximum key length is 512 characters. */
+ WCHAR buff[SIZ_BUFLEN];
+ LONG rc = ERROR_SUCCESS;
+ HKEY hRootKey = NULL;
+ HKEY hUserKey = NULL;
+ HKEY hServKey = NULL;
+ HKEY hRparamKey = NULL;
+ HKEY hSparamKey = NULL;
+ HKEY hUparamKey = NULL;
+
+ if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
+ return NULL;
+ if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
+ return NULL;
+
+ /* make the HKLM\\SOFTWARE key */
+ lstrcpyW(buff, REGSOFTWARE_ROOT);
+ if (szRoot)
+ lstrcatW(buff, szRoot);
+ else
+ lstrcatW(buff, REGAPACHE_ROOT);
+ lstrcatW(buff, REGSEPARATOR);
+ lstrcatW(buff, szKeyName);
+ /* Open or create the root key */
+ if (dwOptions & APXREG_SOFTWARE) {
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, buff, 0, NULL, 0,
+ samDesired, NULL,
+ &hRootKey, NULL);
+ else
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
+ samDesired, &hRootKey);
+ if (rc != ERROR_SUCCESS) {
+ hRootKey = NULL;
+ goto cleanup;
+ }
+ /* Open or create the root parameters key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(hRootKey, REGPARAMS, 0, NULL, 0,
+ samDesired, NULL,
+ &hRparamKey, NULL);
+ else
+ rc = RegOpenKeyExW(hRootKey, REGPARAMS, 0,
+ samDesired, &hRparamKey);
+ if (rc != ERROR_SUCCESS) {
+ hRparamKey = NULL;
+ goto cleanup;
+ }
+ }
+
+ if (dwOptions & APXREG_USER) {
+ /* Open or create the users root key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(HKEY_CURRENT_USER, buff, 0, NULL, 0,
+ samDesired, NULL,
+ &hUserKey, NULL);
+ else
+ rc = RegOpenKeyExW(HKEY_CURRENT_USER, buff, 0,
+ samDesired, &hUserKey);
+ if (rc != ERROR_SUCCESS) {
+ hUserKey = NULL;
+ goto cleanup;
+ }
+ /* Open or create the users parameters key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(hUserKey, REGPARAMS, 0, NULL, 0,
+ samDesired, NULL,
+ &hUparamKey, NULL);
+ else
+ rc = RegOpenKeyExW(hUserKey, REGPARAMS, 0,
+ samDesired, &hUparamKey);
+ if (rc != ERROR_SUCCESS) {
+ hUparamKey = NULL;
+ goto cleanup;
+ }
+ }
+ /* Check if we need a service key */
+ if (dwOptions & APXREG_SERVICE) {
+ lstrcpyW(buff, REGSERVICE_ROOT);
+ lstrcatW(buff, szKeyName);
+ /* Service has to be created allready */
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
+ samDesired, &hServKey);
+ if (rc != ERROR_SUCCESS) {
+ hServKey = NULL;
+ goto cleanup;
+ }
+ /* Open or create the root parameters key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(hServKey, REGPARAMS, 0, NULL, 0,
+ samDesired, NULL,
+ &hSparamKey, NULL);
+ else
+ rc = RegOpenKeyExW(hServKey, REGPARAMS, 0,
+ samDesired, &hSparamKey);
+ if (rc != ERROR_SUCCESS) {
+ hSparamKey = NULL;
+ goto cleanup;
+ }
+ }
+ hRegistry = apxHandleCreate(hPool, 0,
+ NULL, sizeof(APXREGISTRY),
+ __apxRegistryCallback);
+ if (IS_INVALID_HANDLE(hRegistry))
+ return NULL;
+ hRegistry->dwType = APXHANDLE_TYPE_REGISTRY;
+ lpReg = APXHANDLE_DATA(hRegistry);
+ lpReg->samOptions = samDesired;
+ lpReg->hRootKey = hRootKey;
+ lpReg->hUserKey = hUserKey;
+ lpReg->hServKey = hServKey;
+ lpReg->hRparamKey = hRparamKey;
+ lpReg->hUparamKey = hUparamKey;
+ lpReg->hSparamKey = hSparamKey;
+ TAILQ_INIT(&lpReg->lSubkeys);
+
+ SetLastError(rc);
+ return hRegistry;
+
+cleanup:
+ SAFE_CLOSE_KEY(hRparamKey);
+ SAFE_CLOSE_KEY(hSparamKey);
+ SAFE_CLOSE_KEY(hUparamKey);
+ SAFE_CLOSE_KEY(hRootKey);
+ SAFE_CLOSE_KEY(hServKey);
+ SAFE_CLOSE_KEY(hUserKey);
+
+ SetLastError(rc);
+ return NULL;
+}
+
+APXHANDLE
+apxCreateRegistryA(APXHANDLE hPool, REGSAM samDesired,
+ LPCSTR szRoot,
+ LPCSTR szKeyName,
+ DWORD dwOptions)
+{
+ WCHAR wcRoot[SIZ_RESLEN];
+ WCHAR wcKey[SIZ_RESLEN];
+ LPWSTR wsRoot = NULL;
+ if (szRoot) {
+ AsciiToWide(szRoot, wcRoot);
+ wsRoot = wcRoot;
+ }
+ AsciiToWide(szKeyName, wcKey);
+ return apxCreateRegistryW(hPool, samDesired, wsRoot, wcKey, dwOptions);
+}
+
+LPSTR
+apxRegistryGetStringA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExA(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ lpReg->pCurrVal = __apxGetRegistrySzA(hRegistry->hPool, hKey, szValueName);
+
+ return lpReg->pCurrVal;
+}
+
+LPWSTR
+apxRegistryGetStringW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ lpReg->pCurrVal = __apxGetRegistrySzW(hRegistry->hPool, hKey, szValueName);
+
+ return lpReg->pCurrVal;
+}
+
+LPBYTE
+apxRegistryGetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ LPBYTE lpData, LPDWORD lpdwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExA(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (lpData && lpdwLength && *lpdwLength) {
+ DWORD rc, dwType = REG_BINARY;
+ rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
+ if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+ lpReg->pCurrVal = lpData;
+ }
+ else {
+ lpReg->pCurrVal = __apxGetRegistryBinaryA(hRegistry->hPool, hKey, szValueName, lpdwLength);
+ }
+
+ return lpReg->pCurrVal;
+}
+
+LPBYTE
+apxRegistryGetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPBYTE lpData, LPDWORD lpdwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (lpData && lpdwLength && *lpdwLength) {
+ DWORD rc, dwType = REG_BINARY;
+ rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
+ if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
+ return NULL;
+ }
+ lpReg->pCurrVal = lpData;
+ }
+ else {
+ lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
+ }
+ return lpReg->pCurrVal;
+}
+
+DWORD
+apxRegistryGetNumberW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwRval, rl;
+ DWORD rc, dwType = REG_DWORD;
+
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return 0;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return 0;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return 0;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ rl = sizeof(DWORD);
+ rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (LPBYTE)&dwRval, &rl);
+ if (rc != ERROR_SUCCESS || dwType != REG_DWORD)
+ return 0;
+ else
+ return dwRval;
+}
+
+LPWSTR
+apxRegistryGetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPWSTR lpData, LPDWORD lpdwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (lpData && lpdwLength && *lpdwLength) {
+ DWORD rc, dwType = REG_MULTI_SZ;
+ rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (BYTE *)lpData, lpdwLength);
+ if (rc != ERROR_SUCCESS || dwType != REG_MULTI_SZ) {
+ return NULL;
+ }
+ lpReg->pCurrVal = lpData;
+ }
+ else {
+ lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
+ if (lpReg->pCurrVal && lpdwLength)
+ *lpdwLength = *lpdwLength * sizeof(WCHAR);
+ }
+ return lpReg->pCurrVal;
+}
+
+BOOL
+apxRegistrySetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ const LPBYTE lpData, DWORD dwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_BINARY;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExA(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExA(hKey, szValueName, 0, dwType,
+ lpData, dwLength) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ const LPBYTE lpData, DWORD dwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_BINARY;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ lpData, dwLength) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPCWSTR lpData, DWORD dwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_MULTI_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ (const BYTE *)lpData, dwLength) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetStrA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ LPCSTR szValue)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExA(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (!szValue || !lstrlenA(szValue)) {
+ if (RegDeleteValueA(hKey, szValueName) != ERROR_SUCCESS)
+ return FALSE;
+ }
+ else if (RegSetValueExA(hKey, szValueName, 0, dwType,
+ (LPBYTE)szValue, lstrlenA(szValue) + 1) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPCWSTR szValue)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (!szValue || !lstrlenW(szValue)) {
+ if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
+ return FALSE;
+ }
+ else if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ (LPBYTE)szValue,
+ (lstrlenW(szValue) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetNumW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ DWORD dwValue)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_DWORD;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ (LPBYTE)&dwValue,
+ sizeof(DWORD)) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+
+BOOL
+apxRegistryDeleteW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+
+LONG apxDeleteRegistryRecursive(HKEY hKeyRoot, LPCWSTR szSubKey) {
+ LONG rc = ERROR_SUCCESS;
+ DWORD dwSize = 0;
+ WCHAR szName[SIZ_BUFLEN];
+ HKEY hKey = NULL;
+
+ if (ERROR_SUCCESS == RegDeleteKey(hKeyRoot, szSubKey)) {
+ return ERROR_SUCCESS;
+ }
+
+ rc = RegOpenKeyExW(hKeyRoot, szSubKey, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ if (rc == ERROR_FILE_NOT_FOUND) {
+ return ERROR_SUCCESS;
+ } else {
+ return rc;
+ }
+ }
+ while (rc == ERROR_SUCCESS) {
+ dwSize = SIZ_BUFLEN;
+ rc = RegEnumKeyExW(hKey, 0, szName, &dwSize, NULL, NULL, NULL, NULL );
+
+ if (rc == ERROR_NO_MORE_ITEMS) {
+ rc = RegDeleteKeyW(hKeyRoot, szSubKey);
+ break;
+ } else {
+ rc = apxDeleteRegistryRecursive(hKey, szName);
+ if (rc != ERROR_SUCCESS) {
+ break; // abort when we start failing
+ }
+ }
+ }
+ RegCloseKey(hKey);
+ return rc;
+}
+
+
+BOOL
+apxDeleteRegistryW(LPCWSTR szRoot,
+ LPCWSTR szKeyName,
+ REGSAM samDesired,
+ BOOL bDeleteEmptyRoot)
+{
+ WCHAR buff[SIZ_BUFLEN];
+ LONG rc = ERROR_SUCCESS;
+ HKEY hKey = NULL;
+ BOOL rv = TRUE;
+ HKEY hives[] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER, NULL}, *hive = NULL;
+
+ if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
+ return FALSE;
+ if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
+ return FALSE;
+
+ if (szRoot)
+ lstrcpyW(buff, szRoot);
+ else
+ lstrcpyW(buff, REGAPACHE_ROOT);
+ lstrcatW(buff, REGSEPARATOR);
+
+ for (hive = &hives[0]; *hive; hive++) {
+ HKEY hkeySoftware = NULL;
+
+ rc = RegOpenKeyExW(*hive, REGSOFTWARE_ROOT, 0, KEY_READ | samDesired, &hkeySoftware);
+ if (rc != ERROR_SUCCESS) {
+ rv = FALSE;
+ } else {
+ rc = RegOpenKeyExW(hkeySoftware, buff, 0, samDesired | KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey);
+ if (rc == ERROR_SUCCESS) {
+ rc = apxDeleteRegistryRecursive(hKey, szKeyName);
+ RegCloseKey(hKey);
+ hKey = NULL;
+ rv |= (rc == ERROR_SUCCESS);
+ }
+ if (bDeleteEmptyRoot) {
+ // will fail if there are subkeys, just like we want
+ RegDeleteKeyW(hkeySoftware, buff);
+ }
+ RegCloseKey(hkeySoftware);
+ }
+ }
+ return rv;
+}
+
+BOOL
+apxDeleteRegistryA(LPCSTR szRoot,
+ LPCSTR szKeyName,
+ REGSAM samDesired,
+ BOOL bDeleteEmptyRoot)
+{
+ WCHAR wcRoot[SIZ_RESLEN];
+ WCHAR wcKey[SIZ_RESLEN];
+ LPWSTR wsRoot = NULL;
+ if (szRoot) {
+ AsciiToWide(szRoot, wcRoot);
+ wsRoot = wcRoot;
+ }
+ AsciiToWide(szKeyName, wcKey);
+
+ return apxDeleteRegistryW(wsRoot, wcKey, samDesired, bDeleteEmptyRoot);
+}
+
+
+LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre)
+{
+ LPWSTR wsJhome, off;
+ DWORD err, dwLen;
+ HKEY hKey;
+ WCHAR wsBuf[SIZ_BUFLEN];
+ WCHAR wsKey[SIZ_RESLEN];
+#if 1 /* XXX: Add that customizable using function call arg */
+ if (!bPreferJre && (wsJhome = __apxGetEnvironmentVariableW(hPool, JAVA_HOME)))
+ return wsJhome;
+#endif
+ lstrcpyW(wsKey, JAVA_CURRENT);
+ if (bPreferJre)
+ lstrcpyW(wsBuf, JRE_REGKEY);
+ else
+ lstrcpyW(wsBuf, JDK_REGKEY);
+ dwLen = lstrlenW(wsBuf);
+ off = &wsBuf[dwLen];
+ dwLen = SIZ_RESMAX;
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
+ (LPBYTE)off,
+ &dwLen)) != ERROR_SUCCESS) {
+ RegCloseKey(hKey);
+ return NULL;
+ }
+ RegCloseKey(hKey);
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ wsJhome = __apxGetRegistrySzW(hPool, hKey, JAVAHOME);
+ if (wsJhome)
+ SetEnvironmentVariableW(JAVA_HOME, wsJhome);
+ RegCloseKey(hKey);
+
+ return wsJhome;
+}
+
+LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool)
+{
+ LPWSTR wsRtlib, off;
+ DWORD err, dwLen = SIZ_RESLEN;
+ HKEY hKey;
+ WCHAR wsBuf[SIZ_BUFLEN];
+
+ lstrcpyW(wsBuf, JRE_REGKEY);
+
+ dwLen = lstrlenW(wsBuf);
+ off = &wsBuf[dwLen];
+ dwLen = SIZ_RESLEN;
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
+ (LPBYTE)off,
+ &dwLen)) != ERROR_SUCCESS) {
+ RegCloseKey(hKey);
+ return NULL;
+ }
+ RegCloseKey(hKey);
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ wsRtlib = __apxGetRegistrySzW(hPool, hKey, JAVA_RUNTIME);
+ RegCloseKey(hKey);
+
+ return wsRtlib;
+}
+
+/* Service Registry helper functions */
+
+BOOL apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry)
+{
+ DWORD rc, dwLength = SIZ_RESLEN;
+
+ if (IS_INVALID_HANDLE(lpEnum->hServicesKey)) {
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, REGSERVICE_ROOT, 0,
+ KEY_READ, &(lpEnum->hServicesKey));
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+ rc = RegQueryInfoKeyW(lpEnum->hServicesKey,
+ NULL,
+ NULL,
+ NULL,
+ &lpEnum->cSubKeys,
+ &lpEnum->cbMaxSubKey,
+ &lpEnum->cchMaxClass,
+ &lpEnum->cValues,
+ &lpEnum->cchMaxValue,
+ &lpEnum->cbMaxValueData,
+ NULL,
+ NULL);
+ /* TODO: add dynamic maxsubkey length */
+ if (rc != ERROR_SUCCESS || lpEnum->cbMaxSubKey > SIZ_RESLEN) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ }
+ if (lpEnum->dwIndex >= lpEnum->cSubKeys) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ rc = RegEnumKeyExW(lpEnum->hServicesKey,
+ lpEnum->dwIndex++,
+ lpEntry->szServiceName,
+ &dwLength,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ if (rc != ERROR_SUCCESS) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ else {
+ HKEY hKey;
+ rc = RegOpenKeyExW(lpEnum->hServicesKey, lpEntry->szServiceName,
+ 0, KEY_READ, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ __apxGetRegistryStrW(NULL, hKey, REGDESCRIPTION,
+ lpEntry->szServiceDescription, SIZ_DESLEN);
+ __apxGetRegistryStrW(NULL, hKey, REGSERVICE_USER,
+ lpEntry->szObjectName, SIZ_RESLEN);
+ lpEntry->dwStart = __apxGetRegistryDwordW(NULL, hKey, REGSERVICE_START);
+ RegCloseKey(hKey);
+
+ }
+ return TRUE;
+}
+
+/* We could use the ChangeServiceConfig2 on WIN2K+
+ * For now use the registry.
+ */
+BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription)
+{
+ HKEY hKey;
+ WCHAR wcName[SIZ_RESLEN];
+ DWORD rc;
+
+ if (lstrlenW(szServiceName) > SIZ_RESMAX)
+ return FALSE;
+ lstrcpyW(wcName, REGSERVICE_ROOT);
+ lstrcatW(wcName, szServiceName);
+
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_WRITE, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ rc = RegSetValueExW(hKey, REGDESCRIPTION, 0, REG_SZ, (CONST BYTE *)szDescription,
+ (lstrlenW(szDescription) + 1) * sizeof(WCHAR));
+ SAFE_CLOSE_KEY(hKey);
+
+ return rc == ERROR_SUCCESS;
+}
+
+BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
+ DWORD dwDescriptionLength)
+{
+ HKEY hKey;
+ WCHAR wcName[SIZ_RESLEN];
+ DWORD rc, l = dwDescriptionLength * sizeof(WCHAR);
+ DWORD t = REG_SZ;
+ if (lstrlenW(szServiceName) > SIZ_RESMAX)
+ return FALSE;
+ lstrcpyW(wcName, REGSERVICE_ROOT);
+ lstrcatW(wcName, szServiceName);
+
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+ rc = RegQueryValueExW(hKey, REGDESCRIPTION, NULL, &t, (BYTE *)szDescription,
+ &l);
+ SAFE_CLOSE_KEY(hKey);
+ if (rc == ERROR_SUCCESS && t == REG_SZ)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
+ DWORD dwUserLength)
+{
+ HKEY hKey;
+ WCHAR wcName[SIZ_RESLEN];
+ DWORD rc, l = dwUserLength * sizeof(WCHAR);
+ DWORD t = REG_SZ;
+ if (lstrlenW(szServiceName) > SIZ_RESMAX)
+ return FALSE;
+ lstrcpyW(wcName, REGSERVICE_ROOT);
+ lstrcatW(wcName, szServiceName);
+
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+ rc = RegQueryValueExW(hKey, REGSERVICE_USER, NULL, &t, (BYTE *)szUser,
+ &l);
+ SAFE_CLOSE_KEY(hKey);
+ if (rc == ERROR_SUCCESS && t == REG_SZ)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+DWORD apxGetMaxServiceTimeout(APXHANDLE hPool)
+{
+ DWORD maxTimeout = 20000;
+ LPWSTR wsMaxTimeout;
+ DWORD err;
+ HKEY hKey;
+ WCHAR wsBuf[SIZ_BUFLEN];
+
+ lstrcpyW(wsBuf, CONTROL_REGKEY);
+
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return maxTimeout;
+ }
+ wsMaxTimeout = __apxGetRegistrySzW(hPool, hKey, REGTIMEOUT);
+ RegCloseKey(hKey);
+
+ if (wsMaxTimeout[0]) {
+ maxTimeout = (DWORD)apxAtoulW(wsMaxTimeout);
+ }
+ apxFree(wsMaxTimeout);
+
+ return maxTimeout;
+}
Deleted: tags/jbosssvc/2.0.8/procrun/src/rprocess.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/rprocess.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/rprocess.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,939 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-#define CHILD_RUNNING 0x0001
-#define CHILD_INITIALIZED 0x0002
-#define CHILD_MAINTREAD_FINISHED 0x0004
-#define PROC_INITIALIZED 0x0008
-#define CHILD_TERMINATE_CODE 19640323 /* Could be any value like my birthday ;-)*/
-
-DYNOLAD_TYPE_DECLARE(CreateRemoteThread,
- __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES,
- DWORD, LPTHREAD_START_ROUTINE,
- LPVOID, DWORD, LPDWORD);
-
-DYNOLAD_TYPE_DECLARE(ExitProcess, __stdcall, void)(UINT);
-
-#define CHECK_IF_ACTIVE(proc) \
- APXMACRO_BEGIN \
- DWORD __st; \
- if (!GetExitCodeProcess((proc)->stProcInfo.hProcess, &__st) || \
- (__st != STILL_ACTIVE)) \
- goto cleanup; \
- APXMACRO_END
-
-#define SAVE_STD_HANDLES(p) \
- APXMACRO_BEGIN \
- if ((p)->bSaveHandles) { \
- (p)->hParentStdSave[0] = GetStdHandle(STD_INPUT_HANDLE); \
- (p)->hParentStdSave[1] = GetStdHandle(STD_OUTPUT_HANDLE); \
- (p)->hParentStdSave[2] = GetStdHandle(STD_ERROR_HANDLE); \
- } APXMACRO_END
-
-#define RESTORE_STD_HANDLES(p) \
- APXMACRO_BEGIN \
- if ((p)->bSaveHandles) { \
- SetStdHandle(STD_INPUT_HANDLE, (p)->hParentStdSave[0]); \
- SetStdHandle(STD_OUTPUT_HANDLE, (p)->hParentStdSave[1]); \
- SetStdHandle(STD_ERROR_HANDLE, (p)->hParentStdSave[2]); \
- } APXMACRO_END
-
-#define REDIRECT_STD_HANDLES(p) \
- APXMACRO_BEGIN \
- if ((p)->bSaveHandles) { \
- SetStdHandle(STD_INPUT_HANDLE, (p)->hChildStdInp); \
- SetStdHandle(STD_OUTPUT_HANDLE, (p)->hChildStdOut); \
- SetStdHandle(STD_ERROR_HANDLE, (p)->hChildStdErr); \
- } APXMACRO_END
-
-typedef struct APXPROCESS {
- DWORD dwChildStatus;
- DWORD dwOptions;
- PROCESS_INFORMATION stProcInfo;
- /* Size of chars for ANSI/Unicode programs */
- DWORD chSize;
- /* application working path */
- LPWSTR szWorkingPath;
- /* executable name */
- LPWSTR szApplicationExec;
- /* command line (first arg is program name for argv[0]) */
- LPWSTR szCommandLine;
- LPWSTR lpEnvironment;
- /* set of child inherited pipes */
- HANDLE hChildStdInp;
- HANDLE hChildStdOut;
- HANDLE hChildStdErr;
- /* parent ends of child pipes */
- HANDLE hChildInpWr;
- HANDLE hChildOutRd;
- HANDLE hChildErrRd;
- /* Saved console pipes */
- HANDLE hParentStdSave[3];
- HANDLE hWorkerThreads[3];
- HANDLE hUserToken;
- HANDLE hCurrentProcess;
- BOOL bSaveHandles;
- /** callback function */
- LPAPXFNCALLBACK fnUserCallback;
- LPSECURITY_ATTRIBUTES lpSA;
- LPVOID lpSD;
- BYTE bSD[SECURITY_DESCRIPTOR_MIN_LENGTH];
- BYTE bSA[sizeof(SECURITY_ATTRIBUTES)];
-
-} APXPROCESS, *LPAPXPROCESS;
-
-/** Process worker thread
- * Monitors the process thread
- */
-static DWORD WINAPI __apxProcWorkerThread(LPVOID lpParameter)
-{
- APXHANDLE hProcess = (APXHANDLE)lpParameter;
- LPAPXPROCESS lpProc;
- DWORD dwExitCode = 0;
-
- lpProc = APXHANDLE_DATA(hProcess);
- /* Wait util a process has finished its initialization.
- */
- WaitForInputIdle(lpProc->stProcInfo.hProcess, INFINITE);
- lpProc->dwChildStatus |= CHILD_INITIALIZED;
- /* Wait until the child process exits */
- if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
- INFINITE) == WAIT_OBJECT_0) {
- lpProc->dwChildStatus |= CHILD_MAINTREAD_FINISHED;
-#if 0
- if (hProcess->fnCallback)
- (*hProcess->fnCallback)(hProcess, WM_QUIT, (WPARAM)dwExitCode, 0);
- lpProc->dwChildStatus &= ~CHILD_RUNNING;
- GetExitCodeProcess(lpProc->stProcInfo.hProcess, &dwExitCode);
-
- /* Close that handle */
-#endif
- }
- ExitThread(0);
- return 0;
-}
-
-static DWORD WINAPI __apxProcStdoutThread(LPVOID lpParameter)
-{
- APXHANDLE hProcess = (APXHANDLE)lpParameter;
- LPAPXPROCESS lpProc;
- APXCALLHOOK *lpCall;
- INT ch;
- DWORD dwReaded;
- lpProc = APXHANDLE_DATA(hProcess);
- while (lpProc->dwChildStatus & CHILD_RUNNING) {
- ch = 0;
- if (!ReadFile(lpProc->hChildOutRd, &ch, lpProc->chSize,
- &dwReaded, NULL) || !dwReaded) {
-
- break;
- }
- if (lpProc->fnUserCallback)
- (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
- TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
- (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
- }
- dwReaded = 0;
- SwitchToThread();
- }
- ExitThread(0);
- return 0;
-}
-
-static DWORD WINAPI __apxProcStderrThread(LPVOID lpParameter)
-{
- APXHANDLE hProcess = (APXHANDLE)lpParameter;
- LPAPXPROCESS lpProc;
- APXCALLHOOK *lpCall;
- INT ch;
- DWORD dwReaded;
- lpProc = APXHANDLE_DATA(hProcess);
- while (lpProc->dwChildStatus & CHILD_RUNNING) {
- if (!ReadFile(lpProc->hChildErrRd, &ch, lpProc->chSize,
- &dwReaded, NULL) || !dwReaded) {
-
- break;
- }
- if (lpProc->fnUserCallback)
- (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
- TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
- (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
- }
-
- dwReaded = 0;
- SwitchToThread();
- }
-
- ExitThread(0);
- return 0;
-}
-
-static DWORD __apxProcessPutc(LPAPXPROCESS lpProc, INT ch, DWORD dwSize)
-{
- if (lpProc->dwChildStatus & CHILD_RUNNING) {
- DWORD wr = 0;
- if (WriteFile(lpProc->hChildInpWr, &ch, dwSize, &wr, NULL) &&
- wr == dwSize) {
- return 1;
- }
- }
-
- return 0;
-}
-
-static DWORD __apxProcessPuts(LPAPXPROCESS lpProc, LPCTSTR szString)
-{
- DWORD l, n = 0;
- l = lstrlen(szString) * lpProc->chSize;
- if (lpProc->dwChildStatus & CHILD_RUNNING && l) {
- DWORD wr = 0;
- while (TRUE) {
- if (WriteFile(lpProc->hChildInpWr, szString, l,
- &wr, NULL)) {
- n += wr;
- if (wr < l) {
- l -= wr;
- szString += wr;
- }
- else {
- /* Flush the buffer */
- FlushFileBuffers(lpProc->hChildInpWr);
- break;
- }
- }
- else
- break;
- }
- }
-
- return n;
-}
-
-static DWORD __apxProcessWrite(LPAPXPROCESS lpProc, LPCVOID lpData, DWORD dwLen)
-{
- LPBYTE buf = (LPBYTE)lpData;
- DWORD n = 0;
- if (!lpData || !dwLen)
- return 0;
-
- if (lpProc->dwChildStatus & CHILD_RUNNING) {
- DWORD wr = 0;
- while (lpProc->dwChildStatus & CHILD_RUNNING) {
- if (WriteFile(lpProc->hChildInpWr, buf, dwLen,
- &wr, NULL)) {
- n += wr;
- if (wr < dwLen) {
- dwLen -= wr;
- buf += wr;
- }
- else
- break;
- }
- else
- break;
- }
- }
-
- return n;
-}
-
-/** Helper functions */
-static BOOL __apxProcCreateChildPipes(LPAPXPROCESS lpProc)
-{
- BOOL rv = FALSE;
-
- if (!CreatePipe(&(lpProc->hChildStdInp),
- &(lpProc->hChildInpWr),
- lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
- goto cleanup;
- }
- if (!SetHandleInformation(lpProc->hChildInpWr,
- HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
- goto cleanup;
- }
-
- if (!CreatePipe(&(lpProc->hChildOutRd),
- &(lpProc->hChildStdOut),
- lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
- goto cleanup;
- }
-
- if (!SetHandleInformation(lpProc->hChildOutRd,
- HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
- goto cleanup;
- }
-
- if (!CreatePipe(&(lpProc->hChildErrRd),
- &(lpProc->hChildStdErr),
- lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
- goto cleanup;
- }
-
- if (!SetHandleInformation(lpProc->hChildErrRd,
- HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
- goto cleanup;
- }
- rv = TRUE;
-cleanup:
-
- return rv;
-}
-
-/* Close the process.
- * Create the remote thread and call the ExitProcess
- * Terminate the process, if all of the above fails.
- */
-static BOOL __apxProcessClose(APXHANDLE hProcess)
-{
- LPAPXPROCESS lpProc;
- DYNLOAD_FPTR_DECLARE(CreateRemoteThread);
- DYNLOAD_FPTR_DECLARE(ExitProcess);
-
- UINT uExitCode = CHILD_TERMINATE_CODE; /* Could be any value like my birthday ;-)*/
- HANDLE hDup, hRemote;
-
- lpProc = APXHANDLE_DATA(hProcess);
- CHECK_IF_ACTIVE(lpProc);
-
- /* Try to close the child's stdin first */
- SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
- /* Wait 1 sec for child process to
- * recognize that the stdin has been closed.
- */
- if (WaitForSingleObject(lpProc->stProcInfo.hProcess, 1000) == WAIT_OBJECT_0)
- goto cleanup;
-
- CHECK_IF_ACTIVE(lpProc);
-
- /* Try to create the remote thread in the child address space */
- DYNLOAD_FPTR_ADDRESS(CreateRemoteThread, KERNEL32);
- if (DuplicateHandle(lpProc->hCurrentProcess,
- lpProc->stProcInfo.hProcess,
- lpProc->hCurrentProcess,
- &hDup,
- PROCESS_ALL_ACCESS,
- FALSE, 0)) {
- DYNLOAD_FPTR_ADDRESS(ExitProcess, KERNEL32);
- /* Now call the ExitProcess from inside the client
- * This will safely unload all the dll's.
- */
- hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup,
- NULL, 0,
- (LPTHREAD_START_ROUTINE)DYNLOAD_FPTR(ExitProcess),
- (PVOID)&uExitCode, 0, NULL);
- if (!IS_INVALID_HANDLE(hRemote)) {
- if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
- 2000) == WAIT_OBJECT_0) {
-
- }
- else {
- TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
- }
- CloseHandle(hRemote);
- }
- CloseHandle(hDup);
- goto cleanup;
- }
-
- TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
-
-cleanup:
- /* Close the process handle */
- SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
- lpProc->dwChildStatus &= ~CHILD_RUNNING;
- return TRUE;
-}
-
-static BOOL __apxProcessCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- LPAPXPROCESS lpProc;
-
- lpProc = APXHANDLE_DATA(hObject);
- /* Call the user supplied callback first */
- if (lpProc->fnUserCallback)
- (*lpProc->fnUserCallback)(hObject, uMsg, wParam, lParam);
- switch (uMsg) {
- case WM_CLOSE:
- if (lpProc->dwChildStatus & CHILD_RUNNING) {
- __apxProcessClose(hObject);
- /* Wait for all worker threads to exit */
- WaitForMultipleObjects(3, lpProc->hWorkerThreads, TRUE, INFINITE);
- }
- SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
-
- /* Close parent side of the pipes */
- SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
- SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
- SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
-
- SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[0]);
- SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[1]);
- SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[2]);
- SAFE_CLOSE_HANDLE(lpProc->hUserToken);
- apxFree(lpProc->szApplicationExec);
- apxFree(lpProc->szCommandLine);
- apxFree(lpProc->szWorkingPath);
- RESTORE_STD_HANDLES(lpProc);
- SAFE_CLOSE_HANDLE(lpProc->hCurrentProcess);
- if (lpProc->lpEnvironment)
- FreeEnvironmentStringsW(lpProc->lpEnvironment);
-
- case WM_QUIT:
- /* The process has finished
- * This is a WorkerThread message
- */
- lpProc->dwChildStatus &= ~CHILD_RUNNING;
- break;
- case WM_CHAR:
- __apxProcessPutc(lpProc, (INT)lParam, lpProc->chSize);
- break;
- case WM_SETTEXT:
- if (wParam)
- __apxProcessWrite(lpProc, (LPCVOID)lParam, (DWORD)wParam);
- else
- __apxProcessPuts(lpProc, (LPCTSTR)lParam);
- break;
- default:
- break;
- }
-
- return TRUE;
-}
-
-/** Create the process but don't start it
- *
- APXHANDLE
-apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
- LPAPXFNCALLBACK fnCallback,
- LPCWSTR szUsername, LPCWSTR szPassword,
- BOOL bLogonAsService)
-{
- APXHANDLE hProcess;
- LPAPXPROCESS lpProc;
- HANDLE hUserToken = NULL;
- if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
- HANDLE hUser;
-#ifndef _UNICODE
- WCHAR wsUsername[256];
- WCHAR wsPassword[256];
- AsciiToWide(szUsername, wsUsername);
- AsciiToWide(szPassword, wsPassword);
-#else
- LPCWSTR wsUsername = szUsername;
- LPCWSTR wsPassword = szPassword;
-#endif
-
- */
-
-
- APXHANDLE
-apxCreateProcessA(APXHANDLE hPool, DWORD dwOptions,
- LPAPXFNCALLBACK fnCallback,
- LPCSTR szUsername, LPCSTR szPassword,
- BOOL bLogonAsService)
-{
-
- if (szUsername && szPassword) {
- WCHAR wsUsername[256];
- WCHAR wsPassword[256];
- AsciiToWide(szUsername, wsUsername);
- AsciiToWide(szPassword, wsPassword);
- return apxCreateProcessW(hPool, dwOptions, fnCallback,
- wsUsername, wsPassword, bLogonAsService);
- }
- else
- return apxCreateProcessW(hPool, dwOptions, fnCallback,
- NULL, NULL, bLogonAsService);
-}
-
-APXHANDLE
-apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
- LPAPXFNCALLBACK fnCallback,
- LPCWSTR szUsername, LPCWSTR szPassword,
- BOOL bLogonAsService)
-{
- APXHANDLE hProcess;
- LPAPXPROCESS lpProc;
- HANDLE hUserToken = NULL;
- /* CreateProcessAsUser is supported only on NT */
- if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
- HANDLE hUser;
- if (!LogonUserW(szUsername,
- NULL,
- szPassword,
- bLogonAsService ? LOGON32_LOGON_SERVICE : LOGON32_LOGON_NETWORK,
- LOGON32_PROVIDER_DEFAULT,
- &hUser)) {
- /* Logon Failed */
- ErrorMessage(NULL, TRUE);
- return NULL;
- }
- if (!DuplicateTokenEx(hUser,
- TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
- NULL,
- SecurityImpersonation,
- TokenPrimary,
- &hUserToken)) {
- CloseHandle(hUser);
- /* Failed to duplicate the user token */
- ErrorMessage(NULL, TRUE);
- return NULL;
- }
- if (!ImpersonateLoggedOnUser(hUserToken)) {
- CloseHandle(hUser);
- CloseHandle(hUserToken);
- /* failed to impersonate the logged user */
- ErrorMessage(NULL, TRUE);
- return NULL;
- }
- CloseHandle(hUser);
- }
-
- hProcess = apxHandleCreate(hPool, APXHANDLE_HAS_EVENT,
- NULL, sizeof(APXPROCESS),
- __apxProcessCallback);
- if (IS_INVALID_HANDLE(hProcess))
- return NULL;
- hProcess->dwType = APXHANDLE_TYPE_PROCESS;
- lpProc = APXHANDLE_DATA(hProcess);
- lpProc->dwOptions = dwOptions;
- lpProc->fnUserCallback = fnCallback;
- lpProc->hUserToken = hUserToken;
- /* set the CHAR length */
- if (dwOptions & CREATE_UNICODE_ENVIRONMENT)
- lpProc->chSize = sizeof(WCHAR);
- else
- lpProc->chSize = sizeof(CHAR);
-#if 1
- DuplicateHandle(GetCurrentProcess(),
- GetCurrentProcess(),
- GetCurrentProcess(),
- &lpProc->hCurrentProcess,
- PROCESS_ALL_ACCESS,
- FALSE,
- 0);
-#else
- lpProc->hCurrentProcess = GetCurrentProcess();
-#endif
- lpProc->lpSD = &lpProc->bSD;
-
- InitializeSecurityDescriptor(lpProc->lpSD, SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(lpProc->lpSD, -1, 0, 0);
-
- lpProc->lpSA = (LPSECURITY_ATTRIBUTES)&lpProc->bSA[0];
- lpProc->lpSA->nLength = sizeof (SECURITY_ATTRIBUTES);
- lpProc->lpSA->lpSecurityDescriptor = lpProc->lpSD;
- lpProc->lpSA->bInheritHandle = TRUE;
-
- return hProcess;
-}
-
-static WCHAR _desktop_name[] =
- {'W', 'i', 'n', 's', 't', 'a', '0', '\\', 'D', 'e', 'f', 'a', 'u', 'l', 't', 0};
-
-BOOL
-apxProcessExecute(APXHANDLE hProcess)
-{
- LPAPXPROCESS lpProc;
- STARTUPINFOW si;
- DWORD id;
- BOOL bS = FALSE;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- /* don't allow multiple execute calls on the same object */
- if (lpProc->dwChildStatus & PROC_INITIALIZED)
- return FALSE;
- lpProc->bSaveHandles = TRUE;
- SAVE_STD_HANDLES(lpProc);
- if (!__apxProcCreateChildPipes(lpProc))
- goto cleanup;
- REDIRECT_STD_HANDLES(lpProc);
- AplZeroMemory(&si, sizeof(STARTUPINFO));
-
- si.cb = sizeof(STARTUPINFO);
- si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE;
- /* Set the redirected handles */
- si.hStdOutput = lpProc->hChildStdOut;
- si.hStdError = lpProc->hChildStdErr;
- si.hStdInput = lpProc->hChildStdInp;
-
- if (lpProc->lpEnvironment)
- FreeEnvironmentStringsW(lpProc->lpEnvironment);
- lpProc->lpEnvironment = GetEnvironmentStringsW();
-
- if (!IS_INVALID_HANDLE(lpProc->hUserToken)) {
- si.lpDesktop = _desktop_name;
- bS = CreateProcessAsUserW(lpProc->hUserToken,
- lpProc->szApplicationExec,
- lpProc->szCommandLine,
- lpProc->lpSA,
- NULL,
- TRUE,
- CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
- lpProc->lpEnvironment,
- lpProc->szWorkingPath,
- &si,
- &(lpProc->stProcInfo));
- }
- else {
- OutputDebugStringW(lpProc->szApplicationExec);
- OutputDebugStringW(lpProc->szCommandLine);
-
- bS = CreateProcessW(lpProc->szApplicationExec,
- lpProc->szCommandLine,
- lpProc->lpSA,
- NULL,
- TRUE,
- CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
- lpProc->lpEnvironment,
- lpProc->szWorkingPath,
- &si,
- &(lpProc->stProcInfo));
- }
- /* Close unused sides of pipes */
- SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);
- SAFE_CLOSE_HANDLE(lpProc->hChildStdOut);
- SAFE_CLOSE_HANDLE(lpProc->hChildStdErr);
- if (!bS)
- goto cleanup;
- /* Set the running flag */
- lpProc->dwChildStatus |= (CHILD_RUNNING | PROC_INITIALIZED);
-
- lpProc->hWorkerThreads[0] = CreateThread(NULL, 0, __apxProcStdoutThread,
- hProcess, 0, &id);
- lpProc->hWorkerThreads[1] = CreateThread(NULL, 0, __apxProcStderrThread,
- hProcess, 0, &id);
- ResumeThread(lpProc->stProcInfo.hThread);
- lpProc->hWorkerThreads[2] = CreateThread(NULL, 0, __apxProcWorkerThread,
- hProcess, 0, &id);
-
- SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hThread);
- /* Close child handles first */
- return TRUE;
-cleanup:
- /* Close parent side of the pipes */
- SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
- SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
- SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
-
- return FALSE;
-}
-
-BOOL
-apxProcessSetExecutableA(APXHANDLE hProcess, LPCSTR szName)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- apxFree(lpProc->szApplicationExec);
- lpProc->szApplicationExec = apxPoolWStrdupA(hProcess->hPool, szName);
- OutputDebugStringW(lpProc->szApplicationExec);
- return lpProc->szApplicationExec != NULL;
-}
-
-BOOL
-apxProcessSetExecutableW(APXHANDLE hProcess, LPCWSTR szName)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- apxFree(lpProc->szApplicationExec);
- lpProc->szApplicationExec = apxPoolStrdupW(hProcess->hPool, szName);
- OutputDebugStringW(lpProc->szApplicationExec);
- return lpProc->szApplicationExec != NULL;
-}
-
-BOOL
-apxProcessSetCommandLineA(APXHANDLE hProcess, LPCSTR szCmdline)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- apxFree(lpProc->szCommandLine);
- lpProc->szCommandLine = apxPoolWStrdupA(hProcess->hPool, szCmdline);
-
- return lpProc->szCommandLine != NULL;
-}
-
-BOOL
-apxProcessSetCommandLineW(APXHANDLE hProcess, LPCWSTR szCmdline)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- apxFree(lpProc->szCommandLine);
- lpProc->szCommandLine = apxPoolStrdupW(hProcess->hPool, szCmdline);
-
- return lpProc->szCommandLine != NULL;
-}
-
-BOOL
-apxProcessSetWorkingPathA(APXHANDLE hProcess, LPCSTR szPath)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- apxFree(lpProc->szWorkingPath);
- lpProc->szWorkingPath = apxPoolWStrdupA(hProcess->hPool, szPath);
-
- return lpProc->szWorkingPath != NULL;
-}
-
-BOOL
-apxProcessSetWorkingPathW(APXHANDLE hProcess, LPCWSTR szPath)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- apxFree(lpProc->szWorkingPath);
- if (!szPath) {
- /* Clear the WorkingPath */
- lpProc->szWorkingPath = NULL;
- return TRUE;
- }
- lpProc->szWorkingPath = apxPoolWStrdupW(hProcess->hPool, szPath);
-
- return lpProc->szWorkingPath != NULL;
-}
-
-DWORD
-apxProcessPutcA(APXHANDLE hProcess, INT ch)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return 0;
-
- lpProc = APXHANDLE_DATA(hProcess);
- return __apxProcessPutc(lpProc, ch, sizeof(CHAR));
-}
-
-DWORD
-apxProcessPutcW(APXHANDLE hProcess, INT ch)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return 0;
-
- lpProc = APXHANDLE_DATA(hProcess);
- return __apxProcessPutc(lpProc, ch, sizeof(WCHAR));
-}
-
-DWORD
-apxProcessPutsA(APXHANDLE hProcess, LPCSTR szString)
-{
- LPAPXPROCESS lpProc;
- DWORD len;
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
- return 0;
- lpProc = APXHANDLE_DATA(hProcess);
- len = lstrlenA(szString);
- len = __apxProcessWrite(lpProc, szString, len);
- if (len) {
- FlushFileBuffers(lpProc->hChildInpWr);
- return len;
- }
- else
- return 0;
-}
-
-DWORD
-apxProcessPutsW(APXHANDLE hProcess, LPCWSTR szString)
-{
- LPAPXPROCESS lpProc;
- DWORD len;
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
- return 0;
- lpProc = APXHANDLE_DATA(hProcess);
- len = lstrlenW(szString);
- len = __apxProcessWrite(lpProc, szString, len * 2);
- if (len) {
- FlushFileBuffers(lpProc->hChildInpWr);
- return (len / sizeof(WCHAR));
- }
- else
- return 0;
-}
-
-DWORD
-apxProcessWrite(APXHANDLE hProcess, LPCVOID lpData, DWORD dwLen)
-{
- LPAPXPROCESS lpProc;
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return 0;
-
- lpProc = APXHANDLE_DATA(hProcess);
-
- return __apxProcessWrite(lpProc, lpData, dwLen);
-}
-
-BOOL
-apxProcessFlushStdin(APXHANDLE hProcess)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
-
- if (lpProc->dwChildStatus & CHILD_RUNNING) {
- return FlushFileBuffers(lpProc->hChildInpWr);
- }
-
- return FALSE;
-}
-
-VOID
-apxProcessCloseInputStream(APXHANDLE hProcess)
-{
- if (hProcess->dwType == APXHANDLE_TYPE_PROCESS) {
- LPAPXPROCESS lpProc = APXHANDLE_DATA(hProcess);
- if (lpProc->dwChildStatus & CHILD_RUNNING)
- SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
- }
-}
-
-DWORD
-apxProcessWait(APXHANDLE hProcess, DWORD dwMilliseconds, BOOL bKill)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return WAIT_ABANDONED;
-
- lpProc = APXHANDLE_DATA(hProcess);
-
- if (lpProc->dwChildStatus & CHILD_RUNNING) {
- DWORD rv = WaitForMultipleObjects(3, lpProc->hWorkerThreads,
- TRUE, dwMilliseconds);
- if (rv == WAIT_TIMEOUT && bKill) {
- __apxProcessCallback(hProcess, WM_CLOSE, 0, 0);
- }
- return rv;
- }
- else
- return WAIT_OBJECT_0;
-}
-
-BOOL
-apxProcessRunning(APXHANDLE hProcess)
-{
- LPAPXPROCESS lpProc;
-
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
-
- return (lpProc->dwChildStatus & CHILD_RUNNING);
-}
-
-static LPWSTR __apxStrQuote(LPWSTR lpDest, LPCWSTR szSrc)
-{
- LPWSTR p;
- BOOL q = FALSE;
-
- /* Find if string has embeded spaces
- */
- for (p = (LPWSTR)szSrc; *p; p++) {
- if (*p == L' ' || *p == '\t' ||
- *p == '"' || *p == '\\') {
- q = TRUE;
- break;
- }
- }
- p = lpDest;
- if (q) *p++ = L'"';
- while (*szSrc) {
- if (*szSrc == '"' || *szSrc == '\\')
- *p++ = L'\\';
- *p++ = *szSrc++;
- }
- if (q) *p++ = L'"';
- return p;
-}
-
-BOOL
-apxProcessSetCommandArgsW(APXHANDLE hProcess, LPCWSTR szTitle,
- DWORD dwArgc, LPCWSTR *lpArgs)
-{
- LPAPXPROCESS lpProc;
- DWORD i, l = 0;
- LPWSTR p;
- if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
- return FALSE;
-
- lpProc = APXHANDLE_DATA(hProcess);
- apxFree(lpProc->szCommandLine);
-
- l = lstrlenW(szTitle) + 3;
- for (i = 0; i < (DWORD)lstrlenW(szTitle); i++) {
- if (szTitle[i] == L'"')
- ++l;
- }
- for (i = 0; i < dwArgc; i++) {
- int x, q = 0;
- l += (lstrlenW(lpArgs[i]) + 3);
- for (x = 0; x < lstrlenW(lpArgs[i]); x++) {
- if (lpArgs[i][x] == L'"')
- ++q;
- }
- l += q;
- }
- p = lpProc->szCommandLine = apxPoolAlloc(hProcess->hPool, l * sizeof(WCHAR));
- p = __apxStrQuote(p, szTitle);
- for (i = 0; i < dwArgc; i++) {
- *p++ = L' ';
- p = __apxStrQuote(p, lpArgs[i]);
- }
- *p = L'\0';
- OutputDebugStringW(lpProc->szCommandLine);
- return lpProc->szCommandLine != NULL;
-}
Copied: tags/jbosssvc/2.0.8/procrun/src/rprocess.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/rprocess.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/rprocess.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/rprocess.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,943 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define CHILD_RUNNING 0x0001
+#define CHILD_INITIALIZED 0x0002
+#define CHILD_MAINTREAD_FINISHED 0x0004
+#define PROC_INITIALIZED 0x0008
+#define CHILD_TERMINATE_CODE 19640323 /* Could be any value like my birthday ;-)*/
+
+DYNOLAD_TYPE_DECLARE(CreateRemoteThread,
+ __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES,
+ DWORD, LPTHREAD_START_ROUTINE,
+ LPVOID, DWORD, LPDWORD);
+
+DYNOLAD_TYPE_DECLARE(ExitProcess, __stdcall, void)(UINT);
+
+#define CHECK_IF_ACTIVE(proc) \
+ APXMACRO_BEGIN \
+ DWORD __st; \
+ if (!GetExitCodeProcess((proc)->stProcInfo.hProcess, &__st) || \
+ (__st != STILL_ACTIVE)) \
+ goto cleanup; \
+ APXMACRO_END
+
+#define SAVE_STD_HANDLES(p) \
+ APXMACRO_BEGIN \
+ if ((p)->bSaveHandles) { \
+ (p)->hParentStdSave[0] = GetStdHandle(STD_INPUT_HANDLE); \
+ (p)->hParentStdSave[1] = GetStdHandle(STD_OUTPUT_HANDLE); \
+ (p)->hParentStdSave[2] = GetStdHandle(STD_ERROR_HANDLE); \
+ } APXMACRO_END
+
+#define RESTORE_STD_HANDLES(p) \
+ APXMACRO_BEGIN \
+ if ((p)->bSaveHandles) { \
+ SetStdHandle(STD_INPUT_HANDLE, (p)->hParentStdSave[0]); \
+ SetStdHandle(STD_OUTPUT_HANDLE, (p)->hParentStdSave[1]); \
+ SetStdHandle(STD_ERROR_HANDLE, (p)->hParentStdSave[2]); \
+ } APXMACRO_END
+
+#define REDIRECT_STD_HANDLES(p) \
+ APXMACRO_BEGIN \
+ if ((p)->bSaveHandles) { \
+ SetStdHandle(STD_INPUT_HANDLE, (p)->hChildStdInp); \
+ SetStdHandle(STD_OUTPUT_HANDLE, (p)->hChildStdOut); \
+ SetStdHandle(STD_ERROR_HANDLE, (p)->hChildStdErr); \
+ } APXMACRO_END
+
+typedef struct APXPROCESS {
+ DWORD dwChildStatus;
+ DWORD dwOptions;
+ PROCESS_INFORMATION stProcInfo;
+ /* Size of chars for ANSI/Unicode programs */
+ DWORD chSize;
+ /* application working path */
+ LPWSTR szWorkingPath;
+ /* executable name */
+ LPWSTR szApplicationExec;
+ /* command line (first arg is program name for argv[0]) */
+ LPWSTR szCommandLine;
+ LPWSTR lpEnvironment;
+ /* set of child inherited pipes */
+ HANDLE hChildStdInp;
+ HANDLE hChildStdOut;
+ HANDLE hChildStdErr;
+ /* parent ends of child pipes */
+ HANDLE hChildInpWr;
+ HANDLE hChildOutRd;
+ HANDLE hChildErrRd;
+ /* Saved console pipes */
+ HANDLE hParentStdSave[3];
+ HANDLE hWorkerThreads[3];
+ HANDLE hUserToken;
+ HANDLE hCurrentProcess;
+ BOOL bSaveHandles;
+ /** callback function */
+ LPAPXFNCALLBACK fnUserCallback;
+ LPSECURITY_ATTRIBUTES lpSA;
+ LPVOID lpSD;
+ BYTE bSD[SECURITY_DESCRIPTOR_MIN_LENGTH];
+ BYTE bSA[sizeof(SECURITY_ATTRIBUTES)];
+
+} APXPROCESS, *LPAPXPROCESS;
+
+/** Process worker thread
+ * Monitors the process thread
+ */
+static DWORD WINAPI __apxProcWorkerThread(LPVOID lpParameter)
+{
+ APXHANDLE hProcess = (APXHANDLE)lpParameter;
+ LPAPXPROCESS lpProc;
+ DWORD dwExitCode = 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ /* Wait util a process has finished its initialization.
+ */
+ WaitForInputIdle(lpProc->stProcInfo.hProcess, INFINITE);
+ lpProc->dwChildStatus |= CHILD_INITIALIZED;
+ /* Wait until the child process exits */
+ if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
+ INFINITE) == WAIT_OBJECT_0) {
+ lpProc->dwChildStatus |= CHILD_MAINTREAD_FINISHED;
+#if 0
+ if (hProcess->fnCallback)
+ (*hProcess->fnCallback)(hProcess, WM_QUIT, (WPARAM)dwExitCode, 0);
+ lpProc->dwChildStatus &= ~CHILD_RUNNING;
+ GetExitCodeProcess(lpProc->stProcInfo.hProcess, &dwExitCode);
+
+ /* Close that handle */
+#endif
+ }
+ ExitThread(0);
+ return 0;
+}
+
+static DWORD WINAPI __apxProcStdoutThread(LPVOID lpParameter)
+{
+ APXHANDLE hProcess = (APXHANDLE)lpParameter;
+ LPAPXPROCESS lpProc;
+ APXCALLHOOK *lpCall;
+ INT ch;
+ DWORD dwReaded;
+ lpProc = APXHANDLE_DATA(hProcess);
+ while (lpProc->dwChildStatus & CHILD_RUNNING) {
+ ch = 0;
+ if (!ReadFile(lpProc->hChildOutRd, &ch, lpProc->chSize,
+ &dwReaded, NULL) || !dwReaded) {
+
+ break;
+ }
+ if (lpProc->fnUserCallback)
+ (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
+ TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
+ }
+ dwReaded = 0;
+ SwitchToThread();
+ }
+ ExitThread(0);
+ return 0;
+}
+
+static DWORD WINAPI __apxProcStderrThread(LPVOID lpParameter)
+{
+ APXHANDLE hProcess = (APXHANDLE)lpParameter;
+ LPAPXPROCESS lpProc;
+ APXCALLHOOK *lpCall;
+ INT ch;
+ DWORD dwReaded;
+ lpProc = APXHANDLE_DATA(hProcess);
+ while (lpProc->dwChildStatus & CHILD_RUNNING) {
+ if (!ReadFile(lpProc->hChildErrRd, &ch, lpProc->chSize,
+ &dwReaded, NULL) || !dwReaded) {
+
+ break;
+ }
+ if (lpProc->fnUserCallback)
+ (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
+ TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
+ }
+
+ dwReaded = 0;
+ SwitchToThread();
+ }
+
+ ExitThread(0);
+ return 0;
+}
+
+static DWORD __apxProcessPutc(LPAPXPROCESS lpProc, INT ch, DWORD dwSize)
+{
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ DWORD wr = 0;
+ if (WriteFile(lpProc->hChildInpWr, &ch, dwSize, &wr, NULL) &&
+ wr == dwSize) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static DWORD __apxProcessPuts(LPAPXPROCESS lpProc, LPCTSTR szString)
+{
+ DWORD l, n = 0;
+ l = lstrlen(szString) * lpProc->chSize;
+ if (lpProc->dwChildStatus & CHILD_RUNNING && l) {
+ DWORD wr = 0;
+ while (TRUE) {
+ if (WriteFile(lpProc->hChildInpWr, szString, l,
+ &wr, NULL)) {
+ n += wr;
+ if (wr < l) {
+ l -= wr;
+ szString += wr;
+ }
+ else {
+ /* Flush the buffer */
+ FlushFileBuffers(lpProc->hChildInpWr);
+ break;
+ }
+ }
+ else
+ break;
+ }
+ }
+
+ return n;
+}
+
+static DWORD __apxProcessWrite(LPAPXPROCESS lpProc, LPCVOID lpData, DWORD dwLen)
+{
+ LPBYTE buf = (LPBYTE)lpData;
+ DWORD n = 0;
+ if (!lpData || !dwLen)
+ return 0;
+
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ DWORD wr = 0;
+ while (lpProc->dwChildStatus & CHILD_RUNNING) {
+ if (WriteFile(lpProc->hChildInpWr, buf, dwLen,
+ &wr, NULL)) {
+ n += wr;
+ if (wr < dwLen) {
+ dwLen -= wr;
+ buf += wr;
+ }
+ else
+ break;
+ }
+ else
+ break;
+ }
+ }
+
+ return n;
+}
+
+/** Helper functions */
+static BOOL __apxProcCreateChildPipes(LPAPXPROCESS lpProc)
+{
+ BOOL rv = FALSE;
+
+ if (!CreatePipe(&(lpProc->hChildStdInp),
+ &(lpProc->hChildInpWr),
+ lpProc->lpSA, 0)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ goto cleanup;
+ }
+ if (!SetHandleInformation(lpProc->hChildInpWr,
+ HANDLE_FLAG_INHERIT, 0)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ goto cleanup;
+ }
+
+ if (!CreatePipe(&(lpProc->hChildOutRd),
+ &(lpProc->hChildStdOut),
+ lpProc->lpSA, 0)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ goto cleanup;
+ }
+
+ if (!SetHandleInformation(lpProc->hChildOutRd,
+ HANDLE_FLAG_INHERIT, 0)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ goto cleanup;
+ }
+
+ if (!CreatePipe(&(lpProc->hChildErrRd),
+ &(lpProc->hChildStdErr),
+ lpProc->lpSA, 0)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ goto cleanup;
+ }
+
+ if (!SetHandleInformation(lpProc->hChildErrRd,
+ HANDLE_FLAG_INHERIT, 0)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ goto cleanup;
+ }
+ rv = TRUE;
+cleanup:
+
+ return rv;
+}
+
+/* Close the process.
+ * Create the remote thread and call the ExitProcess
+ * Terminate the process, if all of the above fails.
+ */
+static BOOL __apxProcessClose(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+ DYNLOAD_FPTR_DECLARE(CreateRemoteThread);
+ DYNLOAD_FPTR_DECLARE(ExitProcess);
+
+ UINT uExitCode = CHILD_TERMINATE_CODE; /* Could be any value like my birthday ;-)*/
+ HANDLE hDup, hRemote;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ CHECK_IF_ACTIVE(lpProc);
+
+ /* Try to close the child's stdin first */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ /* Wait 1 sec for child process to
+ * recognize that the stdin has been closed.
+ */
+ if (WaitForSingleObject(lpProc->stProcInfo.hProcess, 1000) == WAIT_OBJECT_0)
+ goto cleanup;
+
+ CHECK_IF_ACTIVE(lpProc);
+
+ /* Try to create the remote thread in the child address space */
+ DYNLOAD_FPTR_ADDRESS(CreateRemoteThread, KERNEL32);
+ if (DuplicateHandle(lpProc->hCurrentProcess,
+ lpProc->stProcInfo.hProcess,
+ lpProc->hCurrentProcess,
+ &hDup,
+ PROCESS_ALL_ACCESS,
+ FALSE, 0)) {
+ DYNLOAD_FPTR_ADDRESS(ExitProcess, KERNEL32);
+ /* Now call the ExitProcess from inside the client
+ * This will safely unload all the dll's.
+ */
+ hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup,
+ NULL, 0,
+ (LPTHREAD_START_ROUTINE)DYNLOAD_FPTR(ExitProcess),
+ (PVOID)&uExitCode, 0, NULL);
+ if (!IS_INVALID_HANDLE(hRemote)) {
+ if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
+ 2000) == WAIT_OBJECT_0) {
+
+ }
+ else {
+ TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
+ }
+ CloseHandle(hRemote);
+ }
+ CloseHandle(hDup);
+ goto cleanup;
+ }
+
+ TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
+
+cleanup:
+ /* Close the process handle */
+ SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
+ lpProc->dwChildStatus &= ~CHILD_RUNNING;
+ return TRUE;
+}
+
+static BOOL __apxProcessCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXPROCESS lpProc;
+
+ lpProc = APXHANDLE_DATA(hObject);
+ /* Call the user supplied callback first */
+ if (lpProc->fnUserCallback)
+ (*lpProc->fnUserCallback)(hObject, uMsg, wParam, lParam);
+ switch (uMsg) {
+ case WM_CLOSE:
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ __apxProcessClose(hObject);
+ /* Wait for all worker threads to exit */
+ WaitForMultipleObjects(3, lpProc->hWorkerThreads, TRUE, INFINITE);
+ }
+ SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
+
+ /* Close parent side of the pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
+ SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
+
+ SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[0]);
+ SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[1]);
+ SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[2]);
+ SAFE_CLOSE_HANDLE(lpProc->hUserToken);
+ apxFree(lpProc->szApplicationExec);
+ apxFree(lpProc->szCommandLine);
+ apxFree(lpProc->szWorkingPath);
+ RESTORE_STD_HANDLES(lpProc);
+ SAFE_CLOSE_HANDLE(lpProc->hCurrentProcess);
+ if (lpProc->lpEnvironment)
+ FreeEnvironmentStringsW(lpProc->lpEnvironment);
+
+ case WM_QUIT:
+ /* The process has finished
+ * This is a WorkerThread message
+ */
+ lpProc->dwChildStatus &= ~CHILD_RUNNING;
+ break;
+ case WM_CHAR:
+ __apxProcessPutc(lpProc, (INT)lParam, lpProc->chSize);
+ break;
+ case WM_SETTEXT:
+ if (wParam)
+ __apxProcessWrite(lpProc, (LPCVOID)lParam, (DWORD)wParam);
+ else
+ __apxProcessPuts(lpProc, (LPCTSTR)lParam);
+ break;
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+/** Create the process but don't start it
+ *
+ APXHANDLE
+apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCWSTR szUsername, LPCWSTR szPassword,
+ BOOL bLogonAsService)
+{
+ APXHANDLE hProcess;
+ LPAPXPROCESS lpProc;
+ HANDLE hUserToken = NULL;
+ if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
+ HANDLE hUser;
+#ifndef _UNICODE
+ WCHAR wsUsername[256];
+ WCHAR wsPassword[256];
+ AsciiToWide(szUsername, wsUsername);
+ AsciiToWide(szPassword, wsPassword);
+#else
+ LPCWSTR wsUsername = szUsername;
+ LPCWSTR wsPassword = szPassword;
+#endif
+
+ */
+
+
+ APXHANDLE
+apxCreateProcessA(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCSTR szUsername, LPCSTR szPassword,
+ BOOL bLogonAsService)
+{
+
+ if (szUsername && szPassword) {
+ WCHAR wsUsername[256];
+ WCHAR wsPassword[256];
+ AsciiToWide(szUsername, wsUsername);
+ AsciiToWide(szPassword, wsPassword);
+ return apxCreateProcessW(hPool, dwOptions, fnCallback,
+ wsUsername, wsPassword, bLogonAsService);
+ }
+ else
+ return apxCreateProcessW(hPool, dwOptions, fnCallback,
+ NULL, NULL, bLogonAsService);
+}
+
+APXHANDLE
+apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCWSTR szUsername, LPCWSTR szPassword,
+ BOOL bLogonAsService)
+{
+ APXHANDLE hProcess;
+ LPAPXPROCESS lpProc;
+ HANDLE hUserToken = NULL;
+ /* CreateProcessAsUser is supported only on NT */
+ if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
+ HANDLE hUser;
+ if (!LogonUserW(szUsername,
+ NULL,
+ szPassword,
+ bLogonAsService ? LOGON32_LOGON_SERVICE : LOGON32_LOGON_NETWORK,
+ LOGON32_PROVIDER_DEFAULT,
+ &hUser)) {
+ /* Logon Failed */
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+ if (!DuplicateTokenEx(hUser,
+ TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
+ NULL,
+ SecurityImpersonation,
+ TokenPrimary,
+ &hUserToken)) {
+ CloseHandle(hUser);
+ /* Failed to duplicate the user token */
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+ if (!ImpersonateLoggedOnUser(hUserToken)) {
+ CloseHandle(hUser);
+ CloseHandle(hUserToken);
+ /* failed to impersonate the logged user */
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+ CloseHandle(hUser);
+ }
+
+ hProcess = apxHandleCreate(hPool, APXHANDLE_HAS_EVENT,
+ NULL, sizeof(APXPROCESS),
+ __apxProcessCallback);
+ if (IS_INVALID_HANDLE(hProcess))
+ return NULL;
+ hProcess->dwType = APXHANDLE_TYPE_PROCESS;
+ lpProc = APXHANDLE_DATA(hProcess);
+ lpProc->dwOptions = dwOptions;
+ lpProc->fnUserCallback = fnCallback;
+ lpProc->hUserToken = hUserToken;
+ /* set the CHAR length */
+ if (dwOptions & CREATE_UNICODE_ENVIRONMENT)
+ lpProc->chSize = sizeof(WCHAR);
+ else
+ lpProc->chSize = sizeof(CHAR);
+#if 1
+ DuplicateHandle(GetCurrentProcess(),
+ GetCurrentProcess(),
+ GetCurrentProcess(),
+ &lpProc->hCurrentProcess,
+ PROCESS_ALL_ACCESS,
+ FALSE,
+ 0);
+#else
+ lpProc->hCurrentProcess = GetCurrentProcess();
+#endif
+ lpProc->lpSD = &lpProc->bSD;
+
+ InitializeSecurityDescriptor(lpProc->lpSD, SECURITY_DESCRIPTOR_REVISION);
+ SetSecurityDescriptorDacl(lpProc->lpSD, -1, 0, 0);
+
+ lpProc->lpSA = (LPSECURITY_ATTRIBUTES)&lpProc->bSA[0];
+ lpProc->lpSA->nLength = sizeof (SECURITY_ATTRIBUTES);
+ lpProc->lpSA->lpSecurityDescriptor = lpProc->lpSD;
+ lpProc->lpSA->bInheritHandle = TRUE;
+
+ return hProcess;
+}
+
+static WCHAR _desktop_name[] =
+ {'W', 'i', 'n', 's', 't', 'a', '0', '\\', 'D', 'e', 'f', 'a', 'u', 'l', 't', 0};
+
+BOOL
+apxProcessExecute(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+ STARTUPINFOW si;
+ DWORD id;
+ BOOL bS = FALSE;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ /* don't allow multiple execute calls on the same object */
+ if (lpProc->dwChildStatus & PROC_INITIALIZED)
+ return FALSE;
+ lpProc->bSaveHandles = TRUE;
+ SAVE_STD_HANDLES(lpProc);
+ if (!__apxProcCreateChildPipes(lpProc))
+ goto cleanup;
+ REDIRECT_STD_HANDLES(lpProc);
+ AplZeroMemory(&si, sizeof(STARTUPINFO));
+
+ si.cb = sizeof(STARTUPINFO);
+ si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+ /* Set the redirected handles */
+ si.hStdOutput = lpProc->hChildStdOut;
+ si.hStdError = lpProc->hChildStdErr;
+ si.hStdInput = lpProc->hChildStdInp;
+
+ if (lpProc->lpEnvironment)
+ FreeEnvironmentStringsW(lpProc->lpEnvironment);
+ lpProc->lpEnvironment = GetEnvironmentStringsW();
+
+ if (!IS_INVALID_HANDLE(lpProc->hUserToken)) {
+ si.lpDesktop = _desktop_name;
+ bS = CreateProcessAsUserW(lpProc->hUserToken,
+ lpProc->szApplicationExec,
+ lpProc->szCommandLine,
+ lpProc->lpSA,
+ NULL,
+ TRUE,
+ CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
+ lpProc->lpEnvironment,
+ lpProc->szWorkingPath,
+ &si,
+ &(lpProc->stProcInfo));
+ }
+ else {
+ OutputDebugStringW(lpProc->szApplicationExec);
+ OutputDebugStringW(lpProc->szCommandLine);
+
+ bS = CreateProcessW(lpProc->szApplicationExec,
+ lpProc->szCommandLine,
+ lpProc->lpSA,
+ NULL,
+ TRUE,
+ CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
+ lpProc->lpEnvironment,
+ lpProc->szWorkingPath,
+ &si,
+ &(lpProc->stProcInfo));
+ }
+ /* Close unused sides of pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);
+ SAFE_CLOSE_HANDLE(lpProc->hChildStdOut);
+ SAFE_CLOSE_HANDLE(lpProc->hChildStdErr);
+ if (!bS)
+ goto cleanup;
+ /* Set the running flag */
+ lpProc->dwChildStatus |= (CHILD_RUNNING | PROC_INITIALIZED);
+
+ lpProc->hWorkerThreads[0] = CreateThread(NULL, 0, __apxProcStdoutThread,
+ hProcess, 0, &id);
+ lpProc->hWorkerThreads[1] = CreateThread(NULL, 0, __apxProcStderrThread,
+ hProcess, 0, &id);
+ ResumeThread(lpProc->stProcInfo.hThread);
+ lpProc->hWorkerThreads[2] = CreateThread(NULL, 0, __apxProcWorkerThread,
+ hProcess, 0, &id);
+
+ SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hThread);
+ /* Close child handles first */
+ return TRUE;
+cleanup:
+ /* Close parent side of the pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
+ SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
+
+ return FALSE;
+}
+
+BOOL
+apxProcessSetExecutableA(APXHANDLE hProcess, LPCSTR szName)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szApplicationExec);
+ lpProc->szApplicationExec = apxPoolWStrdupA(hProcess->hPool, szName);
+ OutputDebugStringW(lpProc->szApplicationExec);
+ return lpProc->szApplicationExec != NULL;
+}
+
+BOOL
+apxProcessSetExecutableW(APXHANDLE hProcess, LPCWSTR szName)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szApplicationExec);
+ lpProc->szApplicationExec = apxPoolStrdupW(hProcess->hPool, szName);
+ OutputDebugStringW(lpProc->szApplicationExec);
+ return lpProc->szApplicationExec != NULL;
+}
+
+BOOL
+apxProcessSetCommandLineA(APXHANDLE hProcess, LPCSTR szCmdline)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szCommandLine);
+ lpProc->szCommandLine = apxPoolWStrdupA(hProcess->hPool, szCmdline);
+
+ return lpProc->szCommandLine != NULL;
+}
+
+BOOL
+apxProcessSetCommandLineW(APXHANDLE hProcess, LPCWSTR szCmdline)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szCommandLine);
+ lpProc->szCommandLine = apxPoolStrdupW(hProcess->hPool, szCmdline);
+
+ return lpProc->szCommandLine != NULL;
+}
+
+BOOL
+apxProcessSetWorkingPathA(APXHANDLE hProcess, LPCSTR szPath)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szWorkingPath);
+ lpProc->szWorkingPath = apxPoolWStrdupA(hProcess->hPool, szPath);
+
+ return lpProc->szWorkingPath != NULL;
+}
+
+BOOL
+apxProcessSetWorkingPathW(APXHANDLE hProcess, LPCWSTR szPath)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szWorkingPath);
+ if (!szPath) {
+ /* Clear the WorkingPath */
+ lpProc->szWorkingPath = NULL;
+ return TRUE;
+ }
+ lpProc->szWorkingPath = apxPoolWStrdupW(hProcess->hPool, szPath);
+
+ return lpProc->szWorkingPath != NULL;
+}
+
+DWORD
+apxProcessPutcA(APXHANDLE hProcess, INT ch)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ return __apxProcessPutc(lpProc, ch, sizeof(CHAR));
+}
+
+DWORD
+apxProcessPutcW(APXHANDLE hProcess, INT ch)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ return __apxProcessPutc(lpProc, ch, sizeof(WCHAR));
+}
+
+DWORD
+apxProcessPutsA(APXHANDLE hProcess, LPCSTR szString)
+{
+ LPAPXPROCESS lpProc;
+ DWORD len;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
+ return 0;
+ lpProc = APXHANDLE_DATA(hProcess);
+ len = lstrlenA(szString);
+ len = __apxProcessWrite(lpProc, szString, len);
+ if (len) {
+ FlushFileBuffers(lpProc->hChildInpWr);
+ return len;
+ }
+ else
+ return 0;
+}
+
+DWORD
+apxProcessPutsW(APXHANDLE hProcess, LPCWSTR szString)
+{
+ LPAPXPROCESS lpProc;
+ DWORD len;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
+ return 0;
+ lpProc = APXHANDLE_DATA(hProcess);
+ len = lstrlenW(szString);
+ len = __apxProcessWrite(lpProc, szString, len * 2);
+ if (len) {
+ FlushFileBuffers(lpProc->hChildInpWr);
+ return (len / sizeof(WCHAR));
+ }
+ else
+ return 0;
+}
+
+DWORD
+apxProcessWrite(APXHANDLE hProcess, LPCVOID lpData, DWORD dwLen)
+{
+ LPAPXPROCESS lpProc;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ return __apxProcessWrite(lpProc, lpData, dwLen);
+}
+
+BOOL
+apxProcessFlushStdin(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ return FlushFileBuffers(lpProc->hChildInpWr);
+ }
+
+ return FALSE;
+}
+
+VOID
+apxProcessCloseInputStream(APXHANDLE hProcess)
+{
+ if (hProcess->dwType == APXHANDLE_TYPE_PROCESS) {
+ LPAPXPROCESS lpProc = APXHANDLE_DATA(hProcess);
+ if (lpProc->dwChildStatus & CHILD_RUNNING)
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ }
+}
+
+DWORD
+apxProcessWait(APXHANDLE hProcess, DWORD dwMilliseconds, BOOL bKill)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return WAIT_ABANDONED;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ DWORD rv = WaitForMultipleObjects(3, lpProc->hWorkerThreads,
+ TRUE, dwMilliseconds);
+ if (rv == WAIT_TIMEOUT && bKill) {
+ __apxProcessCallback(hProcess, WM_CLOSE, 0, 0);
+ }
+ return rv;
+ }
+ else
+ return WAIT_OBJECT_0;
+}
+
+BOOL
+apxProcessRunning(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ return (lpProc->dwChildStatus & CHILD_RUNNING);
+}
+
+DWORD
+apxProcessGetPid(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ return lpProc->stProcInfo.dwProcessId;
+}
+
+static LPWSTR __apxStrQuote(LPWSTR lpDest, LPCWSTR szSrc)
+{
+ LPWSTR p;
+ BOOL space = FALSE, quote = FALSE;
+
+ /* Find if string has embeded spaces, add quotes only if no quotes found
+ */
+ for (p = (LPWSTR)szSrc; *p; p++) {
+ if (*p == L' ' || *p == '\t') {
+ space = TRUE;
+ } else if (*p == L'"') {
+ quote = TRUE;
+ }
+ }
+ p = lpDest;
+ if (space && !quote) *p++ = L'"';
+ while (*szSrc) {
+ *p++ = *szSrc++;
+ }
+ if (space && !quote) *p++ = L'"';
+ return p;
+}
+
+BOOL
+apxProcessSetCommandArgsW(APXHANDLE hProcess, LPCWSTR szTitle,
+ DWORD dwArgc, LPCWSTR *lpArgs)
+{
+ LPAPXPROCESS lpProc;
+ DWORD i, l = 0;
+ LPWSTR p;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szCommandLine);
+
+ l = lstrlenW(szTitle) + 3;
+ for (i = 0; i < dwArgc; i++) {
+ int q = 0;
+ l += (lstrlenW(lpArgs[i]) + 3);
+ l += q;
+ }
+ p = lpProc->szCommandLine = apxPoolAlloc(hProcess->hPool, l * sizeof(WCHAR));
+ p = __apxStrQuote(p, szTitle);
+ for (i = 0; i < dwArgc; i++) {
+ *p++ = L' ';
+ p = __apxStrQuote(p, lpArgs[i]);
+ }
+ *p = L'\0';
+ OutputDebugStringW(lpProc->szCommandLine);
+ return lpProc->szCommandLine != NULL;
+}
+
Deleted: tags/jbosssvc/2.0.8/procrun/src/service.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/service.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/service.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,565 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-#define SAFE_CLOSE_SCH(h) \
- if ((h) != NULL && (h) != INVALID_HANDLE_VALUE) { \
- CloseServiceHandle((h)); \
- (h) = NULL; \
- }
-
-#define CHANGE_SERVICE(h, b, u, p, d) \
- ChangeServiceConfigW(h, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, \
- SERVICE_NO_CHANGE,b,NULL,NULL,NULL, \
- u,p,d)
-
-typedef struct APXSERVICE {
- /* Are we a service manager or we are the service itself */
- BOOL bManagerMode;
- /* Handle to the current service */
- SC_HANDLE hService;
- /* Handle of the Service manager */
- SC_HANDLE hManager;
- APXSERVENTRY stServiceEntry;
-
-} APXSERVICE, *LPAPXSERVICE;
-
-static BOOL __apxIsValidServiceName(LPCWSTR szServiceName)
-{
- do {
- if (!IsCharAlphaNumericW(*szServiceName)) {
- apxDisplayError(TRUE, NULL, 0, "NonAlpha %d", *szServiceName);
- return FALSE;
- }
- } while( *(++szServiceName));
- return TRUE;
-}
-
-static BOOL __apxServiceCallback(APXHANDLE hObject, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
-{
- LPAPXSERVICE lpService;
-
- lpService = APXHANDLE_DATA(hObject);
- switch (uMsg) {
- case WM_CLOSE:
- apxFree(lpService->stServiceEntry.lpConfig);
- lpService->stServiceEntry.lpConfig = NULL;
- SAFE_CLOSE_SCH(lpService->hService);
- SAFE_CLOSE_SCH(lpService->hManager);
- break;
- default:
- break;
- }
- return TRUE;
-}
-
-APXHANDLE
-apxCreateService(APXHANDLE hPool, DWORD dwOptions, BOOL bManagerMode)
-{
- APXHANDLE hService;
- LPAPXSERVICE lpService;
- SC_HANDLE hManager;
-
- if (!(hManager = OpenSCManager(NULL, NULL, dwOptions))) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return NULL;
- }
- hService = apxHandleCreate(hPool, 0,
- NULL, sizeof(APXSERVICE),
- __apxServiceCallback);
- if (IS_INVALID_HANDLE(hService)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed to Create Handle for Service");
- return NULL;
- }
- hService->dwType = APXHANDLE_TYPE_SERVICE;
- lpService = APXHANDLE_DATA(hService);
- lpService->hManager = hManager;
- lpService->bManagerMode = bManagerMode;
-
- return hService;
-}
-
-BOOL
-apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions)
-{
- LPAPXSERVICE lpService;
- DWORD dwNeeded;
-
- if (hService->dwType != APXHANDLE_TYPE_SERVICE)
- return FALSE;
-
- lpService = APXHANDLE_DATA(hService);
- /* Manager mode cannot handle services */
- if (lpService->bManagerMode)
- return FALSE;
-
- /* Close any previous instance
- * Same handle can manage multiple services
- */
- SAFE_CLOSE_SCH(lpService->hService);
- *lpService->stServiceEntry.szServiceDescription = L'\0';
- *lpService->stServiceEntry.szObjectName = L'\0';
- apxFree(lpService->stServiceEntry.lpConfig);
- lpService->stServiceEntry.lpConfig = NULL;
- /* Open the service */
- lpService->hService = OpenServiceW(lpService->hManager,
- szServiceName,
- dwOptions);
-
- if (IS_INVALID_HANDLE(lpService->hService)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return FALSE;
- }
- lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
- if (!apxGetServiceDescriptionW(szServiceName,
- lpService->stServiceEntry.szServiceDescription,
- SIZ_DESLEN)) {
- apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service description");
- lpService->stServiceEntry.szServiceDescription[0] = L'\0';
- }
- if (!apxGetServiceUserW(szServiceName,
- lpService->stServiceEntry.szObjectName,
- SIZ_RESLEN)) {
- apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service user name");
- lpService->stServiceEntry.szObjectName[0] = L'\0';
- }
- if (!QueryServiceConfigW(lpService->hService, NULL, 0, &dwNeeded)) {
- if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- apxLogWrite(APXLOG_MARK_SYSERR);
- }
- /* TODO: Check GetLastError ERROR_INSUFFICIENT_BUFFER */
- lpService->stServiceEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
- dwNeeded);
- return QueryServiceConfigW(lpService->hService,
- lpService->stServiceEntry.lpConfig,
- dwNeeded, &dwNeeded);
-}
-
-LPAPXSERVENTRY
-apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus)
-{
- LPAPXSERVICE lpService;
-
- if (hService->dwType != APXHANDLE_TYPE_SERVICE)
- return NULL;
-
- lpService = APXHANDLE_DATA(hService);
- /* Manager mode cannot handle services */
- if (lpService->bManagerMode)
- return NULL;
-
- if (bRequeryStatus && !QueryServiceStatus(lpService->hService,
- &(lpService->stServiceEntry.stServiceStatus))) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return NULL;
- }
-
- return &lpService->stServiceEntry;
-}
-
-/* Set the service names etc...
- * If the ImagePath contains a space, it must be quoted
- */
-BOOL
-apxServiceSetNames(APXHANDLE hService,
- LPCWSTR szImagePath,
- LPCWSTR szDisplayName,
- LPCWSTR szDescription,
- LPCWSTR szUsername,
- LPCWSTR szPassword)
-{
- LPAPXSERVICE lpService;
-
- if (hService->dwType != APXHANDLE_TYPE_SERVICE)
- return FALSE;
-
- lpService = APXHANDLE_DATA(hService);
- /* Manager mode cannot handle services */
- if (lpService->bManagerMode)
- return FALSE;
- /* Check if the ServiceOpen has been called */
- if (IS_INVALID_HANDLE(lpService->hService))
- return FALSE;
- if (!CHANGE_SERVICE(lpService->hService,
- szImagePath,
- szUsername,
- szPassword,
- szDisplayName)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return FALSE;
- }
- if (szDescription) {
- return apxSetServiceDescriptionW(lpService->stServiceEntry.szServiceName,
- szDescription);
- }
- return TRUE;
-}
-
-BOOL
-apxServiceSetOptions(APXHANDLE hService,
- DWORD dwServiceType,
- DWORD dwStartType,
- DWORD dwErrorControl)
-{
- LPAPXSERVICE lpService;
-
- if (hService->dwType != APXHANDLE_TYPE_SERVICE)
- return FALSE;
-
- lpService = APXHANDLE_DATA(hService);
- /* Manager mode cannot handle services */
- if (lpService->bManagerMode)
- return FALSE;
- /* Check if the ServixeOpen has been called */
- if (IS_INVALID_HANDLE(lpService->hService))
- return FALSE;
- return ChangeServiceConfig(lpService->hService, dwServiceType,
- dwStartType, dwErrorControl,
- NULL, NULL, NULL, NULL, NULL,
- NULL, NULL);
-}
-
-BOOL
-apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
- LPAPXFNCALLBACK fnControlCallback,
- LPVOID lpCbData)
-{
- LPAPXSERVICE lpService;
- SERVICE_STATUS stStatus;
- DWORD dwPending = 0;
- DWORD dwState = 0;
- DWORD dwTick = 0;
- DWORD dwWait, dwCheck, dwStart;
- BOOL bStatus;
-
- if (hService->dwType != APXHANDLE_TYPE_SERVICE)
- return FALSE;
-
- lpService = APXHANDLE_DATA(hService);
- /* Manager mode cannot handle services */
- if (lpService->bManagerMode)
- return FALSE;
- /* Check if the ServixeOpen has been called */
- if (IS_INVALID_HANDLE(lpService->hService))
- return FALSE;
- switch (dwControl) {
- case SERVICE_CONTROL_CONTINUE:
- dwPending = SERVICE_START_PENDING;
- dwState = SERVICE_RUNNING;
- break;
- case SERVICE_CONTROL_STOP:
- dwPending = SERVICE_STOP_PENDING;
- dwState = SERVICE_STOPPED;
- break;
- case SERVICE_CONTROL_PAUSE:
- dwPending = SERVICE_PAUSE_PENDING;
- dwState = SERVICE_PAUSED;
- break;
- default:
- break;
- }
- /* user defined controls */
- if (dwControl > 127 && dwControl < 224) {
- /* 128 ... 159 start signals
- * 160 ... 191 stop signals
- * 192 ... 223 pause signals
- */
- switch (dwControl & 0xE0) {
- case 0x80:
- case 0x90:
- dwPending = SERVICE_START_PENDING;
- dwState = SERVICE_RUNNING;
- break;
- case 0xA0:
- case 0xB0:
- dwPending = SERVICE_STOP_PENDING;
- dwState = SERVICE_STOPPED;
- break;
- case 0xC0:
- case 0xD0:
- dwPending = SERVICE_PAUSE_PENDING;
- dwState = SERVICE_PAUSED;
- break;
- default:
- break;
- }
- }
- if (!dwPending && !dwState)
- return FALSE;
- /* Now lets control */
- if (!QueryServiceStatus(lpService->hService, &stStatus)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
- return FALSE;
- }
- /* signal that we are about to control the service */
- if (fnControlCallback)
- (*fnControlCallback)(lpCbData, uMsg, (WPARAM)1, (LPARAM)dwState);
- if (dwControl == SERVICE_CONTROL_CONTINUE &&
- stStatus.dwCurrentState != SERVICE_PAUSED)
- bStatus = StartService(lpService->hService, 0, NULL);
- else
- bStatus = ControlService(lpService->hService, dwControl, &stStatus);
- dwStart = GetTickCount();
- dwCheck = stStatus.dwCheckPoint;
- if (bStatus) {
- Sleep(100); /* Initial Sleep period */
- while (QueryServiceStatus(lpService->hService, &stStatus)) {
- if (stStatus.dwCurrentState == dwPending) {
- /* Do not wait longer than the wait hint. A good interval is
- * one tenth the wait hint, but no less than 1 second and no
- * more than 10 seconds.
- */
- dwWait = stStatus.dwWaitHint / 10;
-
- if( dwWait < 1000 )
- dwWait = 1000;
- else if ( dwWait > 10000 )
- dwWait = 10000;
- /* Signal to the callback that we are pending
- * break if callback returns false.
- */
- if (fnControlCallback) {
- if (!(*fnControlCallback)(lpCbData, uMsg, (WPARAM)2,
- (LPARAM)dwTick++))
- break;
- }
- Sleep(dwWait);
- if (stStatus.dwCheckPoint > dwCheck) {
- /* The service is making progress. */
- dwStart = GetTickCount();
- dwCheck = stStatus.dwCheckPoint;
- }
- else {
- if(GetTickCount() - dwStart > stStatus.dwWaitHint) {
- /* No progress made within the wait hint */
- break;
- }
- }
- }
- else
- break;
- }
- }
- /* signal that we are done with controling the service */
- if (fnControlCallback)
- (*fnControlCallback)(lpCbData, uMsg, (WPARAM)3, (LPARAM)0);
- /* Check if we are in the desired state */
- Sleep(1000);
-
- if (QueryServiceStatus(lpService->hService, &stStatus)) {
- if (fnControlCallback)
- (*fnControlCallback)(lpCbData, uMsg, (WPARAM)4,
- (LPARAM)&stStatus);
- if (stStatus.dwCurrentState == dwState)
- return TRUE;
-
- }
-
- return FALSE;
-}
-
-BOOL
-apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
- LPCWSTR szDisplayName, LPCWSTR szImagePath,
- LPCWSTR lpDependencies, DWORD dwServiceType,
- DWORD dwStartType)
-{
- LPAPXSERVICE lpService;
-
- if (hService->dwType != APXHANDLE_TYPE_SERVICE)
- return FALSE;
-
- lpService = APXHANDLE_DATA(hService);
- /* Manager mode cannot handle services */
- if (lpService->bManagerMode)
- return FALSE;
- if (IS_INVALID_HANDLE(lpService->hManager))
- return FALSE;
- if (!__apxIsValidServiceName(szServiceName))
- return FALSE;
- /* Close any previous instance
- * Same handle can install multiple services
- */
- SAFE_CLOSE_SCH(lpService->hService);
-
- apxFree(lpService->stServiceEntry.lpConfig);
- lpService->stServiceEntry.lpConfig = NULL;
- AplZeroMemory(&lpService->stServiceEntry, sizeof(APXSERVENTRY));
-
- lpService->hService = CreateServiceW(lpService->hManager,
- szServiceName,
- szDisplayName,
- SERVICE_ALL_ACCESS,
- dwServiceType,
- dwStartType,
- SERVICE_ERROR_NORMAL,
- szImagePath,
- NULL,
- NULL,
- lpDependencies,
- NULL,
- NULL);
-
- if (IS_INVALID_HANDLE(lpService->hService)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
-
- ErrorMessage(NULL, FALSE);
- return FALSE;
- }
- else {
- lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
- lpService->stServiceEntry.dwStart = dwStartType;
- return TRUE;
- }
-}
-
-BOOL
-apxServiceDelete(APXHANDLE hService)
-{
- LPAPXSERVICE lpService;
- SERVICE_STATUS stStatus;
- if (hService->dwType != APXHANDLE_TYPE_SERVICE)
- return FALSE;
-
- lpService = APXHANDLE_DATA(hService);
- /* Manager mode cannot handle services */
- if (lpService->bManagerMode)
- return FALSE;
- /* Check if the ServiceOpen has been called */
- if (IS_INVALID_HANDLE(lpService->hService))
- return FALSE;
- if (QueryServiceStatus(lpService->hService, &stStatus)) {
- BOOL rv;
- if (stStatus.dwCurrentState != SERVICE_STOPPED)
- apxServiceControl(hService, SERVICE_CONTROL_STOP, 0, NULL, NULL);
- rv = DeleteService(lpService->hService);
- SAFE_CLOSE_SCH(lpService->hService);
- SAFE_CLOSE_SCH(lpService->hManager);
-
- return rv;
- }
- return FALSE;
-}
-
-/* Browse the services */
-DWORD
-apxServiceBrowse(APXHANDLE hService,
- LPCWSTR szIncludeNamePattern,
- LPCWSTR szIncludeImagePattern,
- LPCWSTR szExcludeNamePattern,
- LPCWSTR szExcludeImagePattern,
- UINT uMsg,
- LPAPXFNCALLBACK fnDisplayCallback,
- LPVOID lpCbData)
-{
- DWORD nFound = 0;
- APXREGENUM stEnum;
- LPAPXSERVICE lpService;
- SC_LOCK hLock;
- if (hService->dwType != APXHANDLE_TYPE_SERVICE || !fnDisplayCallback)
- return 0;
-
- lpService = APXHANDLE_DATA(hService);
- /* Only the manager mode can browse services */
- if (!lpService->bManagerMode ||
- IS_INVALID_HANDLE(lpService->hManager))
- return 0;
- hLock = LockServiceDatabase(lpService->hManager);
- if (IS_INVALID_HANDLE(hLock)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
-
- ErrorMessage(NULL, FALSE);
- return 0;
- }
- AplZeroMemory(&stEnum, sizeof(APXREGENUM));
-
- while (TRUE) {
- APXSERVENTRY stEntry;
- BOOL rv;
- AplZeroMemory(&stEntry, sizeof(APXSERVENTRY));
- rv = apxRegistryEnumServices(&stEnum, &stEntry);
-
- if (rv) {
- INT fm = -1;
- SC_HANDLE hSrv = NULL;
- DWORD dwNeeded = 0;
- hSrv = OpenServiceW(lpService->hManager,
- stEntry.szServiceName,
- GENERIC_READ);
- if (!IS_INVALID_HANDLE(hSrv)) {
- QueryServiceConfigW(hSrv, NULL, 0, &dwNeeded);
- stEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
- dwNeeded);
- /* Call the QueryServiceConfig againg with allocated config */
- if (QueryServiceConfigW(hSrv, stEntry.lpConfig, dwNeeded, &dwNeeded)) {
- /* Make that customizable so that kernel mode drivers can be
- * displayed and maintained. For now skip the
- * filesystem and device drivers.
- * XXX: Do we need that customizable after all?
- */
- if ((stEntry.lpConfig->dwServiceType &
- ~SERVICE_INTERACTIVE_PROCESS) & SERVICE_WIN32)
- fm = 0;
-
- if (!fm && szIncludeNamePattern) {
- fm = apxMultiStrMatchW(stEntry.szServiceName,
- szIncludeNamePattern, L';', TRUE);
- }
- if (!fm && szExcludeNamePattern) {
- fm = !apxMultiStrMatchW(stEntry.szServiceName,
- szExcludeNamePattern, L';', TRUE);
- }
- if (!fm && szIncludeImagePattern) {
- fm = apxMultiStrMatchW(stEntry.lpConfig->lpBinaryPathName,
- szIncludeImagePattern, L';', TRUE);
- }
- if (!fm && szExcludeImagePattern) {
- fm = !apxMultiStrMatchW(stEntry.szServiceName,
- szExcludeImagePattern, L';', TRUE);
- }
- if (!fm) {
- QueryServiceStatus(hSrv, &(stEntry.stServiceStatus));
- /* WIN2K + extended service info */
- if (_st_apx_oslevel >= 4) {
- DWORD dwNeed;
- QueryServiceStatusEx(hSrv, SC_STATUS_PROCESS_INFO,
- (LPBYTE)(&(stEntry.stStatusProcess)),
- sizeof(SERVICE_STATUS_PROCESS),
- &dwNeed);
- }
- /* finaly call the provided callback */
- rv = (*fnDisplayCallback)(lpCbData, uMsg,
- (WPARAM)&stEntry,
- (LPARAM)nFound++);
- }
- }
- /* release the skipped service config */
- if (fm) {
- apxFree(stEntry.lpConfig);
- }
- }
- SAFE_CLOSE_SCH(hSrv);
- }
- if (!rv)
- break;
- }
-
- UnlockServiceDatabase(hLock);
- return nFound;
-}
Copied: tags/jbosssvc/2.0.8/procrun/src/service.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/service.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/service.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/service.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,669 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define SAFE_CLOSE_SCH(h) \
+ if ((h) != NULL && (h) != INVALID_HANDLE_VALUE) { \
+ CloseServiceHandle((h)); \
+ (h) = NULL; \
+ }
+
+#define CHANGE_SERVICE(h, b, u, p, d) \
+ ChangeServiceConfigW(h, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, \
+ SERVICE_NO_CHANGE,b,NULL,NULL,NULL, \
+ u,p,d)
+
+typedef struct APXSERVICE {
+ /* Are we a service manager or we are the service itself */
+ BOOL bManagerMode;
+ /* Handle to the current service */
+ SC_HANDLE hService;
+ /* Handle of the Service manager */
+ SC_HANDLE hManager;
+ APXSERVENTRY stServiceEntry;
+
+} APXSERVICE, *LPAPXSERVICE;
+
+static BOOL __apxIsValidServiceName(LPCWSTR szServiceName)
+{
+ do {
+ if (!IsCharAlphaNumericW(*szServiceName)) {
+ apxDisplayError(FALSE, NULL, 0, "NonAlpha %d", *szServiceName);
+ return FALSE;
+ }
+ } while( *(++szServiceName));
+ return TRUE;
+}
+
+static BOOL __apxServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXSERVICE lpService;
+
+ lpService = APXHANDLE_DATA(hObject);
+ switch (uMsg) {
+ case WM_CLOSE:
+ apxFree(lpService->stServiceEntry.lpConfig);
+ lpService->stServiceEntry.lpConfig = NULL;
+ SAFE_CLOSE_SCH(lpService->hService);
+ SAFE_CLOSE_SCH(lpService->hManager);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+APXHANDLE
+apxCreateService(APXHANDLE hPool, DWORD dwOptions, BOOL bManagerMode)
+{
+ APXHANDLE hService;
+ LPAPXSERVICE lpService;
+ SC_HANDLE hManager;
+
+ if (!(hManager = OpenSCManager(NULL, NULL, dwOptions))) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+ hService = apxHandleCreate(hPool, 0,
+ NULL, sizeof(APXSERVICE),
+ __apxServiceCallback);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to Create Handle for Service");
+ return NULL;
+ }
+ hService->dwType = APXHANDLE_TYPE_SERVICE;
+ lpService = APXHANDLE_DATA(hService);
+ lpService->hManager = hManager;
+ lpService->bManagerMode = bManagerMode;
+
+ return hService;
+}
+
+BOOL
+apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions)
+{
+ LPAPXSERVICE lpService;
+ DWORD dwNeeded;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+
+ /* Close any previous instance
+ * Same handle can manage multiple services
+ */
+ SAFE_CLOSE_SCH(lpService->hService);
+ *lpService->stServiceEntry.szServiceDescription = L'\0';
+ *lpService->stServiceEntry.szObjectName = L'\0';
+ apxFree(lpService->stServiceEntry.lpConfig);
+ lpService->stServiceEntry.lpConfig = NULL;
+ /* Open the service */
+ lpService->hService = OpenServiceW(lpService->hManager,
+ szServiceName,
+ dwOptions);
+
+ if (IS_INVALID_HANDLE(lpService->hService)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ lstrlcpyW(lpService->stServiceEntry.szServiceName, SIZ_RESLEN, szServiceName);
+ if (!apxGetServiceDescriptionW(szServiceName,
+ lpService->stServiceEntry.szServiceDescription,
+ SIZ_DESLEN)) {
+ apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service description");
+ lpService->stServiceEntry.szServiceDescription[0] = L'\0';
+ }
+ if (!apxGetServiceUserW(szServiceName,
+ lpService->stServiceEntry.szObjectName,
+ SIZ_RESLEN)) {
+ apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service user name");
+ lpService->stServiceEntry.szObjectName[0] = L'\0';
+ }
+ if (!QueryServiceConfigW(lpService->hService, NULL, 0, &dwNeeded)) {
+ if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ }
+ /* TODO: Check GetLastError ERROR_INSUFFICIENT_BUFFER */
+ lpService->stServiceEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
+ dwNeeded);
+ return QueryServiceConfigW(lpService->hService,
+ lpService->stServiceEntry.lpConfig,
+ dwNeeded, &dwNeeded);
+}
+
+LPAPXSERVENTRY
+apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return NULL;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return NULL;
+
+ if (bRequeryStatus && !QueryServiceStatus(lpService->hService,
+ &(lpService->stServiceEntry.stServiceStatus))) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+
+ return &lpService->stServiceEntry;
+}
+
+/* Set the service names etc...
+ * If the ImagePath contains a space, it must be quoted
+ */
+BOOL
+apxServiceSetNames(APXHANDLE hService,
+ LPCWSTR szImagePath,
+ LPCWSTR szDisplayName,
+ LPCWSTR szDescription,
+ LPCWSTR szUsername,
+ LPCWSTR szPassword)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServiceOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ if (!CHANGE_SERVICE(lpService->hService,
+ szImagePath,
+ szUsername,
+ szPassword,
+ szDisplayName)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ if (szDescription) {
+ return apxSetServiceDescriptionW(lpService->stServiceEntry.szServiceName,
+ szDescription);
+ }
+ return TRUE;
+}
+
+BOOL
+apxServiceSetOptions(APXHANDLE hService,
+ DWORD dwServiceType,
+ DWORD dwStartType,
+ DWORD dwErrorControl)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServixeOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ return ChangeServiceConfig(lpService->hService, dwServiceType,
+ dwStartType, dwErrorControl,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL);
+}
+
+static BOOL
+__apxStopDependentServices(LPAPXSERVICE lpService)
+{
+ DWORD i;
+ DWORD dwBytesNeeded;
+ DWORD dwCount;
+
+ LPENUM_SERVICE_STATUS lpDependencies = NULL;
+ ENUM_SERVICE_STATUS ess;
+ SC_HANDLE hDepService;
+ SERVICE_STATUS_PROCESS ssp;
+
+ DWORD dwStartTime = GetTickCount();
+ /* Use the 30-second time-out */
+ DWORD dwTimeout = 30000;
+
+ /* Pass a zero-length buffer to get the required buffer size.
+ */
+ if (EnumDependentServices(lpService->hService,
+ SERVICE_ACTIVE,
+ lpDependencies, 0,
+ &dwBytesNeeded,
+ &dwCount)) {
+ /* If the Enum call succeeds, then there are no dependent
+ * services, so do nothing.
+ */
+ return TRUE;
+ }
+ else {
+ if (GetLastError() != ERROR_MORE_DATA)
+ return FALSE; // Unexpected error
+
+ /* Allocate a buffer for the dependencies.
+ */
+ lpDependencies = (LPENUM_SERVICE_STATUS) HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ dwBytesNeeded);
+ if (!lpDependencies)
+ return FALSE;
+
+ __try {
+ /* Enumerate the dependencies. */
+ if (!EnumDependentServices(lpService->hService,
+ SERVICE_ACTIVE,
+ lpDependencies,
+ dwBytesNeeded,
+ &dwBytesNeeded,
+ &dwCount))
+ return FALSE;
+
+ for (i = 0; i < dwCount; i++) {
+ ess = *(lpDependencies + i);
+ /* Open the service. */
+ hDepService = OpenService(lpService->hManager,
+ ess.lpServiceName,
+ SERVICE_STOP | SERVICE_QUERY_STATUS);
+
+ if (!hDepService)
+ return FALSE;
+
+ __try {
+ /* Send a stop code. */
+ if (!ControlService(hDepService,
+ SERVICE_CONTROL_STOP,
+ (LPSERVICE_STATUS) &ssp))
+ return FALSE;
+
+ /* Wait for the service to stop. */
+ while (ssp.dwCurrentState != SERVICE_STOPPED) {
+ Sleep(ssp.dwWaitHint);
+ if (!QueryServiceStatusEx(hDepService,
+ SC_STATUS_PROCESS_INFO,
+ (LPBYTE)&ssp,
+ sizeof(SERVICE_STATUS_PROCESS),
+ &dwBytesNeeded))
+ return FALSE;
+
+ if (ssp.dwCurrentState == SERVICE_STOPPED)
+ break;
+
+ if (GetTickCount() - dwStartTime > dwTimeout)
+ return FALSE;
+ }
+ }
+ __finally {
+ /* Always release the service handle. */
+ CloseServiceHandle(hDepService);
+ }
+ }
+ }
+ __finally {
+ /* Always free the enumeration buffer. */
+ HeapFree(GetProcessHeap(), 0, lpDependencies);
+ }
+ }
+ return TRUE;
+}
+
+BOOL
+apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
+ LPAPXFNCALLBACK fnControlCallback,
+ LPVOID lpCbData)
+{
+ LPAPXSERVICE lpService;
+ SERVICE_STATUS stStatus;
+ DWORD dwPending = 0;
+ DWORD dwState = 0;
+ DWORD dwTick = 0;
+ DWORD dwWait, dwCheck, dwStart;
+ BOOL bStatus;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServiceOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ switch (dwControl) {
+ case SERVICE_CONTROL_CONTINUE:
+ dwPending = SERVICE_START_PENDING;
+ dwState = SERVICE_RUNNING;
+ break;
+ case SERVICE_CONTROL_STOP:
+ dwPending = SERVICE_STOP_PENDING;
+ dwState = SERVICE_STOPPED;
+ break;
+ case SERVICE_CONTROL_PAUSE:
+ dwPending = SERVICE_PAUSE_PENDING;
+ dwState = SERVICE_PAUSED;
+ break;
+ default:
+ break;
+ }
+ /* user defined controls */
+ if (dwControl > 127 && dwControl < 224) {
+ /* 128 ... 159 start signals
+ * 160 ... 191 stop signals
+ * 192 ... 223 pause signals
+ */
+ switch (dwControl & 0xE0) {
+ case 0x80:
+ case 0x90:
+ dwPending = SERVICE_START_PENDING;
+ dwState = SERVICE_RUNNING;
+ break;
+ case 0xA0:
+ case 0xB0:
+ dwPending = SERVICE_STOP_PENDING;
+ dwState = SERVICE_STOPPED;
+ break;
+ case 0xC0:
+ case 0xD0:
+ dwPending = SERVICE_PAUSE_PENDING;
+ dwState = SERVICE_PAUSED;
+ break;
+ default:
+ break;
+ }
+ }
+ if (!dwPending && !dwState)
+ return FALSE;
+ /* Now lets control */
+ if (!QueryServiceStatus(lpService->hService, &stStatus)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ /* signal that we are about to control the service */
+ if (fnControlCallback)
+ (*fnControlCallback)(lpCbData, uMsg, (WPARAM)1, (LPARAM)dwState);
+ if (dwControl == SERVICE_CONTROL_CONTINUE &&
+ stStatus.dwCurrentState != SERVICE_PAUSED)
+ bStatus = StartService(lpService->hService, 0, NULL);
+ else {
+ bStatus = TRUE;
+ if (dwControl == SERVICE_CONTROL_STOP) {
+ /* First stop dependent services
+ */
+ bStatus = __apxStopDependentServices(lpService);
+ }
+ if (bStatus)
+ bStatus = ControlService(lpService->hService, dwControl, &stStatus);
+ }
+ dwStart = GetTickCount();
+ dwCheck = stStatus.dwCheckPoint;
+ if (bStatus) {
+ Sleep(100); /* Initial Sleep period */
+ while (QueryServiceStatus(lpService->hService, &stStatus)) {
+ if (stStatus.dwCurrentState == dwPending) {
+ /* Do not wait longer than the wait hint. A good interval is
+ * one tenth the wait hint, but no less than 1 second and no
+ * more than 10 seconds.
+ */
+ dwWait = stStatus.dwWaitHint / 10;
+
+ if( dwWait < 1000 )
+ dwWait = 1000;
+ else if ( dwWait > 10000 )
+ dwWait = 10000;
+ /* Signal to the callback that we are pending
+ * break if callback returns false.
+ */
+ if (fnControlCallback) {
+ if (!(*fnControlCallback)(lpCbData, uMsg, (WPARAM)2,
+ (LPARAM)dwTick++))
+ break;
+ }
+ Sleep(dwWait);
+ if (stStatus.dwCheckPoint > dwCheck) {
+ /* The service is making progress. */
+ dwStart = GetTickCount();
+ dwCheck = stStatus.dwCheckPoint;
+ }
+ else {
+ if(GetTickCount() - dwStart > stStatus.dwWaitHint) {
+ /* No progress made within the wait hint */
+ break;
+ }
+ }
+ }
+ else
+ break;
+ }
+ }
+ /* signal that we are done with controling the service */
+ if (fnControlCallback)
+ (*fnControlCallback)(lpCbData, uMsg, (WPARAM)3, (LPARAM)0);
+ /* Check if we are in the desired state */
+ Sleep(1000);
+
+ if (QueryServiceStatus(lpService->hService, &stStatus)) {
+ if (fnControlCallback)
+ (*fnControlCallback)(lpCbData, uMsg, (WPARAM)4,
+ (LPARAM)&stStatus);
+ if (stStatus.dwCurrentState == dwState)
+ return TRUE;
+
+ }
+
+ return FALSE;
+}
+
+BOOL
+apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
+ LPCWSTR szDisplayName, LPCWSTR szImagePath,
+ LPCWSTR lpDependencies, DWORD dwServiceType,
+ DWORD dwStartType)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ if (IS_INVALID_HANDLE(lpService->hManager))
+ return FALSE;
+ if (!__apxIsValidServiceName(szServiceName))
+ return FALSE;
+ /* Close any previous instance
+ * Same handle can install multiple services
+ */
+ SAFE_CLOSE_SCH(lpService->hService);
+
+ apxFree(lpService->stServiceEntry.lpConfig);
+ lpService->stServiceEntry.lpConfig = NULL;
+ AplZeroMemory(&lpService->stServiceEntry, sizeof(APXSERVENTRY));
+
+ lpService->hService = CreateServiceW(lpService->hManager,
+ szServiceName,
+ szDisplayName,
+ SERVICE_ALL_ACCESS,
+ dwServiceType,
+ dwStartType,
+ SERVICE_ERROR_NORMAL,
+ szImagePath,
+ NULL,
+ NULL,
+ lpDependencies,
+ NULL,
+ NULL);
+
+ if (IS_INVALID_HANDLE(lpService->hService)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ else {
+ lstrlcpyW(lpService->stServiceEntry.szServiceName,
+ SIZ_RESLEN, szServiceName);
+ lpService->stServiceEntry.dwStart = dwStartType;
+ return TRUE;
+ }
+}
+
+BOOL
+apxServiceDelete(APXHANDLE hService)
+{
+ LPAPXSERVICE lpService;
+ SERVICE_STATUS stStatus;
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServiceOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ if (QueryServiceStatus(lpService->hService, &stStatus)) {
+ BOOL rv;
+ if (stStatus.dwCurrentState != SERVICE_STOPPED)
+ apxServiceControl(hService, SERVICE_CONTROL_STOP, 0, NULL, NULL);
+ rv = DeleteService(lpService->hService);
+ SAFE_CLOSE_SCH(lpService->hService);
+ SAFE_CLOSE_SCH(lpService->hManager);
+
+ return rv;
+ }
+ return FALSE;
+}
+
+/* Browse the services */
+DWORD
+apxServiceBrowse(APXHANDLE hService,
+ LPCWSTR szIncludeNamePattern,
+ LPCWSTR szIncludeImagePattern,
+ LPCWSTR szExcludeNamePattern,
+ LPCWSTR szExcludeImagePattern,
+ UINT uMsg,
+ LPAPXFNCALLBACK fnDisplayCallback,
+ LPVOID lpCbData)
+{
+ DWORD nFound = 0;
+ APXREGENUM stEnum;
+ LPAPXSERVICE lpService;
+ SC_LOCK hLock;
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE || !fnDisplayCallback)
+ return 0;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Only the manager mode can browse services */
+ if (!lpService->bManagerMode ||
+ IS_INVALID_HANDLE(lpService->hManager))
+ return 0;
+ hLock = LockServiceDatabase(lpService->hManager);
+ if (IS_INVALID_HANDLE(hLock)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+
+ return 0;
+ }
+ AplZeroMemory(&stEnum, sizeof(APXREGENUM));
+
+ while (TRUE) {
+ APXSERVENTRY stEntry;
+ BOOL rv;
+ AplZeroMemory(&stEntry, sizeof(APXSERVENTRY));
+ rv = apxRegistryEnumServices(&stEnum, &stEntry);
+
+ if (rv) {
+ INT fm = -1;
+ SC_HANDLE hSrv = NULL;
+ DWORD dwNeeded = 0;
+ hSrv = OpenServiceW(lpService->hManager,
+ stEntry.szServiceName,
+ GENERIC_READ);
+ if (!IS_INVALID_HANDLE(hSrv)) {
+ QueryServiceConfigW(hSrv, NULL, 0, &dwNeeded);
+ stEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
+ dwNeeded);
+ /* Call the QueryServiceConfig againg with allocated config */
+ if (QueryServiceConfigW(hSrv, stEntry.lpConfig, dwNeeded, &dwNeeded)) {
+ /* Make that customizable so that kernel mode drivers can be
+ * displayed and maintained. For now skip the
+ * filesystem and device drivers.
+ * XXX: Do we need that customizable after all?
+ */
+ if ((stEntry.lpConfig->dwServiceType &
+ ~SERVICE_INTERACTIVE_PROCESS) & SERVICE_WIN32)
+ fm = 0;
+
+ if (!fm && szIncludeNamePattern) {
+ fm = apxMultiStrMatchW(stEntry.szServiceName,
+ szIncludeNamePattern, L';', TRUE);
+ }
+ if (!fm && szExcludeNamePattern) {
+ fm = !apxMultiStrMatchW(stEntry.szServiceName,
+ szExcludeNamePattern, L';', TRUE);
+ }
+ if (!fm && szIncludeImagePattern) {
+ fm = apxMultiStrMatchW(stEntry.lpConfig->lpBinaryPathName,
+ szIncludeImagePattern, L';', TRUE);
+ }
+ if (!fm && szExcludeImagePattern) {
+ fm = !apxMultiStrMatchW(stEntry.szServiceName,
+ szExcludeImagePattern, L';', TRUE);
+ }
+ if (!fm) {
+ QueryServiceStatus(hSrv, &(stEntry.stServiceStatus));
+ /* WIN2K + extended service info */
+ if (_st_apx_oslevel >= 4) {
+ DWORD dwNeed;
+ QueryServiceStatusEx(hSrv, SC_STATUS_PROCESS_INFO,
+ (LPBYTE)(&(stEntry.stStatusProcess)),
+ sizeof(SERVICE_STATUS_PROCESS),
+ &dwNeed);
+ }
+ /* finaly call the provided callback */
+ rv = (*fnDisplayCallback)(lpCbData, uMsg,
+ (WPARAM)&stEntry,
+ (LPARAM)nFound++);
+ }
+ }
+ /* release the skipped service config */
+ if (fm) {
+ apxFree(stEntry.lpConfig);
+ }
+ }
+ SAFE_CLOSE_SCH(hSrv);
+ }
+ if (!rv)
+ break;
+ }
+
+ UnlockServiceDatabase(hLock);
+ return nFound;
+}
Deleted: tags/jbosssvc/2.0.8/procrun/src/utils.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/utils.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ tags/jbosssvc/2.0.8/procrun/src/utils.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -1,1037 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apxwin.h"
-#include "private.h"
-
-APX_OSLEVEL _st_apx_oslevel = APX_WINVER_UNK;
-
-/* Apache's APR stripped Os level detection */
-APX_OSLEVEL apxGetOsLevel()
-{
- if (_st_apx_oslevel == APX_WINVER_UNK) {
- static OSVERSIONINFO oslev;
- oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&oslev);
-
- if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT) {
- if (oslev.dwMajorVersion < 4)
- _st_apx_oslevel = APX_WINVER_UNSUP;
- else if (oslev.dwMajorVersion == 4)
- _st_apx_oslevel = APX_WINVER_NT_4;
- else if (oslev.dwMajorVersion == 5) {
- if (oslev.dwMinorVersion == 0)
- _st_apx_oslevel = APX_WINVER_2000;
- else
- _st_apx_oslevel = APX_WINVER_XP;
- }
- else
- _st_apx_oslevel = APX_WINVER_XP;
- }
-#ifndef WINNT
- else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
- if (oslev.dwMinorVersion < 10)
- _st_apx_oslevel = APX_WINVER_95;
- else if (oslev.dwMinorVersion < 90)
- _st_apx_oslevel = APX_WINVER_98;
- else
- _st_apx_oslevel = APX_WINVER_ME;
- }
-#endif
-#ifdef _WIN32_WCE
- else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE) {
- if (oslev.dwMajorVersion < 3)
- _st_apx_oslevel = APX_WINVER_UNSUP;
- else
- _st_apx_oslevel = APX_WINVER_CE_3;
- }
-#endif
- else
- _st_apx_oslevel = APX_WINVER_UNSUP;
- }
-
- if (_st_apx_oslevel < APX_WINVER_UNSUP)
- return APX_WINVER_UNK;
- else
- return _st_apx_oslevel;
-}
-
-LPWSTR __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName)
-{
- LPWSTR wsRet;
- DWORD rc;
-
- rc = GetEnvironmentVariableW(wsName, NULL, 0);
- if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
- return NULL;
-
- if (!(wsRet = apxPoolAlloc(hPool, (rc + 1) * sizeof(WCHAR))))
- return NULL;
- if (!GetEnvironmentVariableW(wsName, wsRet, rc)) {
- apxFree(wsRet);
- ErrorMessage(NULL, FALSE);
- return NULL;
- }
- return wsRet;
-}
-
-LPSTR __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName)
-{
- LPSTR szRet;
- DWORD rc;
-
- rc = GetEnvironmentVariableA(szName, NULL, 0);
- if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
- return NULL;
-
- if (!(szRet = apxPoolAlloc(hPool, rc + 1)))
- return NULL;
- if (!GetEnvironmentVariableA(szName, szRet, rc)) {
- apxFree(szRet);
- ErrorMessage(NULL, FALSE);
- return NULL;
- }
- return szRet;
-}
-
-
-LPWSTR AsciiToWide(LPCSTR s, LPWSTR ws)
-{
- LPWSTR pszSave = ws;
-
- if (!s) {
- *ws = L'\0';
- return pszSave;
- }
- do {
- *ws++ = (WCHAR)*s;
- } while (*s++);
- return pszSave;
-}
-
-LPSTR WideToAscii(LPCWSTR ws, LPSTR s)
-{
- LPSTR pszSave = s;
-
- if (!ws) {
- *s = '\0';
- return pszSave;
- }
- do {
- *s++ = (CHAR)*ws;
- } while( *ws++);
- return pszSave;
-}
-
-LPSTR WideToUTF8(LPCWSTR ws)
-{
-
- LPSTR s;
- int cch = WideCharToMultiByte(CP_UTF8, 0, ws, -1, NULL, 0, NULL, NULL);
- s = (LPSTR)apxAlloc(cch);
- if (!WideCharToMultiByte(CP_UTF8, 0, ws, -1, s, cch, NULL, NULL)) {
- apxFree(s);
- return NULL;
- }
- return s;
-}
-
-LPSTR MzWideToAscii(LPCWSTR ws, LPSTR s)
-{
- LPSTR pszSave = s;
-
- if (ws) {
- do {
- *s++ = (CHAR)*ws;
- ws++;
- } while( *ws || *(ws + 1));
- }
- /* double terminate */
- *s++ = '\0';
- *s = '\0';
- return pszSave;
-}
-
-LPSTR MzWideToUTF8(LPCWSTR ws)
-{
- LPSTR str;
- LPSTR s;
- LPCWSTR p = ws;
- int cch = 0;
-
- for ( ; p && *p; p++) {
- int len = WideCharToMultiByte(CP_UTF8, 0, p, -1, NULL, 0, NULL, NULL);
- if (len > 0)
- cch += len;
- while (*p)
- p++;
- }
- cch ++;
- str = s = (LPSTR)apxAlloc(cch + 1);
-
- p = ws;
- for ( ; p && *p; p++) {
- int len = WideCharToMultiByte(CP_UTF8, 0, p, -1, s, cch, NULL, NULL);
- if (len > 0) {
- s = s + len;
- cch -= len;
- }
- while (*p)
- p++;
- }
- /* double terminate */
- *s = '\0';
- return str;
-}
-
-#ifdef _DEBUG
-
-void ErrorMessage(LPCTSTR szError, BOOL bFatal)
-{
- LPVOID lpMsgBuf = NULL;
- UINT nType;
- int nRet;
- DWORD dwErr = GetLastError();
- if (bFatal)
- nType = MB_ICONERROR | MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL;
- else
- nType = MB_ICONEXCLAMATION | MB_OK;
- if (szError) {
- nRet = MessageBox(NULL, szError, TEXT("Application Error"), nType);
- }
- else {
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwErr,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
- (LPTSTR) &lpMsgBuf, 0, NULL);
- nRet = MessageBox(NULL, (LPCTSTR)lpMsgBuf,
- TEXT("Application System Error"), nType);
- LocalFree(lpMsgBuf);
- }
- if (bFatal && (nRet == IDCANCEL || nRet == IDABORT)) {
- ExitProcess(dwErr);
- }
-}
-#endif /* _DEBUG */
-
-DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount)
-{
- LPCSTR p = lpStr;
- if (lpdwCount)
- *lpdwCount = 0;
- for ( ; p && *p; p++) {
- if (lpdwCount)
- *lpdwCount += 1;
- while (*p)
- p++;
- }
- return (DWORD)(p - lpStr);
-}
-
-DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount)
-{
- LPCWSTR p = lpStr;
- if (lpdwCount)
- *lpdwCount = 0;
- for ( ; p && *p; p++) {
- if (lpdwCount)
- *lpdwCount += 1;
- while (*p)
- p++;
- }
- return (DWORD)((p - lpStr));
-}
-
-LPWSTR apxMultiSzCombine(APXHANDLE hPool, LPCWSTR lpStrA, LPCWSTR lpStrB,
- LPDWORD lpdwLength)
-{
- LPWSTR rv;
- DWORD la = 0, lb = 0;
- if (!lpStrA && !lpStrB)
- return NULL; /* Nothing to do if both are NULL */
-
- la = __apxGetMultiSzLengthW(lpStrA, NULL);
- lb = __apxGetMultiSzLengthW(lpStrB, NULL);
-
- rv = apxPoolCalloc(hPool, (la + lb + 1) * sizeof(WCHAR));
- if (la) {
- AplMoveMemory(rv, lpStrA, la * sizeof(WCHAR));
- }
- if (lb) {
- AplMoveMemory(&rv[la], lpStrB, lb * sizeof(WCHAR));
- }
- if (*lpdwLength)
- *lpdwLength = (la + lb + 1) * sizeof(WCHAR);
- return rv;
-}
-
-BOOL
-apxSetEnvironmentVariable(APXHANDLE hPool, LPCTSTR szName, LPCTSTR szValue,
- BOOL bAppend)
-{
- LPTSTR szNew = (LPTSTR)szValue;
-
- if (bAppend) {
- DWORD l = GetEnvironmentVariable(szName, NULL, 0);
- if (l > 0) {
- BOOL rv;
- if (IS_INVALID_HANDLE(hPool))
- szNew = apxAlloc(l + lstrlen(szValue) + 3);
- else
- szNew = apxPoolAlloc(hPool, l + lstrlen(szValue) + 3);
- GetEnvironmentVariable(szName, szNew, l + 1);
- lstrcat(szNew, TEXT(";"));
- lstrcat(szNew, szValue);
- rv = SetEnvironmentVariable(szName, szNew);
- apxFree(szNew);
- return rv;
- }
- }
- return SetEnvironmentVariable(szName, szNew);
-}
-
-
-/** Convert null separated double null terimated string to LPTSTR array)
- * returns array size
- */
-DWORD
-apxMultiSzToArrayW(APXHANDLE hPool, LPCWSTR lpString, LPWSTR **lppArray)
-{
- DWORD i, n, l;
- char *buff;
- LPWSTR p;
-
- l = __apxGetMultiSzLengthW(lpString, &n);
- if (!n || !l)
- return 0;
- if (IS_INVALID_HANDLE(hPool))
- buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
- else
- buff = apxAlloc((n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
-
- *lppArray = (LPWSTR *)buff;
- p = (LPWSTR)(buff + (n + 2) * sizeof(LPWSTR));
- AplCopyMemory(p, lpString, (l + 1) * sizeof(WCHAR) + sizeof(WCHAR));
- for (i = 0; i < n; i++) {
- (*lppArray)[i] = p;
- while (*p)
- p++;
- p++;
- }
- (*lppArray)[++i] = NULL;
-
- return n;
-}
-
-DWORD
-apxMultiSzToArrayA(APXHANDLE hPool, LPCSTR lpString, LPSTR **lppArray)
-{
- DWORD i, n, l;
- char *buff;
- LPSTR p;
-
- l = __apxGetMultiSzLengthA(lpString, &n);
- if (!n || !l)
- return 0;
- if (IS_INVALID_HANDLE(hPool))
- buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPTSTR) + (l + 1));
- else
- buff = apxAlloc((n + 2) * sizeof(LPSTR) + (l + 1) * sizeof(CHAR));
-
- *lppArray = (LPSTR *)buff;
- p = (LPSTR)(buff + (n + 2) * sizeof(LPSTR));
- AplCopyMemory(p, lpString, (l + 1) * sizeof(CHAR) + sizeof(CHAR));
- for (i = 0; i < n; i++) {
- (*lppArray)[i] = p;
- while (*p)
- p++;
- p++;
- }
- (*lppArray)[++i] = NULL;
-
- return n;
-}
-
-#define QSTR_BOUNDARY 127
-#define QSTR_ALIGN(size) \
- (((size) + QSTR_BOUNDARY + sizeof(APXMULTISZ) + 2) & ~(QSTR_BOUNDARY))
-
-#define QSTR_SIZE(size) \
- ((QSTR_ALIGN(size)) - sizeof(APXMULTISZ))
-
-#define QSTR_DATA(q) ((char *)(q) + sizeof(APXMULTISZ))
-
-#if 0
-LPAPXMULTISZ apxMultiSzStrdup(LPCTSTR szSrc)
-{
- LPAPXMULTISZ q;
-
- if (szSrc) {
- DWORD l = lstrlen(szSrc);
- q = (LPAPXMULTISZ)apxAlloc(QSTR_ALIGN(l));
- q->dwAllocated = QSTR_SIZE(l);
- q->dwInsert = l + 1;
- AplMoveMemory(QSTR_DATA(q), szSrc, l);
- RtlZeroMemory(QSTR_DATA(q) + l, q->dwAllocated - l);
- }
- else {
- q = (LPAPXMULTISZ)apxCalloc(QSTR_ALIGN(0));
- q->dwAllocated = QSTR_SIZE(0);
- }
-
- return q;
-}
-
-LPTSTR apxMultiSzStrcat(LPAPXMULTISZ lpmSz, LPCTSTR szSrc)
-{
- DWORD l = lstrlen(szSrc);
- LPTSTR p;
-
- if (lpmSz->dwInsert + l + 2 > lpmSz->dwAllocated) {
- if ((lpmSz = (LPAPXMULTISZ )apxRealloc(lpmSz, QSTR_ALIGN(lpmSz->dwInsert + l))) == NULL)
- return NULL;
-
- lpmSz->dwAllocated = QSTR_SIZE(lpmSz->dwInsert + l);
- AplZeroMemory(QSTR_DATA(lpmSz) + lpmSz->dwInsert + l,
- lpmSz->dwAllocated - (lpmSz->dwInsert + l));
- }
- p = (LPTSTR)QSTR_DATA(lpmSz) + lpmSz->dwInsert;
- AplMoveMemory(p, szSrc, l);
-
- lpmSz->dwInsert += (l + 1);
- return p;
-}
-
-DWORD apxMultiSzLen(LPAPXMULTISZ lpmSz)
-{
- if (lpmSz->dwInsert)
- return lpmSz->dwInsert - 1;
- else
- return 0;
-}
-
-LPCTSTR apxMultiSzGet(LPAPXMULTISZ lpmSz)
-{
- return (LPCTSTR)QSTR_DATA(lpmSz);
-}
-#endif
-
-LPTSTR apxStrCharRemove(LPTSTR szString, TCHAR chSkip)
-{
- LPTSTR p = szString;
- LPTSTR q = szString;
- while (*p) {
- if(*p != chSkip)
- *q++ = *p;
- ++p;
- }
- *q = TEXT('\0');
-
- return szString;
-}
-
-DWORD apxStrCharRemoveA(LPSTR szString, CHAR chSkip)
-{
- LPSTR p = szString;
- LPSTR q = szString;
- DWORD c = 0;
- while (*p) {
- if(*p != chSkip)
- *q++ = *p;
- else
- ++c;
- ++p;
- }
- *q = '\0';
-
- return c;
-}
-
-DWORD apxStrCharRemoveW(LPWSTR szString, WCHAR chSkip)
-{
- LPWSTR p = szString;
- LPWSTR q = szString;
- DWORD c = 0;
- while (*p) {
- if(*p != chSkip)
- *q++ = *p;
- else
- ++c;
- ++p;
- }
- *q = L'\0';
-
- return c;
-}
-
-void
-apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith)
-{
- LPSTR p = szString;
- LPSTR q = szString;
- while (*p) {
- if(*p == chReplace)
- *q++ = chReplaceWith;
- else
- *q++ = *p;
- ++p;
- }
- *q = '\0';
-}
-
-void
-apxStrCharReplaceW(LPWSTR szString, WCHAR chReplace, WCHAR chReplaceWith)
-{
- LPWSTR p = szString;
- LPWSTR q = szString;
- while (*p) {
- if(*p == chReplace)
- *q++ = chReplaceWith;
- else
- *q++ = *p;
- ++p;
- }
- *q = L'\0';
-}
-
-static const LPCTSTR _st_hex = TEXT("0123456789abcdef");
-#define XTOABUFFER_SIZE (sizeof(ULONG) * 2 + 2)
-#define UTOABUFFER_SIZE (sizeof(ULONG_PTR) * 2 + 2)
-#define LO_NIBLE(x) ((BYTE)((x) & 0x0000000F))
-
-BOOL apxUltohex(ULONG n, LPTSTR lpBuff, DWORD dwBuffLength)
-{
- LPTSTR p;
- DWORD i;
- *lpBuff = 0;
- if (dwBuffLength < XTOABUFFER_SIZE)
- return FALSE;
- p = lpBuff + XTOABUFFER_SIZE;
- *p-- = 0;
- for (i = 0; i < sizeof(ULONG) * 2; i++) {
- *p-- = _st_hex[LO_NIBLE(n)];
- n = n >> 4;
- }
- *p-- = TEXT('x');
- *p = TEXT('0');
- return TRUE;
-}
-
-BOOL apxUptohex(ULONG_PTR n, LPTSTR lpBuff, DWORD dwBuffLength)
-{
- LPTSTR p;
- DWORD i;
- *lpBuff = 0;
- if (dwBuffLength < UTOABUFFER_SIZE)
- return FALSE;
- p = lpBuff + UTOABUFFER_SIZE;
- *p-- = 0;
- for (i = 0; i < sizeof(ULONG_PTR) * 2; i++) {
- *p-- = _st_hex[LO_NIBLE(n)];
- n = n >> 4;
- }
- *p-- = TEXT('x');
- *p = TEXT('0');
- return TRUE;
-}
-
-ULONG apxStrToul(LPCTSTR szNum)
-{
- ULONG rv = 0;
- DWORD sh = 0;
- LPCTSTR p = szNum;
- ++p;
- while (*p && (*p != TEXT('x')) && (*(p - 1) != TEXT('0')))
- p++;
- if (*p != 'x')
- return 0;
- /* go to the last digit */
- while (*(p + 1)) p++;
-
- /* go back to 'x' */
- while (*p != TEXT('x')) {
- ULONG v = 0;
- switch (*p--) {
- case TEXT('0'): v = 0UL; break;
- case TEXT('1'): v = 1UL; break;
- case TEXT('2'): v = 2UL; break;
- case TEXT('3'): v = 3UL; break;
- case TEXT('4'): v = 4UL; break;
- case TEXT('5'): v = 5UL; break;
- case TEXT('6'): v = 6UL; break;
- case TEXT('7'): v = 7UL; break;
- case TEXT('8'): v = 8UL; break;
- case TEXT('9'): v = 9UL; break;
- case TEXT('a'): case TEXT('A'): v = 10UL; break;
- case TEXT('b'): case TEXT('B'): v = 11UL; break;
- case TEXT('c'): case TEXT('C'): v = 12UL; break;
- case TEXT('d'): case TEXT('D'): v = 13UL; break;
- case TEXT('e'): case TEXT('E'): v = 14UL; break;
- case TEXT('f'): case TEXT('F'): v = 15UL; break;
- default:
- return 0;
- break;
- }
- rv |= rv + (v << sh);
- sh += 4;
- }
- return rv;
-}
-
-ULONG apxStrToulW(LPCWSTR szNum)
-{
- ULONG rv = 0;
- DWORD sh = 0;
- LPCWSTR p = szNum;
- ++p;
- while (*p && (*p != L'x') && (*(p - 1) != L'0'))
- p++;
- if (*p != L'x')
- return 0;
- /* go to the last digit */
- while (*(p + 1)) p++;
-
- /* go back to 'x' */
- while (*p != L'x') {
- ULONG v = 0;
- switch (*p--) {
- case L'0': v = 0UL; break;
- case L'1': v = 1UL; break;
- case L'2': v = 2UL; break;
- case L'3': v = 3UL; break;
- case L'4': v = 4UL; break;
- case L'5': v = 5UL; break;
- case L'6': v = 6UL; break;
- case L'7': v = 7UL; break;
- case L'8': v = 8UL; break;
- case L'9': v = 9UL; break;
- case L'a': case L'A': v = 10UL; break;
- case L'b': case L'B': v = 11UL; break;
- case L'c': case L'C': v = 12UL; break;
- case L'd': case L'D': v = 13UL; break;
- case L'e': case L'E': v = 14UL; break;
- case L'f': case L'F': v = 15UL; break;
- default:
- return 0;
- break;
- }
- rv |= rv + (v << sh);
- sh += 4;
- }
- return rv;
-}
-
-ULONG apxAtoulW(LPCWSTR szNum)
-{
- ULONG rv = 0;
- DWORD sh = 1;
- int s = 1;
- LPCWSTR p = szNum;
-
- /* go to the last digit */
- if (!p || !*p)
- return 0;
- if (*p == L'-') {
- s = -1;
- ++p;
- }
- while (*(p + 1)) p++;
-
- /* go back */
- while (p >= szNum) {
- ULONG v = 0;
- switch (*p--) {
- case L'0': v = 0UL; break;
- case L'1': v = 1UL; break;
- case L'2': v = 2UL; break;
- case L'3': v = 3UL; break;
- case L'4': v = 4UL; break;
- case L'5': v = 5UL; break;
- case L'6': v = 6UL; break;
- case L'7': v = 7UL; break;
- case L'8': v = 8UL; break;
- case L'9': v = 9UL; break;
- default:
- return rv * s;
- break;
- }
- rv = rv + (v * sh);
- sh = sh * 10;
- }
- return rv * s;
-}
-
-/* Make the unique system resource name from prefix and process id
- *
- */
-BOOL
-apxMakeResourceName(LPCTSTR szPrefix, LPTSTR lpBuff, DWORD dwBuffLength)
-{
- DWORD pl = lstrlen(szPrefix);
- if (dwBuffLength < (pl + 11))
- return FALSE;
- lstrcpy(lpBuff, szPrefix);
- return apxUltohex(GetCurrentProcessId(), lpBuff + pl, dwBuffLength - pl);
-}
-/** apxStrMatchA ANSI string pattern matching
- * Match = 0, NoMatch = 1, Abort = -1
- * Based loosely on sections of wildmat.c by Rich Salz
- */
-INT apxStrMatchA(LPCSTR szString, LPCSTR szPattern, BOOL bIgnoreCase)
-{
- int x, y;
-
- for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
- if (!szPattern[x] && (szPattern[y] != '*' || szPattern[y] != '?'))
- return -1;
- if (szPattern[y] == '*') {
- while (szPattern[++y] == '*');
- if (!szPattern[y])
- return 0;
- while (szString[x]) {
- INT rc;
- if ((rc = apxStrMatchA(&szString[x++], &szPattern[y],
- bIgnoreCase)) != 1)
- return rc;
- }
- return -1;
- }
- else if (szPattern[y] != '?') {
- if (bIgnoreCase) {
- if (CharLowerA((LPSTR)((SIZE_T)szString[x])) !=
- CharLowerA((LPSTR)((SIZE_T)szPattern[y])))
- return 1;
- }
- else {
- if (szString[x] != szPattern[y])
- return 1;
- }
- }
- }
- return (szString[x] != '\0');
-}
-
-INT apxStrMatchW(LPCWSTR szString, LPCWSTR szPattern, BOOL bIgnoreCase)
-{
- int x, y;
-
- for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
- if (!szPattern[x] && (szPattern[y] != L'*' || szPattern[y] != L'?'))
- return -1;
- if (szPattern[y] == L'*') {
- while (szPattern[++y] == L'*');
- if (!szPattern[y])
- return 0;
- while (szString[x]) {
- INT rc;
- if ((rc = apxStrMatchW(&szString[x++], &szPattern[y],
- bIgnoreCase)) != 1)
- return rc;
- }
- return -1;
- }
- else if (szPattern[y] != L'?') {
- if (bIgnoreCase) {
- if (CharLowerW((LPWSTR)((SIZE_T)szString[x])) !=
- CharLowerW((LPWSTR)((SIZE_T)szPattern[y])))
- return 1;
- }
- else {
- if (szString[x] != szPattern[y])
- return 1;
- }
- }
- }
- return (szString[x] != L'\0');
-}
-
-INT apxMultiStrMatchW(LPCWSTR szString, LPCWSTR szPattern,
- WCHAR chSeparator, BOOL bIgnoreCase)
-{
- WCHAR szM[SIZ_HUGLEN];
- DWORD i = 0;
- LPCWSTR p = szPattern;
- INT m = -1;
-
- if (chSeparator == 0)
- return apxStrMatchW(szString, szPattern, bIgnoreCase);
- while (*p != L'\0') {
- if (*p == chSeparator) {
- m = apxStrMatchW(szString, szM, bIgnoreCase);
- if (m == 0)
- return 0;
- p++;
- i = 0;
- szM[0] = L'\0';
- }
- else {
- if (i < SIZ_HUGMAX)
- szM[i++] = *p++;
- else
- return -1;
- }
- }
- szM[i] = L'\0';
- if (szM[0])
- return apxStrMatchW(szString, szM, bIgnoreCase);
- else
- return m;
-}
-
-LPSTR apxArrayToMultiSzA(APXHANDLE hPool, DWORD nArgs, LPCSTR *lpArgs)
-{
- DWORD i, l = 0;
- LPSTR lpSz, p;
- if (!nArgs)
- return NULL;
- for (i = 0; i < nArgs; i++)
- l += lstrlenA(lpArgs[i]);
- l += (nArgs + 2);
-
- p = lpSz = (LPSTR)apxPoolAlloc(hPool, l);
- for (i = 0; i < nArgs; i++) {
- lstrcpyA(p, lpArgs[i]);
- p += lstrlenA(lpArgs[i]);
- *p++ = '\0';
- }
- *p++ = '\0';
- *p++ = '\0';
- return lpSz;
-}
-
-void apxStrQuoteInplaceW(LPWSTR szString)
-{
- LPWSTR p = szString;
- BOOL needsQuote = FALSE;
- while (*p) {
- if (*p++ == L' ') {
- needsQuote = TRUE;
- break;
- }
- }
- if (needsQuote) {
- DWORD l = lstrlenW(szString);
- AplMoveMemory(&szString[1], szString, l * sizeof(WCHAR));
- szString[0] = L'"';
- szString[++l] = L'"';
- szString[++l] = L'\0';
- }
-}
-
-DWORD apxStrUnQuoteInplaceA(LPSTR szString)
-{
- LPSTR p = szString;
- BOOL needsQuote = FALSE;
- BOOL inQuote = FALSE;
- while (*p) {
- if (*p == '"') {
- if (inQuote)
- break;
- else
- inQuote = TRUE;
- }
- else if (*p == ' ') {
- if (inQuote) {
- needsQuote = TRUE;
- break;
- }
- }
- ++p;
- }
- if (!needsQuote)
- return apxStrCharRemoveA(szString, '"');
- else
- return 0;
-}
-
-DWORD apxStrUnQuoteInplaceW(LPWSTR szString)
-{
- LPWSTR p = szString;
- BOOL needsQuote = FALSE;
- BOOL inQuote = FALSE;
- while (*p) {
- if (*p == L'"') {
- if (inQuote)
- break;
- else
- inQuote = TRUE;
- }
- else if (*p == L' ') {
- if (inQuote) {
- needsQuote = TRUE;
- break;
- }
- }
- ++p;
- }
- if (!needsQuote)
- return apxStrCharRemoveW(szString, L'"');
- else
- return 0;
-}
-
-LPWSTR
-apxMszToCRLFW(APXHANDLE hPool, LPCWSTR szStr)
-{
- DWORD l, c;
- LPWSTR rv, b;
- LPCWSTR p = szStr;
-
- l = __apxGetMultiSzLengthW(szStr, &c);
- b = rv = apxPoolCalloc(hPool, (l + c + 2) * sizeof(WCHAR));
-
- while (c > 0) {
- if (*p)
- *b++ = *p;
- else {
- *b++ = L'\r';
- *b++ = L'\n';
- c--;
- }
- p++;
- }
- return rv;
-}
-
-LPWSTR
-apxCRLFToMszW(APXHANDLE hPool, LPCWSTR szStr, LPDWORD lpdwBytes)
-{
- DWORD l, c, n = 0;
- LPWSTR rv, b;
-
- l = lstrlenW(szStr);
- b = rv = apxPoolCalloc(hPool, (l + 2) * sizeof(WCHAR));
- for (c = 0; c < l; c++) {
- if (szStr[c] == L'\r') {
- *b++ = '\0';
- n++;
- }
- else if (szStr[c] != L'\n') {
- *b++ = szStr[c];
- n++;
- }
- }
- if (lpdwBytes)
- *lpdwBytes = (n + 2) * sizeof(WCHAR);
- return rv;
-}
-
-LPSTR
-apxExpandStrA(APXHANDLE hPool, LPCSTR szString)
-{
- LPCSTR p = szString;
- while (*p) {
- if (*p == '%') {
- p = szString;
- break;
- }
- ++p;
- }
- if (p != szString)
- return apxPoolStrdupA(hPool, szString);
- else {
- DWORD l = ExpandEnvironmentStringsA(szString, NULL, 0);
- if (l) {
- LPSTR rv = apxPoolAlloc(hPool, l);
- l = ExpandEnvironmentStringsA(szString, rv, l);
- if (l)
- return rv;
- else {
- apxFree(rv);
- return NULL;
- }
- }
- else
- return NULL;
- }
-}
-
-LPWSTR
-apxExpandStrW(APXHANDLE hPool, LPCWSTR szString)
-{
- LPCWSTR p = szString;
- while (*p) {
- if (*p == L'%') {
- p = szString;
- break;
- }
- ++p;
- }
- if (p != szString)
- return apxPoolStrdupW(hPool, szString);
- else {
- DWORD l = ExpandEnvironmentStringsW(szString, NULL, 0);
- if (l) {
- LPWSTR rv = apxPoolAlloc(hPool, l * sizeof(WCHAR));
- l = ExpandEnvironmentStringsW(szString, rv, l);
- if (l)
- return rv;
- else {
- apxFree(rv);
- return NULL;
- }
- }
- else
- return NULL;
- }
-}
-
-/* To share the semaphores with other processes, we need a NULL ACL
- * Code from MS KB Q106387
- */
-PSECURITY_ATTRIBUTES GetNullACL()
-{
- PSECURITY_DESCRIPTOR pSD;
- PSECURITY_ATTRIBUTES sa;
-
- sa = (PSECURITY_ATTRIBUTES) LocalAlloc(LPTR, sizeof(SECURITY_ATTRIBUTES));
- sa->nLength = sizeof(sizeof(SECURITY_ATTRIBUTES));
-
- pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
- sa->lpSecurityDescriptor = pSD;
-
- if (pSD == NULL || sa == NULL) {
- return NULL;
- }
- SetLastError(0);
- if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
- || GetLastError()) {
- LocalFree( pSD );
- LocalFree( sa );
- return NULL;
- }
- if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)
- || GetLastError()) {
- LocalFree( pSD );
- LocalFree( sa );
- return NULL;
- }
-
- sa->bInheritHandle = FALSE;
- return sa;
-}
-
-
-void CleanNullACL(void *sa)
-{
- if (sa) {
- LocalFree(((PSECURITY_ATTRIBUTES)sa)->lpSecurityDescriptor);
- LocalFree(sa);
- }
-}
Copied: tags/jbosssvc/2.0.8/procrun/src/utils.c (from rev 2689, trunk/utils/windows/native/service/procrun/src/utils.c)
===================================================================
--- tags/jbosssvc/2.0.8/procrun/src/utils.c (rev 0)
+++ tags/jbosssvc/2.0.8/procrun/src/utils.c 2010-07-21 20:14:05 UTC (rev 2690)
@@ -0,0 +1,1017 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+APX_OSLEVEL _st_apx_oslevel = APX_WINVER_UNK;
+
+/* Apache's APR stripped Os level detection */
+APX_OSLEVEL apxGetOsLevel()
+{
+ if (_st_apx_oslevel == APX_WINVER_UNK) {
+ static OSVERSIONINFO oslev;
+ oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&oslev);
+
+ if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+ if (oslev.dwMajorVersion < 4)
+ _st_apx_oslevel = APX_WINVER_UNSUP;
+ else if (oslev.dwMajorVersion == 4)
+ _st_apx_oslevel = APX_WINVER_NT_4;
+ else if (oslev.dwMajorVersion == 5) {
+ if (oslev.dwMinorVersion == 0)
+ _st_apx_oslevel = APX_WINVER_2000;
+ else
+ _st_apx_oslevel = APX_WINVER_XP;
+ }
+ else
+ _st_apx_oslevel = APX_WINVER_XP;
+ }
+#ifndef WINNT
+ else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+ if (oslev.dwMinorVersion < 10)
+ _st_apx_oslevel = APX_WINVER_95;
+ else if (oslev.dwMinorVersion < 90)
+ _st_apx_oslevel = APX_WINVER_98;
+ else
+ _st_apx_oslevel = APX_WINVER_ME;
+ }
+#endif
+#ifdef _WIN32_WCE
+ else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE) {
+ if (oslev.dwMajorVersion < 3)
+ _st_apx_oslevel = APX_WINVER_UNSUP;
+ else
+ _st_apx_oslevel = APX_WINVER_CE_3;
+ }
+#endif
+ else
+ _st_apx_oslevel = APX_WINVER_UNSUP;
+ }
+
+ if (_st_apx_oslevel < APX_WINVER_UNSUP)
+ return APX_WINVER_UNK;
+ else
+ return _st_apx_oslevel;
+}
+
+LPWSTR __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName)
+{
+ LPWSTR wsRet;
+ DWORD rc;
+
+ rc = GetEnvironmentVariableW(wsName, NULL, 0);
+ if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+ return NULL;
+
+ if (!(wsRet = apxPoolAlloc(hPool, (rc + 1) * sizeof(WCHAR))))
+ return NULL;
+ if (!GetEnvironmentVariableW(wsName, wsRet, rc)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ apxFree(wsRet);
+ return NULL;
+ }
+ return wsRet;
+}
+
+LPSTR __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName)
+{
+ LPSTR szRet;
+ DWORD rc;
+
+ rc = GetEnvironmentVariableA(szName, NULL, 0);
+ if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+ return NULL;
+
+ if (!(szRet = apxPoolAlloc(hPool, rc + 1)))
+ return NULL;
+ if (!GetEnvironmentVariableA(szName, szRet, rc)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ apxFree(szRet);
+ return NULL;
+ }
+ return szRet;
+}
+
+
+LPWSTR AsciiToWide(LPCSTR s, LPWSTR ws)
+{
+ LPWSTR pszSave = ws;
+
+ if (!s) {
+ *ws = L'\0';
+ return pszSave;
+ }
+ do {
+ *ws++ = (WCHAR)*s;
+ } while (*s++);
+ return pszSave;
+}
+
+LPSTR WideToAscii(LPCWSTR ws, LPSTR s)
+{
+ LPSTR pszSave = s;
+
+ if (!ws) {
+ *s = '\0';
+ return pszSave;
+ }
+ do {
+ *s++ = (CHAR)*ws;
+ } while( *ws++);
+ return pszSave;
+}
+
+LPSTR WideToUTF8(LPCWSTR ws)
+{
+
+ LPSTR s;
+ int cch = WideCharToMultiByte(CP_UTF8, 0, ws, -1, NULL, 0, NULL, NULL);
+ s = (LPSTR)apxAlloc(cch);
+ if (!WideCharToMultiByte(CP_UTF8, 0, ws, -1, s, cch, NULL, NULL)) {
+ apxFree(s);
+ return NULL;
+ }
+ return s;
+}
+
+LPWSTR UTF8ToWide(LPCSTR cs)
+{
+
+ LPWSTR s;
+ int cch = MultiByteToWideChar(CP_UTF8, 0, cs, -1, NULL, 0);
+ s = (LPWSTR)apxAlloc(cch * sizeof(WCHAR));
+ if (!MultiByteToWideChar(CP_UTF8, 0, cs, -1, s, cch)) {
+ apxFree(s);
+ return NULL;
+ }
+ return s;
+}
+
+LPSTR MzWideToAscii(LPCWSTR ws, LPSTR s)
+{
+ LPSTR pszSave = s;
+
+ if (ws) {
+ do {
+ *s++ = (CHAR)*ws;
+ ws++;
+ } while( *ws || *(ws + 1));
+ }
+ /* double terminate */
+ *s++ = '\0';
+ *s = '\0';
+ return pszSave;
+}
+
+LPSTR MzWideToUTF8(LPCWSTR ws)
+{
+ LPSTR str;
+ LPSTR s;
+ LPCWSTR p = ws;
+ int cch = 0;
+
+ for ( ; p && *p; p++) {
+ int len = WideCharToMultiByte(CP_UTF8, 0, p, -1, NULL, 0, NULL, NULL);
+ if (len > 0)
+ cch += len;
+ while (*p)
+ p++;
+ }
+ cch ++;
+ str = s = (LPSTR)apxAlloc(cch + 1);
+
+ p = ws;
+ for ( ; p && *p; p++) {
+ int len = WideCharToMultiByte(CP_UTF8, 0, p, -1, s, cch, NULL, NULL);
+ if (len > 0) {
+ s = s + len;
+ cch -= len;
+ }
+ while (*p)
+ p++;
+ }
+ /* double terminate */
+ *s = '\0';
+ return str;
+}
+
+DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount)
+{
+ LPCSTR p = lpStr;
+ if (lpdwCount)
+ *lpdwCount = 0;
+ for ( ; p && *p; p++) {
+ if (lpdwCount)
+ *lpdwCount += 1;
+ while (*p)
+ p++;
+ }
+ return (DWORD)(p - lpStr);
+}
+
+DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount)
+{
+ LPCWSTR p = lpStr;
+ if (lpdwCount)
+ *lpdwCount = 0;
+ for ( ; p && *p; p++) {
+ if (lpdwCount)
+ *lpdwCount += 1;
+ while (*p)
+ p++;
+ }
+ return (DWORD)((p - lpStr));
+}
+
+LPWSTR apxMultiSzCombine(APXHANDLE hPool, LPCWSTR lpStrA, LPCWSTR lpStrB,
+ LPDWORD lpdwLength)
+{
+ LPWSTR rv;
+ DWORD la = 0, lb = 0;
+ if (!lpStrA && !lpStrB)
+ return NULL; /* Nothing to do if both are NULL */
+
+ la = __apxGetMultiSzLengthW(lpStrA, NULL);
+ lb = __apxGetMultiSzLengthW(lpStrB, NULL);
+
+ rv = apxPoolCalloc(hPool, (la + lb + 1) * sizeof(WCHAR));
+ if (la) {
+ AplMoveMemory(rv, lpStrA, la * sizeof(WCHAR));
+ }
+ if (lb) {
+ AplMoveMemory(&rv[la], lpStrB, lb * sizeof(WCHAR));
+ }
+ if (*lpdwLength)
+ *lpdwLength = (la + lb + 1) * sizeof(WCHAR);
+ return rv;
+}
+
+BOOL
+apxSetEnvironmentVariable(APXHANDLE hPool, LPCTSTR szName, LPCTSTR szValue,
+ BOOL bAppend)
+{
+ LPTSTR szNew = (LPTSTR)szValue;
+
+ if (bAppend) {
+ DWORD l = GetEnvironmentVariable(szName, NULL, 0);
+ if (l > 0) {
+ BOOL rv;
+ if (IS_INVALID_HANDLE(hPool))
+ szNew = apxAlloc(l + lstrlen(szValue) + 3);
+ else
+ szNew = apxPoolAlloc(hPool, l + lstrlen(szValue) + 3);
+ GetEnvironmentVariable(szName, szNew, l + 1);
+ lstrcat(szNew, TEXT(";"));
+ lstrcat(szNew, szValue);
+ rv = SetEnvironmentVariable(szName, szNew);
+ apxFree(szNew);
+ return rv;
+ }
+ }
+ return SetEnvironmentVariable(szName, szNew);
+}
+
+
+/** Convert null separated double null terimated string to LPTSTR array)
+ * returns array size
+ */
+DWORD
+apxMultiSzToArrayW(APXHANDLE hPool, LPCWSTR lpString, LPWSTR **lppArray)
+{
+ DWORD i, n, l;
+ char *buff;
+ LPWSTR p;
+
+ l = __apxGetMultiSzLengthW(lpString, &n);
+ if (!n || !l)
+ return 0;
+ if (IS_INVALID_HANDLE(hPool))
+ buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
+ else
+ buff = apxAlloc((n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
+
+ *lppArray = (LPWSTR *)buff;
+ p = (LPWSTR)(buff + (n + 2) * sizeof(LPWSTR));
+ AplCopyMemory(p, lpString, (l + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+ for (i = 0; i < n; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ (*lppArray)[++i] = NULL;
+
+ return n;
+}
+
+DWORD
+apxMultiSzToArrayA(APXHANDLE hPool, LPCSTR lpString, LPSTR **lppArray)
+{
+ DWORD i, n, l;
+ char *buff;
+ LPSTR p;
+
+ l = __apxGetMultiSzLengthA(lpString, &n);
+ if (!n || !l)
+ return 0;
+ if (IS_INVALID_HANDLE(hPool))
+ buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPTSTR) + (l + 1));
+ else
+ buff = apxAlloc((n + 2) * sizeof(LPSTR) + (l + 1) * sizeof(CHAR));
+
+ *lppArray = (LPSTR *)buff;
+ p = (LPSTR)(buff + (n + 2) * sizeof(LPSTR));
+ AplCopyMemory(p, lpString, (l + 1) * sizeof(CHAR) + sizeof(CHAR));
+ for (i = 0; i < n; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ (*lppArray)[++i] = NULL;
+
+ return n;
+}
+
+#define QSTR_BOUNDARY 127
+#define QSTR_ALIGN(size) \
+ (((size) + QSTR_BOUNDARY + sizeof(APXMULTISZ) + 2) & ~(QSTR_BOUNDARY))
+
+#define QSTR_SIZE(size) \
+ ((QSTR_ALIGN(size)) - sizeof(APXMULTISZ))
+
+#define QSTR_DATA(q) ((char *)(q) + sizeof(APXMULTISZ))
+
+#if 0
+LPAPXMULTISZ apxMultiSzStrdup(LPCTSTR szSrc)
+{
+ LPAPXMULTISZ q;
+
+ if (szSrc) {
+ DWORD l = lstrlen(szSrc);
+ q = (LPAPXMULTISZ)apxAlloc(QSTR_ALIGN(l));
+ q->dwAllocated = QSTR_SIZE(l);
+ q->dwInsert = l + 1;
+ AplMoveMemory(QSTR_DATA(q), szSrc, l);
+ RtlZeroMemory(QSTR_DATA(q) + l, q->dwAllocated - l);
+ }
+ else {
+ q = (LPAPXMULTISZ)apxCalloc(QSTR_ALIGN(0));
+ q->dwAllocated = QSTR_SIZE(0);
+ }
+
+ return q;
+}
+
+LPTSTR apxMultiSzStrcat(LPAPXMULTISZ lpmSz, LPCTSTR szSrc)
+{
+ DWORD l = lstrlen(szSrc);
+ LPTSTR p;
+
+ if (lpmSz->dwInsert + l + 2 > lpmSz->dwAllocated) {
+ if ((lpmSz = (LPAPXMULTISZ )apxRealloc(lpmSz, QSTR_ALIGN(lpmSz->dwInsert + l))) == NULL)
+ return NULL;
+
+ lpmSz->dwAllocated = QSTR_SIZE(lpmSz->dwInsert + l);
+ AplZeroMemory(QSTR_DATA(lpmSz) + lpmSz->dwInsert + l,
+ lpmSz->dwAllocated - (lpmSz->dwInsert + l));
+ }
+ p = (LPTSTR)QSTR_DATA(lpmSz) + lpmSz->dwInsert;
+ AplMoveMemory(p, szSrc, l);
+
+ lpmSz->dwInsert += (l + 1);
+ return p;
+}
+
+DWORD apxMultiSzLen(LPAPXMULTISZ lpmSz)
+{
+ if (lpmSz->dwInsert)
+ return lpmSz->dwInsert - 1;
+ else
+ return 0;
+}
+
+LPCTSTR apxMultiSzGet(LPAPXMULTISZ lpmSz)
+{
+ return (LPCTSTR)QSTR_DATA(lpmSz);
+}
+#endif
+
+LPTSTR apxStrCharRemove(LPTSTR szString, TCHAR chSkip)
+{
+ LPTSTR p = szString;
+ LPTSTR q = szString;
+ while (*p) {
+ if(*p != chSkip)
+ *q++ = *p;
+ ++p;
+ }
+ *q = TEXT('\0');
+
+ return szString;
+}
+
+DWORD apxStrCharRemoveA(LPSTR szString, CHAR chSkip)
+{
+ LPSTR p = szString;
+ LPSTR q = szString;
+ DWORD c = 0;
+ while (*p) {
+ if(*p != chSkip)
+ *q++ = *p;
+ else
+ ++c;
+ ++p;
+ }
+ *q = '\0';
+
+ return c;
+}
+
+DWORD apxStrCharRemoveW(LPWSTR szString, WCHAR chSkip)
+{
+ LPWSTR p = szString;
+ LPWSTR q = szString;
+ DWORD c = 0;
+ while (*p) {
+ if(*p != chSkip)
+ *q++ = *p;
+ else
+ ++c;
+ ++p;
+ }
+ *q = L'\0';
+
+ return c;
+}
+
+void
+apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith)
+{
+ LPSTR p = szString;
+ LPSTR q = szString;
+ while (*p) {
+ if(*p == chReplace)
+ *q++ = chReplaceWith;
+ else
+ *q++ = *p;
+ ++p;
+ }
+ *q = '\0';
+}
+
+void
+apxStrCharReplaceW(LPWSTR szString, WCHAR chReplace, WCHAR chReplaceWith)
+{
+ LPWSTR p = szString;
+ LPWSTR q = szString;
+ while (*p) {
+ if(*p == chReplace)
+ *q++ = chReplaceWith;
+ else
+ *q++ = *p;
+ ++p;
+ }
+ *q = L'\0';
+}
+
+static const LPCTSTR _st_hex = TEXT("0123456789abcdef");
+#define XTOABUFFER_SIZE (sizeof(ULONG) * 2 + 2)
+#define UTOABUFFER_SIZE (sizeof(ULONG_PTR) * 2 + 2)
+#define LO_NIBLE(x) ((BYTE)((x) & 0x0000000F))
+
+BOOL apxUltohex(ULONG n, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+ LPTSTR p;
+ DWORD i;
+ *lpBuff = 0;
+ if (dwBuffLength < XTOABUFFER_SIZE)
+ return FALSE;
+ p = lpBuff + XTOABUFFER_SIZE;
+ *p-- = 0;
+ for (i = 0; i < sizeof(ULONG) * 2; i++) {
+ *p-- = _st_hex[LO_NIBLE(n)];
+ n = n >> 4;
+ }
+ *p-- = TEXT('x');
+ *p = TEXT('0');
+ return TRUE;
+}
+
+BOOL apxUptohex(ULONG_PTR n, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+ LPTSTR p;
+ DWORD i;
+ *lpBuff = 0;
+ if (dwBuffLength < UTOABUFFER_SIZE)
+ return FALSE;
+ p = lpBuff + UTOABUFFER_SIZE;
+ *p-- = 0;
+ for (i = 0; i < sizeof(ULONG_PTR) * 2; i++) {
+ *p-- = _st_hex[LO_NIBLE(n)];
+ n = n >> 4;
+ }
+ *p-- = TEXT('x');
+ *p = TEXT('0');
+ return TRUE;
+}
+
+ULONG apxStrToul(LPCTSTR szNum)
+{
+ ULONG rv = 0;
+ DWORD sh = 0;
+ LPCTSTR p = szNum;
+ ++p;
+ while (*p && (*p != TEXT('x')) && (*(p - 1) != TEXT('0')))
+ p++;
+ if (*p != 'x')
+ return 0;
+ /* go to the last digit */
+ while (*(p + 1)) p++;
+
+ /* go back to 'x' */
+ while (*p != TEXT('x')) {
+ ULONG v = 0;
+ switch (*p--) {
+ case TEXT('0'): v = 0UL; break;
+ case TEXT('1'): v = 1UL; break;
+ case TEXT('2'): v = 2UL; break;
+ case TEXT('3'): v = 3UL; break;
+ case TEXT('4'): v = 4UL; break;
+ case TEXT('5'): v = 5UL; break;
+ case TEXT('6'): v = 6UL; break;
+ case TEXT('7'): v = 7UL; break;
+ case TEXT('8'): v = 8UL; break;
+ case TEXT('9'): v = 9UL; break;
+ case TEXT('a'): case TEXT('A'): v = 10UL; break;
+ case TEXT('b'): case TEXT('B'): v = 11UL; break;
+ case TEXT('c'): case TEXT('C'): v = 12UL; break;
+ case TEXT('d'): case TEXT('D'): v = 13UL; break;
+ case TEXT('e'): case TEXT('E'): v = 14UL; break;
+ case TEXT('f'): case TEXT('F'): v = 15UL; break;
+ default:
+ return 0;
+ break;
+ }
+ rv |= rv + (v << sh);
+ sh += 4;
+ }
+ return rv;
+}
+
+ULONG apxStrToulW(LPCWSTR szNum)
+{
+ ULONG rv = 0;
+ DWORD sh = 0;
+ LPCWSTR p = szNum;
+ ++p;
+ while (*p && (*p != L'x') && (*(p - 1) != L'0'))
+ p++;
+ if (*p != L'x')
+ return 0;
+ /* go to the last digit */
+ while (*(p + 1)) p++;
+
+ /* go back to 'x' */
+ while (*p != L'x') {
+ ULONG v = 0;
+ switch (*p--) {
+ case L'0': v = 0UL; break;
+ case L'1': v = 1UL; break;
+ case L'2': v = 2UL; break;
+ case L'3': v = 3UL; break;
+ case L'4': v = 4UL; break;
+ case L'5': v = 5UL; break;
+ case L'6': v = 6UL; break;
+ case L'7': v = 7UL; break;
+ case L'8': v = 8UL; break;
+ case L'9': v = 9UL; break;
+ case L'a': case L'A': v = 10UL; break;
+ case L'b': case L'B': v = 11UL; break;
+ case L'c': case L'C': v = 12UL; break;
+ case L'd': case L'D': v = 13UL; break;
+ case L'e': case L'E': v = 14UL; break;
+ case L'f': case L'F': v = 15UL; break;
+ default:
+ return 0;
+ break;
+ }
+ rv |= rv + (v << sh);
+ sh += 4;
+ }
+ return rv;
+}
+
+ULONG apxAtoulW(LPCWSTR szNum)
+{
+ ULONG rv = 0;
+ DWORD sh = 1;
+ int s = 1;
+ LPCWSTR p = szNum;
+
+ /* go to the last digit */
+ if (!p || !*p)
+ return 0;
+ if (*p == L'-') {
+ s = -1;
+ ++p;
+ }
+ while (*(p + 1)) p++;
+
+ /* go back */
+ while (p >= szNum) {
+ ULONG v = 0;
+ switch (*p--) {
+ case L'0': v = 0UL; break;
+ case L'1': v = 1UL; break;
+ case L'2': v = 2UL; break;
+ case L'3': v = 3UL; break;
+ case L'4': v = 4UL; break;
+ case L'5': v = 5UL; break;
+ case L'6': v = 6UL; break;
+ case L'7': v = 7UL; break;
+ case L'8': v = 8UL; break;
+ case L'9': v = 9UL; break;
+ default:
+ return rv * s;
+ break;
+ }
+ rv = rv + (v * sh);
+ sh = sh * 10;
+ }
+ return rv * s;
+}
+
+/* Make the unique system resource name from prefix and process id
+ *
+ */
+BOOL
+apxMakeResourceName(LPCTSTR szPrefix, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+ DWORD pl = lstrlen(szPrefix);
+ if (dwBuffLength < (pl + 11))
+ return FALSE;
+ lstrcpy(lpBuff, szPrefix);
+ return apxUltohex(GetCurrentProcessId(), lpBuff + pl, dwBuffLength - pl);
+}
+/** apxStrMatchA ANSI string pattern matching
+ * Match = 0, NoMatch = 1, Abort = -1
+ * Based loosely on sections of wildmat.c by Rich Salz
+ */
+INT apxStrMatchA(LPCSTR szString, LPCSTR szPattern, BOOL bIgnoreCase)
+{
+ int x, y;
+
+ for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
+ if (!szPattern[x] && (szPattern[y] != '*' || szPattern[y] != '?'))
+ return -1;
+ if (szPattern[y] == '*') {
+ while (szPattern[++y] == '*');
+ if (!szPattern[y])
+ return 0;
+ while (szString[x]) {
+ INT rc;
+ if ((rc = apxStrMatchA(&szString[x++], &szPattern[y],
+ bIgnoreCase)) != 1)
+ return rc;
+ }
+ return -1;
+ }
+ else if (szPattern[y] != '?') {
+ if (bIgnoreCase) {
+ if (CharLowerA((LPSTR)((SIZE_T)szString[x])) !=
+ CharLowerA((LPSTR)((SIZE_T)szPattern[y])))
+ return 1;
+ }
+ else {
+ if (szString[x] != szPattern[y])
+ return 1;
+ }
+ }
+ }
+ return (szString[x] != '\0');
+}
+
+INT apxStrMatchW(LPCWSTR szString, LPCWSTR szPattern, BOOL bIgnoreCase)
+{
+ int x, y;
+
+ for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
+ if (!szPattern[x] && (szPattern[y] != L'*' || szPattern[y] != L'?'))
+ return -1;
+ if (szPattern[y] == L'*') {
+ while (szPattern[++y] == L'*');
+ if (!szPattern[y])
+ return 0;
+ while (szString[x]) {
+ INT rc;
+ if ((rc = apxStrMatchW(&szString[x++], &szPattern[y],
+ bIgnoreCase)) != 1)
+ return rc;
+ }
+ return -1;
+ }
+ else if (szPattern[y] != L'?') {
+ if (bIgnoreCase) {
+ if (CharLowerW((LPWSTR)((SIZE_T)szString[x])) !=
+ CharLowerW((LPWSTR)((SIZE_T)szPattern[y])))
+ return 1;
+ }
+ else {
+ if (szString[x] != szPattern[y])
+ return 1;
+ }
+ }
+ }
+ return (szString[x] != L'\0');
+}
+
+INT apxMultiStrMatchW(LPCWSTR szString, LPCWSTR szPattern,
+ WCHAR chSeparator, BOOL bIgnoreCase)
+{
+ WCHAR szM[SIZ_HUGLEN];
+ DWORD i = 0;
+ LPCWSTR p = szPattern;
+ INT m = -1;
+
+ if (chSeparator == 0)
+ return apxStrMatchW(szString, szPattern, bIgnoreCase);
+ while (*p != L'\0') {
+ if (*p == chSeparator) {
+ m = apxStrMatchW(szString, szM, bIgnoreCase);
+ if (m == 0)
+ return 0;
+ p++;
+ i = 0;
+ szM[0] = L'\0';
+ }
+ else {
+ if (i < SIZ_HUGMAX)
+ szM[i++] = *p++;
+ else
+ return -1;
+ }
+ }
+ szM[i] = L'\0';
+ if (szM[0])
+ return apxStrMatchW(szString, szM, bIgnoreCase);
+ else
+ return m;
+}
+
+LPSTR apxArrayToMultiSzA(APXHANDLE hPool, DWORD nArgs, LPCSTR *lpArgs)
+{
+ DWORD i, l = 0;
+ LPSTR lpSz, p;
+ if (!nArgs)
+ return NULL;
+ for (i = 0; i < nArgs; i++)
+ l += lstrlenA(lpArgs[i]);
+ l += (nArgs + 2);
+
+ p = lpSz = (LPSTR)apxPoolAlloc(hPool, l);
+ for (i = 0; i < nArgs; i++) {
+ lstrcpyA(p, lpArgs[i]);
+ p += lstrlenA(lpArgs[i]);
+ *p++ = '\0';
+ }
+ *p++ = '\0';
+ *p++ = '\0';
+ return lpSz;
+}
+
+void apxStrQuoteInplaceW(LPWSTR szString)
+{
+ LPWSTR p = szString;
+ BOOL needsQuote = FALSE;
+ while (*p) {
+ if (*p++ == L' ') {
+ needsQuote = TRUE;
+ break;
+ }
+ }
+ if (needsQuote) {
+ DWORD l = lstrlenW(szString);
+ AplMoveMemory(&szString[1], szString, l * sizeof(WCHAR));
+ szString[0] = L'"';
+ szString[++l] = L'"';
+ szString[++l] = L'\0';
+ }
+}
+
+DWORD apxStrUnQuoteInplaceA(LPSTR szString)
+{
+ LPSTR p = szString;
+ BOOL needsQuote = FALSE;
+ BOOL inQuote = FALSE;
+ while (*p) {
+ if (*p == '"') {
+ if (inQuote)
+ break;
+ else
+ inQuote = TRUE;
+ }
+ else if (*p == ' ') {
+ if (inQuote) {
+ needsQuote = TRUE;
+ break;
+ }
+ }
+ ++p;
+ }
+ if (!needsQuote)
+ return apxStrCharRemoveA(szString, '"');
+ else
+ return 0;
+}
+
+DWORD apxStrUnQuoteInplaceW(LPWSTR szString)
+{
+ LPWSTR p = szString;
+ BOOL needsQuote = FALSE;
+ BOOL inQuote = FALSE;
+ while (*p) {
+ if (*p == L'"') {
+ if (inQuote)
+ break;
+ else
+ inQuote = TRUE;
+ }
+ else if (*p == L' ') {
+ if (inQuote) {
+ needsQuote = TRUE;
+ break;
+ }
+ }
+ ++p;
+ }
+ if (!needsQuote)
+ return apxStrCharRemoveW(szString, L'"');
+ else
+ return 0;
+}
+
+LPWSTR
+apxMszToCRLFW(APXHANDLE hPool, LPCWSTR szStr)
+{
+ DWORD l, c;
+ LPWSTR rv, b;
+ LPCWSTR p = szStr;
+
+ l = __apxGetMultiSzLengthW(szStr, &c);
+ b = rv = apxPoolCalloc(hPool, (l + c + 2) * sizeof(WCHAR));
+
+ while (c > 0) {
+ if (*p)
+ *b++ = *p;
+ else {
+ *b++ = L'\r';
+ *b++ = L'\n';
+ c--;
+ }
+ p++;
+ }
+ return rv;
+}
+
+LPWSTR
+apxCRLFToMszW(APXHANDLE hPool, LPCWSTR szStr, LPDWORD lpdwBytes)
+{
+ DWORD l, c, n = 0;
+ LPWSTR rv, b;
+
+ l = lstrlenW(szStr);
+ b = rv = apxPoolCalloc(hPool, (l + 2) * sizeof(WCHAR));
+ for (c = 0; c < l; c++) {
+ if (szStr[c] == L'\r') {
+ *b++ = '\0';
+ n++;
+ }
+ else if (szStr[c] != L'\n') {
+ *b++ = szStr[c];
+ n++;
+ }
+ }
+ if (lpdwBytes)
+ *lpdwBytes = (n + 2) * sizeof(WCHAR);
+ return rv;
+}
+
+LPSTR
+apxExpandStrA(APXHANDLE hPool, LPCSTR szString)
+{
+ LPCSTR p = szString;
+ while (*p) {
+ if (*p == '%') {
+ p = szString;
+ break;
+ }
+ ++p;
+ }
+ if (p != szString)
+ return apxPoolStrdupA(hPool, szString);
+ else {
+ DWORD l = ExpandEnvironmentStringsA(szString, NULL, 0);
+ if (l) {
+ LPSTR rv = apxPoolAlloc(hPool, l);
+ l = ExpandEnvironmentStringsA(szString, rv, l);
+ if (l)
+ return rv;
+ else {
+ apxFree(rv);
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+ }
+}
+
+LPWSTR
+apxExpandStrW(APXHANDLE hPool, LPCWSTR szString)
+{
+ LPCWSTR p = szString;
+ while (*p) {
+ if (*p == L'%') {
+ p = szString;
+ break;
+ }
+ ++p;
+ }
+ if (p != szString)
+ return apxPoolStrdupW(hPool, szString);
+ else {
+ DWORD l = ExpandEnvironmentStringsW(szString, NULL, 0);
+ if (l) {
+ LPWSTR rv = apxPoolAlloc(hPool, l * sizeof(WCHAR));
+ l = ExpandEnvironmentStringsW(szString, rv, l);
+ if (l)
+ return rv;
+ else {
+ apxFree(rv);
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+ }
+}
+
+/* To share the semaphores with other processes, we need a NULL ACL
+ * Code from MS KB Q106387
+ */
+PSECURITY_ATTRIBUTES GetNullACL()
+{
+ PSECURITY_DESCRIPTOR pSD;
+ PSECURITY_ATTRIBUTES sa;
+
+ sa = (PSECURITY_ATTRIBUTES) LocalAlloc(LPTR, sizeof(SECURITY_ATTRIBUTES));
+ sa->nLength = sizeof(sizeof(SECURITY_ATTRIBUTES));
+
+ pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
+ sa->lpSecurityDescriptor = pSD;
+
+ if (pSD == NULL || sa == NULL) {
+ return NULL;
+ }
+ SetLastError(0);
+ if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
+ || GetLastError()) {
+ LocalFree( pSD );
+ LocalFree( sa );
+ return NULL;
+ }
+ if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)
+ || GetLastError()) {
+ LocalFree( pSD );
+ LocalFree( sa );
+ return NULL;
+ }
+
+ sa->bInheritHandle = FALSE;
+ return sa;
+}
+
+
+void CleanNullACL(void *sa)
+{
+ if (sa) {
+ LocalFree(((PSECURITY_ATTRIBUTES)sa)->lpSecurityDescriptor);
+ LocalFree(sa);
+ }
+}
14 years, 4 months
JBoss Native SVN: r2689 - in trunk/utils/windows/native/service/procrun: apps/prunsrv and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2010-07-21 16:01:54 -0400 (Wed, 21 Jul 2010)
New Revision: 2689
Modified:
trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c
trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h
trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc
trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c
trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h
trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc
trunk/utils/windows/native/service/procrun/src/cmdline.c
trunk/utils/windows/native/service/procrun/src/handles.c
trunk/utils/windows/native/service/procrun/src/javajni.c
trunk/utils/windows/native/service/procrun/src/log.c
trunk/utils/windows/native/service/procrun/src/mclib.c
trunk/utils/windows/native/service/procrun/src/private.h
trunk/utils/windows/native/service/procrun/src/registry.c
trunk/utils/windows/native/service/procrun/src/rprocess.c
trunk/utils/windows/native/service/procrun/src/service.c
trunk/utils/windows/native/service/procrun/src/utils.c
Log:
Implement JBPAPP-4709
Modified: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -15,7 +15,7 @@
*/
/* ====================================================================
- * prunsrv -- Service Runner.
+ * prunmgr -- Service Manager Application.
* Contributed by Mladen Turk <mturk(a)apache.org>
* 05 Aug 2003
* ====================================================================
@@ -80,7 +80,7 @@
static LPCWSTR _s_start = L"Start";
static LPCWSTR _s_stop = L"Stop";
-/* Allowed procrun commands */
+/* Allowed prunmgr commands */
static LPCWSTR _commands[] = {
L"ES", /* 1 Manage Service (default)*/
L"MS", /* 2 Monitor Service */
@@ -285,8 +285,8 @@
BOOL __generalPropertySave(HWND hDlg)
{
- WCHAR szN[256];
- WCHAR szD[256];
+ WCHAR szN[SIZ_RESLEN];
+ WCHAR szD[SIZ_DESLEN];
DWORD dwStartType = SERVICE_NO_CHANGE;
int i;
@@ -296,8 +296,8 @@
if (IS_INVALID_HANDLE(hService))
return FALSE;
- GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, 255);
- GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, 1023);
+ GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, SIZ_DESMAX);
i = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST));
if (i == 0)
dwStartType = SERVICE_AUTO_START;
@@ -316,9 +316,9 @@
BOOL __generalLogonSave(HWND hDlg)
{
- WCHAR szU[64];
- WCHAR szP[64];
- WCHAR szC[64];
+ WCHAR szU[SIZ_RESLEN];
+ WCHAR szP[SIZ_RESLEN];
+ WCHAR szC[SIZ_RESLEN];
DWORD dwStartType = SERVICE_NO_CHANGE;
if (!(TST_BIT_FLAG(_propertyChanged, 2)))
@@ -327,13 +327,15 @@
if (IS_INVALID_HANDLE(hService))
return FALSE;
- GetDlgItemTextW(hDlg, IDC_PPSLUSER, szU, 63);
- GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
- GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+ GetDlgItemTextW(hDlg, IDC_PPSLUSER, szU, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, SIZ_RESMAX);
if (lstrlenW(szU) && lstrcmpiW(szU, STAT_SYSTEM)) {
- if (szP[0] != L' ' && szC[0] != L' ' && !lstrcmpW(szP, szC))
+ if (szP[0] != L' ' && szC[0] != L' ' && !lstrcmpW(szP, szC)) {
apxServiceSetNames(hService, NULL, NULL, NULL, szU, szP);
+ lstrlcpyW(_currentEntry->szObjectName, SIZ_RESLEN, szU);
+ }
else {
MessageBoxW(hDlg, apxLoadResourceW(IDS_VALIDPASS, 0),
apxLoadResourceW(IDS_APPLICATION, 1),
@@ -343,6 +345,7 @@
}
else {
apxServiceSetNames(hService, NULL, NULL, NULL, STAT_SYSTEM, L"");
+ lstrlcpyW(_currentEntry->szObjectName, SIZ_RESLEN, STAT_SYSTEM);
if (IsDlgButtonChecked(hDlg, IDC_PPSLID) == BST_CHECKED)
apxServiceSetOptions(hService,
_currentEntry->stServiceStatus.dwServiceType | SERVICE_INTERACTIVE_PROCESS,
@@ -374,6 +377,8 @@
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Path", szB);
GetDlgItemTextW(hDlg, IDC_PPLGPREFIX, szB, SIZ_DESMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Prefix", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGPIDFILE, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"PidFile", szB);
GetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, szB, SIZ_DESMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdOutput", szB);
GetDlgItemTextW(hDlg, IDC_PPLGSTDERR, szB, SIZ_DESMAX);
@@ -386,7 +391,7 @@
BOOL __generalJvmSave(HWND hDlg)
{
- WCHAR szB[SIZ_DESLEN];
+ WCHAR szB[SIZ_HUGLEN];
LPWSTR p, s;
DWORD l;
if (!(TST_BIT_FLAG(_propertyChanged, 4)))
@@ -396,12 +401,12 @@
if (IS_INVALID_HANDLE(hService))
return FALSE;
if (!IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
- GetDlgItemTextW(hDlg, IDC_PPJJVM, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPJJVM, szB, SIZ_HUGMAX);
}
else
lstrcpyW(szB, L"auto");
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Jvm", szB);
- GetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Classpath", szB);
l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPJOPTIONS));
@@ -411,7 +416,7 @@
apxFree(p);
apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
_s_java, L"Options", s, l);
- if (!GetDlgItemTextW(hDlg, IDC_PPJMS, szB, SIZ_DESMAX))
+ if (!GetDlgItemTextW(hDlg, IDC_PPJMS, szB, SIZ_HUGMAX))
szB[0] = L'\0';
apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMs",
@@ -432,7 +437,7 @@
BOOL __generalStartSave(HWND hDlg)
{
- WCHAR szB[SIZ_DESLEN];
+ WCHAR szB[SIZ_HUGLEN];
LPWSTR p, s;
DWORD l;
@@ -443,15 +448,15 @@
if (IS_INVALID_HANDLE(hService))
return FALSE;
- GetDlgItemTextW(hDlg, IDC_PPRCLASS, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPRCLASS, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Class", szB);
- GetDlgItemTextW(hDlg, IDC_PPRIMAGE, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPRIMAGE, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Image", szB);
- GetDlgItemTextW(hDlg, IDC_PPRWPATH, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPRWPATH, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"WorkingPath", szB);
- GetDlgItemTextW(hDlg, IDC_PPRMETHOD, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPRMETHOD, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Method", szB);
- GetDlgItemTextW(hDlg, IDC_PPRMODE, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPRMODE, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Mode", szB);
l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPRARGS));
@@ -470,7 +475,7 @@
BOOL __generalStopSave(HWND hDlg)
{
- WCHAR szB[SIZ_DESLEN];
+ WCHAR szB[SIZ_HUGLEN];
LPWSTR p, s;
DWORD l;
@@ -481,17 +486,17 @@
if (IS_INVALID_HANDLE(hService))
return FALSE;
- GetDlgItemTextW(hDlg, IDC_PPSCLASS, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSCLASS, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Class", szB);
- GetDlgItemTextW(hDlg, IDC_PPSIMAGE, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSIMAGE, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Image", szB);
- GetDlgItemTextW(hDlg, IDC_PPSWPATH, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSWPATH, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"WorkingPath", szB);
- GetDlgItemTextW(hDlg, IDC_PPSMETHOD, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSMETHOD, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Method", szB);
- GetDlgItemTextW(hDlg, IDC_PPSTIMEOUT, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSTIMEOUT, szB, SIZ_HUGMAX);
apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Timeout", apxAtoulW(szB));
- GetDlgItemTextW(hDlg, IDC_PPSMODE, szB, SIZ_DESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSMODE, szB, SIZ_HUGMAX);
apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Mode", szB);
l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPSARGS));
@@ -553,7 +558,7 @@
LPARAM lParam)
{
LPPSHNOTIFY lpShn;
- WCHAR szBuf[1024];
+ WCHAR szBuf[SIZ_DESLEN];
switch (uMessage) {
case WM_INITDIALOG:
@@ -566,8 +571,8 @@
startPage = 0;
if (!bEnableTry)
apxCenterWindow(GetParent(hDlg), NULL);
- SendMessage(GetDlgItem(hDlg, IDC_PPSGDISP), EM_LIMITTEXT, 255, 0);
- SendMessage(GetDlgItem(hDlg, IDC_PPSGDESC), EM_LIMITTEXT, 1023, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSGDISP), EM_LIMITTEXT, SIZ_RESMAX, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSGDESC), EM_LIMITTEXT, SIZ_DESMAX, 0);
ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_AUTO);
ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_MANUAL);
@@ -596,7 +601,7 @@
break;
case IDC_PPSGDISP:
if (HIWORD(wParam) == EN_CHANGE) {
- GetDlgItemTextW(hDlg, IDC_PPSGDISP, szBuf, 255);
+ GetDlgItemTextW(hDlg, IDC_PPSGDISP, szBuf, SIZ_RESMAX);
if (!lstrcmpW(szBuf, _currentEntry->lpConfig->lpDisplayName)) {
PropSheet_UnChanged(GetParent(hDlg), hDlg);
CLR_BIT_FLAG(_propertyChanged, 1);
@@ -609,7 +614,7 @@
break;
case IDC_PPSGDESC:
if (HIWORD(wParam) == EN_CHANGE) {
- GetDlgItemTextW(hDlg, IDC_PPSGDESC, szBuf, 1023);
+ GetDlgItemTextW(hDlg, IDC_PPSGDESC, szBuf, SIZ_DESMAX);
if (!lstrcmpW(szBuf, _currentEntry->szServiceDescription)) {
PropSheet_UnChanged(GetParent(hDlg), hDlg);
CLR_BIT_FLAG(_propertyChanged, 1);
@@ -678,7 +683,7 @@
LPARAM lParam)
{
LPPSHNOTIFY lpShn;
- WCHAR szBuf[1024];
+ WCHAR szBuf[SIZ_DESLEN];
switch (uMessage) {
case WM_INITDIALOG:
{
@@ -764,7 +769,7 @@
break;
case IDC_PPSLUSER:
if (HIWORD(wParam) == EN_CHANGE) {
- GetDlgItemTextW(hDlg, IDC_PPSLUSER, szBuf, 63);
+ GetDlgItemTextW(hDlg, IDC_PPSLUSER, szBuf, SIZ_RESMAX);
if (!lstrcmpiW(szBuf, _currentEntry->szObjectName)) {
PropSheet_UnChanged(GetParent(hDlg), hDlg);
CLR_BIT_FLAG(_propertyChanged, 2);
@@ -778,10 +783,10 @@
case IDC_PPSLPASS:
case IDC_PPSLCPASS:
if (HIWORD(wParam) == EN_CHANGE) {
- WCHAR szP[64];
- WCHAR szC[64];
- GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
- GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+ WCHAR szP[SIZ_RESLEN];
+ WCHAR szC[SIZ_RESLEN];
+ GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, SIZ_RESMAX);
+ GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, SIZ_RESMAX);
/* check for valid password match */
if (szP[0] == L' ' && szC[0] == L' ') {
PropSheet_UnChanged(GetParent(hDlg), hDlg);
@@ -858,13 +863,25 @@
apxFree(b);
}
else
- ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 1);
if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
_s_log, L"Path")) != NULL) {
SetDlgItemTextW(hDlg, IDC_PPLGPATH, b);
apxFree(b);
}
if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"Prefix")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, b);
+ apxFree(b);
+ }
+ else
+ SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, L"commons-daemon");
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"PidFile")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPIDFILE, b);
+ apxFree(b);
+ }
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
_s_log, L"StdOutput")) != NULL) {
SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, b);
apxFree(b);
@@ -896,6 +913,12 @@
SET_BIT_FLAG(_propertyChanged, 3);
}
break;
+ case IDC_PPLGPIDFILE:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
case IDC_PPLGSTDERR:
if (HIWORD(wParam) == EN_CHANGE) {
PropSheet_Changed(GetParent(hDlg), hDlg);
@@ -1114,7 +1137,7 @@
apxCenterWindow(GetParent(hDlg), NULL);
bpropCentered = TRUE;
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"exe");
ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"jvm");
ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), _s_java);
@@ -1253,7 +1276,7 @@
apxCenterWindow(GetParent(hDlg), NULL);
bpropCentered = TRUE;
- ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"exe");
ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"jvm");
ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), _s_java);
@@ -1399,7 +1422,7 @@
{
PROPSHEETPAGEW psP[6];
PROPSHEETHEADERW psH;
- WCHAR szT[1024] = {0};
+ WCHAR szT[SIZ_DESLEN] = {0};
if (_propertyOpened) {
SetForegroundWindow(_gui_store->hMainWnd);
@@ -1419,10 +1442,10 @@
__stopProperty);
if (_currentEntry && _currentEntry->lpConfig)
- lstrcpyW(szT, _currentEntry->lpConfig->lpDisplayName);
+ lstrlcpyW(szT, SIZ_DESMAX, _currentEntry->lpConfig->lpDisplayName);
else
return;
- lstrcatW(szT, L" Properties");
+ lstrlcatW(szT, SIZ_DESMAX, L" Properties");
psH.dwSize = sizeof(PROPSHEETHEADER);
psH.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
@@ -1449,9 +1472,9 @@
WCHAR en[SIZ_DESLEN];
int i;
- lstrcpyW(en, L"Global\\");
- lstrcatW(en, szServiceName);
- lstrcatW(en, L"SIGNAL");
+ lstrlcpyW(en, SIZ_DESLEN, L"Global\\");
+ lstrlcatW(en, SIZ_DESLEN, szServiceName);
+ lstrlcatW(en, SIZ_DESLEN, L"SIGNAL");
for (i = 7; i < lstrlenW(en); i++) {
if (en[i] >= L'a' && en[i] <= L'z')
en[i] = en[i] - 32;
Modified: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h 2010-07-21 20:01:54 UTC (rev 2689)
@@ -13,20 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
/* ====================================================================
- *
+ *
* Contributed by Mladen Turk <mturk(a)apache.org>
* 05 Aug 2003
- * ====================================================================
+ * ====================================================================
*/
#ifndef _PRUNMGR_H
#define _PRUNMGR_H
#undef PRG_VERSION
-#define PRG_VERSION "2.0.4.1"
-#define CSV_VERSION 2,0,4,1
+#define PRG_VERSION "2.0.5.1"
+#define CSV_VERSION 2,0,5,1
#define PRG_REGROOT L"JBoss\\JBoss Web 2"
#define IDM_TM_EXIT 2000
@@ -137,5 +137,5 @@
#define IDS_ERRSREG 3122
#define IDS_NOTIMPLEMENTED 3199
-
+
#endif /* _PRUNMGR_H */
Modified: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc 2010-07-21 20:01:54 UTC (rev 2689)
@@ -13,26 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "apxwin.h"
#include "prunmgr.h"
#define RSTR_SCMATS "Service Manager is attempting to "
-#define STR_COPYRIGHT "Copyright � 2008 Red Hat Middleware, LLC. " \
+#define STR_COPYRIGHT "Copyright � 2010 Red Hat, Inc. " \
"or its licensors, as applicable."
#define STR_LICENSE "Distributable under LGPL license. " \
"See terms of license at gnu.org."
-#define STR_COMPANY "Red Hat�, Inc."
-#define STR_TRADEMARK "� Red Hat Inc."
+#define STR_COMPANY "Red Hat�, Inc."
+#define STR_TRADEMARK "� Red Hat Inc."
#define STR_PRODUCT "JBoss Web Service manager"
-IDI_MAINICON ICON "../../resources/jboss.ico"
-IDI_REDHATICON ICON "../../resources/redhat.ico"
-IDI_ICONSTOP ICON "../../resources/procruns.ico"
-IDI_ICONRUN ICON "../../resources/procrunr.ico"
+IDI_MAINICON ICON "../../resources/jboss.ico"
+IDI_REDHATICON ICON "../../resources/redhat.ico"
+IDI_ICONSTOP ICON "../../resources/procruns.ico"
+IDI_ICONRUN ICON "../../resources/procrunr.ico"
IDR_LICENSE RTF "../../resources/license.rtf"
BMP_JBOSSLOGO BITMAP "../../resources/jbosslogo.bmp"
@@ -44,17 +44,17 @@
FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
BEGIN
DEFPUSHBUTTON "&OK",IDOK,285,150,50,14
- CONTROL "",IDC_LICENSE,"RichEdit20A",ES_MULTILINE |
+ CONTROL "",IDC_LICENSE,"RichEdit20A",ES_MULTILINE |
ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
CONTROL "BMP_JBOSSLOGO",IDC_STATIC,"Static",SS_BITMAP|0x00000040L,0,0,337,30
LTEXT " ",IDC_ABOUTAPP,2,150,270,12
- LTEXT "Copyright � 2008 Red Hat Middleware, LLC.",IDC_STATIC,2,160,270,12
- LTEXT "http://www.jboss.org",IDC_STATIC,2,170,270,12
+ LTEXT "Copyright � 2008 Red Hat Middleware, LLC.",IDC_STATIC,2,160,270,12
+ LTEXT "http://www.jboss.org",IDC_STATIC,2,170,270,12
PUSHBUTTON "&System Info",IAB_SYSINF,285,170,50,14
END
IDD_PROGRESS DIALOGEX 0, 0, 322, 92
-STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP |
+STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP |
WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOPMOST
CAPTION "JBoss Web Service Manager"
@@ -68,7 +68,7 @@
CONTROL "",IDDP_PROGRESS,"msctls_progress32",WS_BORDER,10,50,302,
14
ICON IDI_MAINICON,IDC_STATIC,10,4,20,20,0,WS_EX_TRANSPARENT
-END
+END
IDD_SELUSER DIALOGEX 0, 0, 410, 201
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU |
@@ -82,10 +82,10 @@
DEFPUSHBUTTON "OK",IDOK,292,180,50,14,WS_DISABLED
PUSHBUTTON "Cancel",IDCANCEL,348,180,50,14
LTEXT "Look In:",IDC_STATIC,10,9,27,8
- CONTROL "",IDSU_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL |
- LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER |
+ CONTROL "",IDSU_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL |
+ LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER |
WS_TABSTOP,0,26,410,149,WS_EX_CLIENTEDGE
- CONTROL "",IDSU_COMBO,"ComboBoxEx32",CBS_DROPDOWNLIST |
+ CONTROL "",IDSU_COMBO,"ComboBoxEx32",CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP,47,6,260,80
END
@@ -102,9 +102,9 @@
LTEXT "Pat&h to executable:",IDC_STATIC,10,63,66,8
EDITTEXT IDC_PPSGDEXE,10,75,240,12,ES_AUTOHSCROLL | WS_DISABLED
LTEXT "Startup typ&e:",IDC_STATIC,10,94,46,8
- COMBOBOX IDC_PPSGCMBST,70,93,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ COMBOBOX IDC_PPSGCMBST,70,93,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
- CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,10,128,240,1
+ CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,10,128,240,1
LTEXT "Service Status:",IDC_STATIC,10,138,52,8
LTEXT " ",IDC_PPSGSTATUS,70,138,240,8
PUSHBUTTON "&Start",IDC_PPSGSTART,10,160,55,14,WS_DISABLED
@@ -137,20 +137,23 @@
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
LTEXT "&Level:",IDC_STATIC,10,18,46,8
- COMBOBOX IDC_PPLGLEVEL,70,17,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ COMBOBOX IDC_PPLGLEVEL,70,17,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
LTEXT "Log &path: ",IDC_STATIC,10,33,50,8
EDITTEXT IDC_PPLGPATH,10,45,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPLGBPATH,232,44,18,14
+ PUSHBUTTON "...",IDC_PPLGBPATH,232,44,18,14
LTEXT "Log prefix: ",IDC_STATIC,10,63,50,8
EDITTEXT IDC_PPLGPREFIX,70,62,158,12,ES_AUTOHSCROLL
-
- LTEXT "Redirect Stdout: ",IDC_STATIC,10,85,80,8
- EDITTEXT IDC_PPLGSTDOUT,10,97,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPLGBSTDOUT,232,96,18,14
- LTEXT "Redirect Stderror: ",IDC_STATIC,10,115,80,8
- EDITTEXT IDC_PPLGSTDERR,10,127,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPLGBSTDERR,232,126,18,14
+
+ LTEXT "Pid file: ",IDC_STATIC,10,81,50,8
+ EDITTEXT IDC_PPLGPIDFILE,70,82,158,12,ES_AUTOHSCROLL
+
+ LTEXT "Redirect Stdout: ",IDC_STATIC,10,105,80,8
+ EDITTEXT IDC_PPLGSTDOUT,10,117,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBSTDOUT,232,116,18,14
+ LTEXT "Redirect Stderror: ",IDC_STATIC,10,135,80,8
+ EDITTEXT IDC_PPLGSTDERR,10,147,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBSTDERR,232,146,18,14
END
IDD_PROPPAGE_JVM DIALOGEX 0, 0, 260, 186
@@ -161,11 +164,11 @@
WS_TABSTOP,10,8,72,12
LTEXT "Java Virtual Machine: ",IDC_STATIC,10,23,80,8
EDITTEXT IDC_PPJJVM,10,35,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPJBJVM,232,34,18,14
+ PUSHBUTTON "...",IDC_PPJBJVM,232,34,18,14
LTEXT "Java Classpath:",IDC_STATIC,10,53,66,8
EDITTEXT IDC_PPJCLASSPATH,10,65,240,12,ES_AUTOHSCROLL
LTEXT "Java Options:",IDC_STATIC,10,83,66,8
- EDITTEXT IDC_PPJOPTIONS,10,95,240,40,ES_MULTILINE | ES_AUTOHSCROLL |
+ EDITTEXT IDC_PPJOPTIONS,10,95,240,40,ES_MULTILINE | ES_AUTOHSCROLL |
ES_WANTRETURN | WS_VSCROLL
LTEXT "Initial memory pool:",IDC_STATIC,10,140,80,8
EDITTEXT IDC_PPJMS,90,139,100,12,ES_AUTOHSCROLL | ES_NUMBER
@@ -186,20 +189,20 @@
EDITTEXT IDC_PPRCLASS,10,20,240,12,ES_AUTOHSCROLL
LTEXT "Image: ",IDC_STATIC,10,38,80,8
EDITTEXT IDC_PPRIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
- PUSHBUTTON "...",IDC_PPRBIMAGE,232,49,18,14,WS_DISABLED
+ PUSHBUTTON "...",IDC_PPRBIMAGE,232,49,18,14,WS_DISABLED
LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
EDITTEXT IDC_PPRWPATH,10,80,218,12,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_PPRBWPATH,232,79,18,14
LTEXT "&Method: ",IDC_STATIC,10,98,50,8
EDITTEXT IDC_PPRMETHOD,70,97,180,12,ES_AUTOHSCROLL
LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
- EDITTEXT IDC_PPRARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
+ EDITTEXT IDC_PPRARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
ES_WANTRETURN | WS_VSCROLL
LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
EDITTEXT IDC_PPRTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | WS_DISABLED
LTEXT "sec.",IDC_STATIC,175,150,25,8
LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
- COMBOBOX IDC_PPRMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ COMBOBOX IDC_PPRMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
END
@@ -211,29 +214,29 @@
EDITTEXT IDC_PPSCLASS,10,20,240,12,ES_AUTOHSCROLL
LTEXT "Image: ",IDC_STATIC,10,38,80,8
EDITTEXT IDC_PPSIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
- PUSHBUTTON "...",IDC_PPSBIMAGE,232,49,18,14,WS_DISABLED
+ PUSHBUTTON "...",IDC_PPSBIMAGE,232,49,18,14,WS_DISABLED
LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
EDITTEXT IDC_PPSWPATH,10,80,218,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_PPSBWPATH,232,79,18,14
+ PUSHBUTTON "...",IDC_PPSBWPATH,232,79,18,14
LTEXT "&Method: ",IDC_STATIC,10,98,50,8
EDITTEXT IDC_PPSMETHOD,70,97,180,12,ES_AUTOHSCROLL
LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
- EDITTEXT IDC_PPSARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
+ EDITTEXT IDC_PPSARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
ES_WANTRETURN | WS_VSCROLL
LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
EDITTEXT IDC_PPSTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | ES_NUMBER
LTEXT "sec.",IDC_STATIC,175,150,25,8
LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
- COMBOBOX IDC_PPSMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ COMBOBOX IDC_PPSMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
END
-STRINGTABLE
+STRINGTABLE
BEGIN
IDS_APPLICATION STR_PRODUCT
- IDS_APPVERSION "Version 2.0.4"
+ IDS_APPVERSION "Version 2.0.5"
IDS_APPFULLNAME STR_PRODUCT " Version " PRG_VERSION
- IDS_APPCOPYRIGHT "Copyright � 2008 Red Hat Middleware, LLC."
+ IDS_APPCOPYRIGHT "Copyright � 2010 Red Hat, Inc."
IDS_APPDESCRIPTION "JBoss Web Service Management Tool"
IDS_ALREAY_RUNING "An instance of '%S' application is already running"
IDS_ERRORCMD "Unknown command line option '%s'\nSee the manual for command line usage."
@@ -241,23 +244,23 @@
IDS_HSSTOP RSTR_SCMATS "stop the following service ..."
IDS_HSRESTART RSTR_SCMATS "to restart the following service ..."
IDS_HSPAUSE RSTR_SCMATS "to pause the following service ..."
- IDS_VALIDPASS "Please enter a valid password"
+ IDS_VALIDPASS "Please enter a valid password"
IDS_PPGENERAL "General"
IDS_PPLOGON "Log On"
IDS_PPLOGGING "Logging"
IDS_PPJAVAVM "Java"
IDS_PPSTART "Startup"
IDS_PPSTOP "Shutdown"
- IDS_NOTIMPLEMENTED "Sorry, but this feature is not implemented yet"
+ IDS_NOTIMPLEMENTED "Sorry, but this feature is not implemented yet"
IDS_LGPATHTITLE "Select Log root folder"
IDS_ALLFILES "All Files (*.*)\0*.*\0"
IDS_DLLFILES "Dynamic Link Libraries (*.dll)\0*.dll\0"
IDS_EXEFILES "Executables (*.exe)\0*.exe\0"
IDS_LGSTDOUT "Select Stdoutput filename"
IDS_LGSTDERR "Select Stderror filename"
- IDS_PPJBJVM "Select Java Virtual Machine DLL"
- IDS_PPWPATH "Select Working path"
- IDS_PPIMAGE "Select Executable Image"
+ IDS_PPJBJVM "Select Java Virtual Machine DLL"
+ IDS_PPWPATH "Select Working path"
+ IDS_PPIMAGE "Select Executable Image"
IDS_ERRSREG "Unable to open the service registry key"
END
Modified: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -39,6 +39,7 @@
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
+#define ONE_MINUTE (60 * 1000)
#ifdef WIN64
#define KREG_WOW6432 KEY_WOW64_32KEY
@@ -50,12 +51,8 @@
LPCWSTR szLogPath;
LPCWSTR szStdOutFilename;
LPCWSTR szStdErrFilename;
- HANDLE hStdOutFile;
- HANDLE hStdErrFile;
- FILE *fpStdOutFile;
- FILE *fpStdErrFile;
- FILE fpStdOutSave;
- FILE fpStdErrSave;
+ FILE *fpStdOutFile;
+ FILE *fpStdErrFile;
} APX_STDWRAP;
/* Use static variables instead of #defines */
@@ -77,6 +74,8 @@
L"US", /* 4 Update Service parameters */
L"IS", /* 5 Install Service */
L"DS", /* 6 Delete Service */
+ L"?", /* 7 Help */
+ L"VS", /* 8 Version */
NULL
};
@@ -124,6 +123,8 @@
/* 33 */ { L"LogLevel", L"Level", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
/* 34 */ { L"StdError", L"StdError", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
/* 35 */ { L"StdOutput", L"StdOutput", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 36 */ { L"LogJniMessages", L"LogJniMessages", L"Log", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 1},
+/* 37 */ { L"PidFile", L"PidFile", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
/* NULL terminate the array */
{ NULL }
};
@@ -183,8 +184,10 @@
#define SO_STDERROR GET_OPT_V(34)
#define SO_STDOUTPUT GET_OPT_V(35)
+#define SO_JNIVFPRINTF GET_OPT_I(36)
+#define SO_PIDFILE GET_OPT_V(37)
-/* Main servic table entry
+/* Main service table entry
* filled at run-time
*/
static SERVICE_TABLE_ENTRYW _service_table[] = {
@@ -200,6 +203,10 @@
static BOOL _jni_startup = FALSE;
/* JVM used for shutdown */
static BOOL _jni_shutdown = FALSE;
+/* Java used as worker */
+static BOOL _java_startup = FALSE;
+/* Java used for shutdown */
+static BOOL _java_shutdown = FALSE;
/* Global variables and objects */
static APXHANDLE gPool;
static APXHANDLE gWorker;
@@ -211,14 +218,16 @@
static LPSTR _jni_classpath = NULL;
static LPCWSTR _jni_rparam = NULL; /* Startup arguments */
static LPCWSTR _jni_sparam = NULL; /* Shutdown arguments */
-static LPSTR _jni_rmethod = NULL; /* Startup arguments */
-static LPSTR _jni_smethod = NULL; /* Shutdown arguments */
-static CHAR _jni_rclass[SIZ_RESLEN] = {'\0'}; /* Startup class */
-static CHAR _jni_sclass[SIZ_RESLEN] = {'\0'}; /* Shutdown class */
+static LPSTR _jni_rmethod = NULL; /* Startup method */
+static LPSTR _jni_smethod = NULL; /* Shutdown method */
+static LPSTR _jni_rclass = NULL; /* Startup class */
+static LPSTR _jni_sclass = NULL; /* Shutdown class */
static HANDLE gShutdownEvent = NULL;
static HANDLE gSignalEvent = NULL;
static HANDLE gSignalThread = NULL;
+static HANDLE gPidfileHandle = NULL;
+static LPWSTR gPidfileName = NULL;
static BOOL gSignalValid = TRUE;
DWORD WINAPI eventThread(LPVOID lpParam)
@@ -247,136 +256,90 @@
BOOL aErr = FALSE;
BOOL aOut = FALSE;
- /* Clear up the handles */
- lpWrapper->fpStdErrFile = NULL;
- lpWrapper->fpStdOutFile = NULL;
-
- /* Save the original streams */
- lpWrapper->fpStdOutSave = *stdout;
- lpWrapper->fpStdErrSave = *stderr;
-
+ if (lpWrapper->szStdOutFilename || lpWrapper->szStdErrFilename)
+ AllocConsole();
/* redirect to file or console */
if (lpWrapper->szStdOutFilename) {
if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
aOut = TRUE;
lpWrapper->szStdOutFilename = apxLogFile(gPool,
lpWrapper->szLogPath,
- NULL,
- L"stdout_");
+ L"service-stdout",
+ NULL, TRUE);
}
/* Delete the file if not in append mode
* XXX: See if we can use the params instead of that.
*/
if (!aOut)
DeleteFileW(lpWrapper->szStdOutFilename);
- lpWrapper->hStdOutFile = CreateFileW(lpWrapper->szStdOutFilename,
- GENERIC_WRITE | GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
- return FALSE;
- /* Allways move to the end of file */
- SetFilePointer(lpWrapper->hStdOutFile, 0, NULL, FILE_END);
+ if ((lpWrapper->fpStdOutFile = _wfopen(lpWrapper->szStdOutFilename,
+ L"a"))) {
+ _dup2(_fileno(lpWrapper->fpStdOutFile), 1);
+ *stdout = *lpWrapper->fpStdOutFile;
+ setvbuf(stdout, NULL, _IONBF, 0);
+ }
}
- else {
- lpWrapper->hStdOutFile = CreateFileW(L"CONOUT$",
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
- return FALSE;
- }
if (lpWrapper->szStdErrFilename) {
if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
aErr = TRUE;
lpWrapper->szStdErrFilename = apxLogFile(gPool,
lpWrapper->szLogPath,
- NULL,
- L"stderr_");
+ L"service-stderr",
+ NULL, TRUE);
}
if (!aErr)
DeleteFileW(lpWrapper->szStdErrFilename);
- lpWrapper->hStdErrFile = CreateFileW(lpWrapper->szStdErrFilename,
- GENERIC_WRITE | GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (IS_INVALID_HANDLE(lpWrapper->hStdErrFile))
- return FALSE;
- SetFilePointer(lpWrapper->hStdErrFile, 0, NULL, FILE_END);
+ if ((lpWrapper->fpStdErrFile = _wfopen(lpWrapper->szStdErrFilename,
+ L"a"))) {
+ _dup2(_fileno(lpWrapper->fpStdErrFile), 2);
+ *stderr = *lpWrapper->fpStdErrFile;
+ setvbuf(stderr, NULL, _IONBF, 0);
+ }
}
- else if (lpWrapper->szStdOutFilename) {
- /* Use the same file handle for stderr as for stdout */
- lpWrapper->szStdErrFilename = lpWrapper->szStdOutFilename;
- lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
+ else if (lpWrapper->fpStdOutFile) {
+ _dup2(_fileno(lpWrapper->fpStdOutFile), 2);
+ *stderr = *lpWrapper->fpStdOutFile;
+ setvbuf(stderr, NULL, _IONBF, 0);
}
- else {
- lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
- }
- /* Open the stream buffers
- * This will redirect all printf to go to the redirected files.
- * It is used for JNI vprintf functionality.
- */
- lpWrapper->fpStdOutFile = _fdopen(_open_osfhandle(
- (intptr_t)lpWrapper->hStdOutFile,
- _O_TEXT), "w");
- lpWrapper->fpStdErrFile = _fdopen(_open_osfhandle(
- (intptr_t)lpWrapper->hStdErrFile,
- _O_TEXT), "w");
- if (lpWrapper->fpStdOutFile) {
- *stdout = *lpWrapper->fpStdOutFile;
- setvbuf(stdout, NULL, _IONBF, 0);
- }
- if (lpWrapper->fpStdErrFile) {
- *stderr = *lpWrapper->fpStdErrFile;
- setvbuf(stderr, NULL, _IONBF, 0);
- }
return TRUE;
}
-static void cleanupStdStreams(APX_STDWRAP *lpWrapper)
-{
- /* Close the redirectied streams */
- if (lpWrapper->fpStdOutFile) {
- fclose(lpWrapper->fpStdOutFile);
- *stdout = lpWrapper->fpStdOutSave;
- }
- if (lpWrapper->fpStdErrFile) {
- fclose(lpWrapper->fpStdErrFile);
- *stderr = lpWrapper->fpStdErrSave;
- }
-}
-
/* Debugging functions */
-static void printUsage(LPAPXCMDLINE lpCmdline)
+static void printUsage(LPAPXCMDLINE lpCmdline, BOOL isHelp)
{
-#ifdef _DEBUG
int i = 0;
- fwprintf(stderr, L"Usage: %s //CMD//Servce [--options]\n",
+ fwprintf(stderr, L"Usage: %s //CMD//Service [--options]\n",
lpCmdline->szExecutable);
fwprintf(stderr, L" Commands:\n");
- fwprintf(stderr, L" //IS//ServiceName Install Service\n");
- fwprintf(stderr, L" //US//ServiceName Update Service parameters\n");
- fwprintf(stderr, L" //DS//ServiceName Delete Service\n");
- fwprintf(stderr, L" //RS//ServiceName Run Service\n");
- fwprintf(stderr, L" //SS//ServiceName Stop Service\n");
- fwprintf(stderr,
- L" //TS//ServiceName Run Service as console application\n");
+ if (isHelp)
+ fwprintf(stderr, L" //? This page\n");
+ fwprintf(stderr, L" //IS[//ServiceName] Install Service\n");
+ fwprintf(stderr, L" //US[//ServiceName] Update Service parameters\n");
+ fwprintf(stderr, L" //DS[//ServiceName] Delete Service\n");
+ fwprintf(stderr, L" //RS[//ServiceName] Run Service\n");
+ fwprintf(stderr, L" //SS[//ServiceName] Stop Service\n");
+ fwprintf(stderr, L" //TS[//ServiceName] Run Service as console application\n");
+ fwprintf(stderr, L" //PP[//Num Seconds] Sleep for n Seconds (defaults to 60)\n");
+ fwprintf(stderr, L" //VS Display version\n");
fwprintf(stderr, L" Options:\n");
while (_options[i].szName) {
fwprintf(stderr, L" --%s\n", _options[i].szName);
++i;
}
+}
+
+static void printVersion(void)
+{
+#ifdef _WIN64
+ int b = 64;
+#else
+ int b = 32;
#endif
+ fwprintf(stderr, L"Commons Daemon Service Runner version %S/Win%d (%S)\n",
+ PRG_VERSION, b, __DATE__);
+ fwprintf(stderr, L"Copyright (c) 2000-2010 The Apache Software Foundation.\n");
}
+
/* Display configuration parameters */
static void dumpCmdline()
{
@@ -424,7 +387,11 @@
lpCmdline->szApplication,
APXREG_SOFTWARE | APXREG_SERVICE);
if (IS_INVALID_HANDLE(hRegistry)) {
- apxLogWrite(APXLOG_MARK_SYSERR);
+ if (GetLastError() == ERROR_FILE_NOT_FOUND)
+ apxLogWrite(APXLOG_MARK_WARN "The system cannot find the Registry key for service '%S'",
+ lpCmdline->szApplication);
+ else
+ apxLogWrite(APXLOG_MARK_SYSERR);
return FALSE;
}
/* browse through options */
@@ -554,18 +521,18 @@
/* Check if --Install is provided */
if (!SO_INSTALL) {
- lstrcpyW(szImage, lpCmdline->szExePath);
- lstrcatW(szImage, L"\\");
- lstrcatW(szImage, lpCmdline->szExecutable);
- lstrcatW(szImage, L".exe");
+ lstrlcpyW(szImage, SIZ_HUGLEN, lpCmdline->szExePath);
+ lstrlcatW(szImage, SIZ_HUGLEN, L"\\");
+ lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szExecutable);
+ lstrlcatW(szImage, SIZ_HUGLEN, L".exe");
}
else
lstrcpyW(szImage, SO_INSTALL);
/* Replace not needed qoutes */
apxStrQuoteInplaceW(szImage);
/* Add run-service command line option */
- lstrcatW(szImage, L" //RS//");
- lstrcatW(szImage, lpCmdline->szApplication);
+ lstrlcatW(szImage, SIZ_HUGLEN, L" //RS//");
+ lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szApplication);
SO_INSTALL = apxPoolStrdupW(gPool, szImage);
/* Ensure that option gets saved in the registry */
ST_INSTALL |= APXCMDOPT_FOUND;
@@ -607,11 +574,11 @@
apxCloseHandle(hService);
if (rv) {
saveConfiguration(lpCmdline);
- apxLogWrite(APXLOG_MARK_INFO "Service %S installed",
+ apxLogWrite(APXLOG_MARK_INFO "Service '%S' installed",
lpCmdline->szApplication);
}
else
- apxLogWrite(APXLOG_MARK_ERROR "Failed installing %S service",
+ apxLogWrite(APXLOG_MARK_ERROR "Failed installing '%S' service",
lpCmdline->szApplication);
return rv;
@@ -632,8 +599,8 @@
if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
WCHAR szWndManagerClass[SIZ_RESLEN];
HANDLE hWndManager = NULL;
- lstrcpyW(szWndManagerClass, lpCmdline->szApplication);
- lstrcatW(szWndManagerClass, L"_CLASS");
+ lstrlcpyW(szWndManagerClass, SIZ_RESLEN, lpCmdline->szApplication);
+ lstrlcatW(szWndManagerClass, SIZ_RESLEN, L"_CLASS");
/* Close the monitor application if running */
if ((hWndManager = FindWindowW(szWndManagerClass, NULL)) != NULL) {
SendMessage(hWndManager, WM_CLOSE, 0, 0);
@@ -642,12 +609,12 @@
}
if (rv) {
/* Delete all service registry settings */
- apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, TRUE);
- apxLogWrite(APXLOG_MARK_DEBUG "Service %S deleted",
+ apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, KREG_WOW6432, TRUE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Service '%S' deleted",
lpCmdline->szApplication);
}
else {
- apxDisplayError(TRUE, NULL, 0, "Unable to delete %S service",
+ apxDisplayError(FALSE, NULL, 0, "Unable to delete '%S' service",
lpCmdline->szApplication);
}
apxCloseHandle(hService);
@@ -660,7 +627,8 @@
APXHANDLE hService;
BOOL rv = FALSE;
- apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+ apxLogWrite(APXLOG_MARK_INFO "Stopping service '%S' ...",
+ lpCmdline->szApplication);
hService = apxCreateService(gPool, GENERIC_ALL, FALSE);
if (IS_INVALID_HANDLE(hService)) {
apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
@@ -677,15 +645,15 @@
NULL,
NULL);
if (rv)
- apxLogWrite(APXLOG_MARK_INFO "Service %S stopped",
+ apxLogWrite(APXLOG_MARK_INFO "Service '%S' stopped",
lpCmdline->szApplication);
else
- apxLogWrite(APXLOG_MARK_ERROR "Failed to stop %S service",
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to stop '%S' service",
lpCmdline->szApplication);
}
else
- apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
+ apxDisplayError(FALSE, NULL, 0, "Unable to open '%S' service",
lpCmdline->szApplication);
apxCloseHandle(hService);
apxLogWrite(APXLOG_MARK_INFO "Stop service finished.");
@@ -695,7 +663,7 @@
static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
{
APXHANDLE hService;
- BOOL rv = FALSE;
+ BOOL rv = TRUE;
apxLogWrite(APXLOG_MARK_INFO "Updating service...");
@@ -706,7 +674,17 @@
}
SetLastError(0);
/* Open the service */
- if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ if (!apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ /* Close the existing manager handler.
+ * It will be reopened inside install.
+ */
+ apxCloseHandle(hService);
+ /* In case service doesn't exist try to install it.
+ * Install will fail if there is no minimum parameters required.
+ */
+ return docmdInstallService(lpCmdline);
+ }
+ else {
DWORD dwStart = SERVICE_NO_CHANGE;
DWORD dwType = SERVICE_NO_CHANGE;
LPCWSTR su = NULL;
@@ -721,12 +699,12 @@
apxLogWrite(APXLOG_MARK_DEBUG "Setting service password %S",
SO_SPASSWORD);
}
- apxServiceSetNames(hService,
- NULL, /* Never update the ImagePath */
- SO_DISPLAYNAME,
- SO_DESCRIPTION,
- su,
- sp);
+ rv = (rv && apxServiceSetNames(hService,
+ NULL, /* Never update the ImagePath */
+ SO_DISPLAYNAME,
+ SO_DESCRIPTION,
+ su,
+ sp));
/* Update the --Startup mode */
if (ST_STARTUP & APXCMDOPT_FOUND) {
if (!lstrcmpiW(SO_STARTUP, PRSRV_AUTO))
@@ -738,21 +716,22 @@
if (!lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE))
dwType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS;
}
- apxServiceSetOptions(hService,
- dwType,
- dwStart,
- SERVICE_NO_CHANGE);
+ rv = (rv && apxServiceSetOptions(hService,
+ dwType,
+ dwStart,
+ SERVICE_NO_CHANGE));
- apxLogWrite(APXLOG_MARK_INFO "Service %S updated",
+ apxLogWrite(APXLOG_MARK_INFO "Service '%S' updated",
lpCmdline->szApplication);
- saveConfiguration(lpCmdline);
+ rv = (rv && saveConfiguration(lpCmdline));
}
+ apxCloseHandle(hService);
+ if (rv)
+ apxLogWrite(APXLOG_MARK_INFO "Update service finished.");
else
- apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
- lpCmdline->szApplication);
- apxCloseHandle(hService);
- apxLogWrite(APXLOG_MARK_INFO "Update service finished.");
+ apxLogWrite(APXLOG_MARK_INFO "Update service '%S' failed.",
+ lpCmdline->szApplication);
return rv;
}
@@ -835,7 +814,7 @@
return 1;
}
if (!apxJavaInitialize(hWorker, _jni_classpath, _jni_jvmoptions,
- SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
+ SO_JVMMS, SO_JVMMX, SO_JVMSS, SO_JNIVFPRINTF)) {
rv = 2;
apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
goto cleanup;
@@ -880,7 +859,15 @@
goto cleanup;
}
/* Assemble the command line */
- nArgs = apxMultiSzToArrayW(gPool, SO_STOPPARAMS, &pArgs);
+ if (_java_shutdown) {
+ nArgs = apxJavaCmdInitialize(gPool, SO_CLASSPATH, SO_STOPCLASS,
+ SO_JVMOPTIONS, SO_JVMMS, SO_JVMMX,
+ SO_JVMSS, SO_STOPPARAMS, &pArgs);
+ }
+ else {
+ nArgs = apxMultiSzToArrayW(gPool, SO_STOPPARAMS, &pArgs);
+ }
+
/* Pass the argv to child process */
if (!apxProcessSetCommandArgsW(hWorker, SO_STOPIMAGE,
nArgs, pArgs)) {
@@ -903,7 +890,7 @@
apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
goto cleanup;
} else {
- apxLogWrite(APXLOG_MARK_DEBUG "Waiting stop worker to finish...");
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for stop worker to finish...");
apxHandleWait(hWorker, INFINITE, FALSE);
apxLogWrite(APXLOG_MARK_DEBUG "Stop worker finished.");
}
@@ -980,6 +967,14 @@
apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
return TRUE; /* Nothing to do */
}
+ if (SO_PIDFILE) {
+ gPidfileName = apxLogFile(gPool, SO_LOGPATH, SO_PIDFILE, NULL, FALSE);
+ if (GetFileAttributesW(gPidfileName) != INVALID_FILE_ATTRIBUTES) {
+ /* Pid file exists */
+ apxLogWrite(APXLOG_MARK_ERROR "Pid file '%S' exists", gPidfileName);
+ return 1;
+ }
+ }
GetSystemTimeAsFileTime(&fts);
if (_jni_startup) {
if (SO_STARTPATH) {
@@ -995,7 +990,7 @@
return 1;
}
if (!apxJavaInitialize(gWorker, _jni_classpath, _jni_jvmoptions,
- SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
+ SO_JVMMS, SO_JVMMX, SO_JVMSS, SO_JNIVFPRINTF)) {
rv = 2;
apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
goto cleanup;
@@ -1009,7 +1004,7 @@
apxJavaSetOut(gWorker, FALSE, gStdwrap.szStdOutFilename);
if (!apxJavaStart(gWorker)) {
rv = 4;
- apxLogWrite(APXLOG_MARK_ERROR "Failed starting Java");
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to start Java");
goto cleanup;
}
apxLogWrite(APXLOG_MARK_DEBUG "Java started %s", _jni_rclass);
@@ -1023,7 +1018,7 @@
SO_PASSWORD,
FALSE);
if (IS_INVALID_HANDLE(gWorker)) {
- apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to create process");
return 1;
}
if (!apxProcessSetExecutableW(gWorker, SO_STARTIMAGE)) {
@@ -1033,7 +1028,15 @@
goto cleanup;
}
/* Assemble the command line */
- nArgs = apxMultiSzToArrayW(gPool, SO_STARTPARAMS, &pArgs);
+ if (_java_startup) {
+ nArgs = apxJavaCmdInitialize(gPool, SO_CLASSPATH, SO_STARTCLASS,
+ SO_JVMOPTIONS, SO_JVMMS, SO_JVMMX,
+ SO_JVMSS, SO_STARTPARAMS, &pArgs);
+ }
+ else {
+ nArgs = apxMultiSzToArrayW(gPool, SO_STARTPARAMS, &pArgs);
+ }
+
/* Pass the argv to child process */
if (!apxProcessSetCommandArgsW(gWorker, SO_STARTIMAGE,
nArgs, pArgs)) {
@@ -1053,7 +1056,7 @@
*/
if (!apxProcessExecute(gWorker)) {
rv = 5;
- apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to execute process");
goto cleanup;
}
}
@@ -1061,6 +1064,27 @@
FILETIME fte;
ULARGE_INTEGER s, e;
DWORD nms;
+ /* Create pidfile */
+ if (gPidfileName) {
+ char pids[32];
+ gPidfileHandle = CreateFileW(gPidfileName,
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_NEW,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (gPidfileHandle != INVALID_HANDLE_VALUE) {
+ DWORD wr = 0;
+ if (_jni_startup)
+ _snprintf(pids, 32, "%d\r\n", GetCurrentProcessId());
+ else
+ _snprintf(pids, 32, "%d\r\n", apxProcessGetPid(gWorker));
+ WriteFile(gPidfileHandle, pids, (DWORD)strlen(pids), &wr, NULL);
+ FlushFileBuffers(gPidfileName);
+ }
+ }
GetSystemTimeAsFileTime(&fte);
s.LowPart = fts.dwLowDateTime;
s.HighPart = fts.dwHighDateTime;
@@ -1166,12 +1190,12 @@
apxLogWrite(APXLOG_MARK_DEBUG "Inside ServiceMain...");
if (_service_name) {
- WCHAR en[SIZ_DESLEN];
+ WCHAR en[SIZ_HUGLEN];
int i;
PSECURITY_ATTRIBUTES sa = GetNullACL();
- lstrcpyW(en, L"Global\\");
- lstrcatW(en, _service_name);
- lstrcatW(en, PRSRV_SIGNAL);
+ lstrlcpyW(en, SIZ_DESLEN, L"Global\\");
+ lstrlcatW(en, SIZ_DESLEN, _service_name);
+ lstrlcatW(en, SIZ_DESLEN, PRSRV_SIGNAL);
for (i = 7; i < lstrlenW(en); i++) {
if (en[i] >= L'a' && en[i] <= L'z')
en[i] = en[i] - 32;
@@ -1188,19 +1212,26 @@
if (SO_STARTMODE) {
if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
_jni_startup = TRUE;
- WideToAscii(SO_STARTCLASS, _jni_rclass);
+ _jni_rclass = WideToUTF8(SO_STARTCLASS);
/* Exchange all dots with slashes */
apxStrCharReplaceA(_jni_rclass, '.', '/');
_jni_rparam = SO_STARTPARAMS;
}
else if (!lstrcmpiW(SO_STARTMODE, PRSRV_JAVA)) {
- LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
+ LPWSTR jx = NULL, szJH = SO_JAVAHOME;
+ if (!szJH)
+ szJH = apxGetJavaSoftHome(gPool, FALSE);
if (szJH) {
jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
lstrcpyW(jx, szJH);
lstrcatW(jx, PRSRV_JBIN);
SO_STARTPATH = szJH;
}
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to find Java Runtime Environment.");
+ goto cleanup;
+ }
+ _java_startup = TRUE;
/* StartImage now contains the full path to the java.exe */
SO_STARTIMAGE = jx;
}
@@ -1209,18 +1240,25 @@
if (SO_STOPMODE) {
if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
_jni_shutdown = TRUE;
- WideToAscii(SO_STOPCLASS, _jni_sclass);
+ _jni_sclass = WideToUTF8(SO_STOPCLASS);
apxStrCharReplaceA(_jni_sclass, '.', '/');
_jni_sparam = SO_STOPPARAMS;
}
else if (!lstrcmpiW(SO_STOPMODE, PRSRV_JAVA)) {
- LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
+ LPWSTR jx = NULL, szJH = SO_JAVAHOME;
+ if (!szJH)
+ szJH = apxGetJavaSoftHome(gPool, FALSE);
if (szJH) {
jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
lstrcpyW(jx, szJH);
lstrcatW(jx, PRSRV_JBIN);
SO_STOPPATH = szJH;
}
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to find Java Runtime Environment.");
+ goto cleanup;
+ }
+ _java_shutdown = TRUE;
/* StopImage now contains the full path to the java.exe */
SO_STOPIMAGE = jx;
}
@@ -1256,26 +1294,39 @@
/* Service is started */
DWORD rv;
reportServiceStatus(SERVICE_RUNNING, NO_ERROR, 0);
- apxLogWrite(APXLOG_MARK_DEBUG "Waiting worker to finish...");
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for worker to finish...");
/* Set console handler to capture CTRL events */
SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
rv = apxHandleWait(gWorker, INFINITE, FALSE);
apxLogWrite(APXLOG_MARK_DEBUG "Worker finished.");
- reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
- fflush(stdout);
}
else {
apxLogWrite(APXLOG_MARK_ERROR "ServiceStart returned %d", rc);
goto cleanup;
}
if (gShutdownEvent) {
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
/* Ensure that shutdown thread exits before us */
apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
- WaitForSingleObject(gShutdownEvent, 60 * 1000);
+ WaitForSingleObject(gShutdownEvent, ONE_MINUTE);
apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
CloseHandle(gShutdownEvent);
+ /* This will cause to wait for all threads to exit
+ */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to exit");
+ apxDestroyJvm(ONE_MINUTE);
}
+ else {
+ /* We came here without shutdown event
+ * Probably because main() returned without ensuring all threads
+ * have finished
+ */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for all threads to exit");
+ apxDestroyJvm(INFINITE);
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+ }
+ apxLogWrite(APXLOG_MARK_DEBUG "JVM destroyed.");
reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
return;
@@ -1293,24 +1344,29 @@
_service_mode = FALSE;
_service_name = lpCmdline->szApplication;
- apxLogWrite(APXLOG_MARK_INFO "Debugging Service...");
+ apxLogWrite(APXLOG_MARK_INFO "Debugging '%S' Service...", _service_name);
serviceMain(0, NULL);
apxLogWrite(APXLOG_MARK_INFO "Debug service finished.");
-
+ SAFE_CLOSE_HANDLE(gPidfileHandle);
+ if (gPidfileName)
+ DeleteFileW(gPidfileName);
return rv;
}
BOOL docmdRunService(LPAPXCMDLINE lpCmdline)
{
BOOL rv = FALSE;
+
_service_mode = TRUE;
-
- apxLogWrite(APXLOG_MARK_INFO "Running Service...");
_service_name = lpCmdline->szApplication;
+ apxLogWrite(APXLOG_MARK_INFO "Running '%S' Service...", _service_name);
_service_table[0].lpServiceName = lpCmdline->szApplication;
_service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTIONW)serviceMain;
- rv = (StartServiceCtrlDispatcherW(_service_table) == FALSE);
+ rv = (StartServiceCtrlDispatcherW(_service_table) != 0);
apxLogWrite(APXLOG_MARK_INFO "Run service finished.");
+ SAFE_CLOSE_HANDLE(gPidfileHandle);
+ if (gPidfileName)
+ DeleteFileW(gPidfileName);
return rv;
}
@@ -1320,6 +1376,18 @@
LPAPXCMDLINE lpCmdline;
+ if (argc > 1 && strncmp(argv[1], "//PP", 4) == 0) {
+ /* Handy sleep routine defaulting to 1 minute */
+ DWORD ss = 60;
+ if (argv[1][4] && argv[1][5] && argv[1][6]) {
+ int us = atoi(argv[1] + 6);
+ if (us > 0)
+ ss = (DWORD)us;
+ }
+ Sleep(ss * 1000);
+ ExitProcess(0);
+ return;
+ }
apxHandleManagerInitialize();
/* Create the main Pool */
gPool = apxPoolCreate(NULL, 0);
@@ -1331,17 +1399,19 @@
goto cleanup;
}
apxCmdlineLoadEnvVars(lpCmdline);
- if (lpCmdline->dwCmdIndex < 5 &&
- !loadConfiguration(lpCmdline)) {
- apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
- rv = 2;
- goto cleanup;
+ if (lpCmdline->dwCmdIndex < 5) {
+ if (!loadConfiguration(lpCmdline) &&
+ lpCmdline->dwCmdIndex < 4) {
+ apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
+ rv = 2;
+ goto cleanup;
+ }
}
apxLogOpen(gPool, SO_LOGPATH, SO_LOGPREFIX);
apxLogLevelSetW(NULL, SO_LOGLEVEL);
- apxLogWrite(APXLOG_MARK_DEBUG "Procrun log initialized");
- apxLogWrite(APXLOG_MARK_INFO "Procrun (%s) started", PRG_VERSION);
+ apxLogWrite(APXLOG_MARK_DEBUG "Commons Daemon procrun log initialized");
+ apxLogWrite(APXLOG_MARK_INFO "Commons Daemon procrun (%s) started", PRG_VERSION);
AplZeroMemory(&gStdwrap, sizeof(APX_STDWRAP));
@@ -1352,6 +1422,18 @@
gStdwrap.szStdErrFilename = SO_STDERROR;
}
redirectStdStreams(&gStdwrap);
+ if (lpCmdline->dwCmdIndex == 2) {
+ SYSTEMTIME t;
+ GetLocalTime(&t);
+ fprintf(stdout, "\n%d-%02d-%02d %02d:%02d:%02d "
+ "Commons Daemon procrun stdout initialized\n",
+ t.wYear, t.wMonth, t.wDay,
+ t.wHour, t.wMinute, t.wSecond);
+ fprintf(stderr, "\n%d-%02d-%02d %02d:%02d:%02d "
+ "Commons Daemon procrun stderr initialized\n",
+ t.wYear, t.wMonth, t.wDay,
+ t.wHour, t.wMinute, t.wSecond);
+ }
switch (lpCmdline->dwCmdIndex) {
case 1: /* Run Service as console application */
if (!docmdDebugService(lpCmdline))
@@ -1377,23 +1459,33 @@
if (!docmdDeleteService(lpCmdline))
rv = 8;
break;
+ case 7: /* Print Usage and exit */
+ printUsage(lpCmdline, TRUE);
+ break;
+ case 8: /* Print version and exit */
+ printVersion();
+ break;
default:
/* Unknown command option */
apxLogWrite(APXLOG_MARK_ERROR "Unknown command line option");
- printUsage(lpCmdline);
+ printUsage(lpCmdline, FALSE);
rv = 99;
break;
}
cleanup:
- apxLogWrite(APXLOG_MARK_INFO "Procrun finished.");
+ if (rv)
+ apxLogWrite(APXLOG_MARK_ERROR "Commons Daemon procrun failed "
+ "with exit value: %d", rv);
+ else
+ apxLogWrite(APXLOG_MARK_INFO "Commons Daemon procrun finished");
if (lpCmdline)
apxCmdlineFree(lpCmdline);
if (_service_status_handle)
CloseHandle(_service_status_handle);
_service_status_handle = NULL;
+ _flushall();
apxLogClose(NULL);
apxHandleManagerDestroy();
- cleanupStdStreams(&gStdwrap);
ExitProcess(rv);
}
Modified: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h 2010-07-21 20:01:54 UTC (rev 2689)
@@ -13,20 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
/* ====================================================================
* jar2exe -- convert .jar file to WIN32 executable.
* Contributed by Mladen Turk <mturk(a)apache.org>
* 05 Aug 2003
- * ====================================================================
+ * ====================================================================
*/
#ifndef _PRUNSRV_H
#define _PRUNSRV_H
#undef PRG_VERSION
-#define PRG_VERSION "2.0.4.1"
-#define CSV_VERSION 2,0,4,1
+#define PRG_VERSION "2.0.5.1"
+#define CSV_VERSION 2,0,5,1
#define PRG_REGROOT L"JBoss\\JBoss Web 2"
#endif /* _PRUNSRV_H */
Modified: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc 2010-07-21 20:01:54 UTC (rev 2689)
@@ -13,22 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "apxwin.h"
#include "prunsrv.h"
-#define STR_COPYRIGHT "Copyright � 2007 Red Hat Middleware, LLC. " \
+#define STR_COPYRIGHT "Copyright � 2010 Red Hat, Inc. " \
"or its licensors, as applicable."
#define STR_LICENSE "Distributable under LGPL license. " \
"See terms of license at gnu.org."
-#define STR_COMPANY "Red Hat�, Inc."
-#define STR_TRADEMARK "� Red Hat Inc."
+#define STR_COMPANY "Red Hat�, Inc."
+#define STR_TRADEMARK "� Red Hat Inc."
#define STR_PRODUCT "JBoss Web Service wrapper"
-IDI_MAINICON ICON "../../resources/jboss.ico"
-IDI_REDHATICON ICON "../../resources/jboss.ico"
+IDI_MAINICON ICON "../../resources/jboss.ico"
+IDI_REDHATICON ICON "../../resources/jboss.ico"
1 VERSIONINFO
FILEVERSION CSV_VERSION
@@ -62,4 +62,4 @@
BEGIN
VALUE "Translation", 0x409, 1200
END
-END
+END
Modified: trunk/utils/windows/native/service/procrun/src/cmdline.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/cmdline.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/cmdline.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -102,34 +102,38 @@
*p = L'\0';
}
}
- if (lpszCommands && _st_sys_argc > 1 && lstrlenW(_st_sys_argvw[1]) > 5) {
- if (_st_sys_argvw[1][0] == L'/' &&
- _st_sys_argvw[1][1] == L'/' &&
- _st_sys_argvw[1][5] == L'/') { /* allow max tree char command */
- l = 2;
- while (_st_sys_argvw[1][l] != L'/') {
- cmd[l - 2] = _st_sys_argvw[1][l];
+ if (lpszCommands && _st_sys_argc > 1 && lstrlenW(_st_sys_argvw[1]) > 2) {
+ LPWSTR ca = _st_sys_argvw[1];
+ if (ca[0] == L'/' && ca[1] == L'/') {
+ l = 0;
+ ca += 2;
+ while (*ca && *ca != L'/') {
+ cmd[l] = *ca;
if (l++ > 3)
break;
+ ca++;
}
- cmd[l - 2] = L'\0';
+ cmd[l] = L'\0';
while (lpszCommands[i]) {
if (lstrcmpW(lpszCommands[i++], cmd) == 0) {
lpCmdline->dwCmdIndex = i;
- s = 2;
break;
}
}
if (lpCmdline->dwCmdIndex) {
- _st_sys_argvw[1][l+1] = L'\0';
- lpCmdline->szApplication = &(_st_sys_argvw[1][l+2]);
- if (!lstrlenW(lpCmdline->szApplication))
+ while (*ca == '/')
+ *(ca++) = L'\0';
+ if (*ca == '\0')
lpCmdline->szApplication = _st_sys_argvw[0];
+ else
+ lpCmdline->szApplication = ca;
}
else {
- apxLogWrite(APXLOG_MARK_ERROR "Unrecognized cmd option %s", cmd);
- s = 2;
+ apxLogWrite(APXLOG_MARK_ERROR "Unrecognized cmd option %S",
+ _st_sys_argvw[1]);
+ return NULL;
}
+ s = 2;
}
}
else {
@@ -218,6 +222,14 @@
break;
}
}
+ if (match == 0) {
+ /* --unknown option
+ *
+ */
+ apxLogWrite(APXLOG_MARK_ERROR "Unrecognized program option %S",
+ _st_sys_argvw[i]);
+ return NULL;
+ }
}
if (i < (DWORD)_st_sys_argc) {
lpCmdline->dwArgc = _st_sys_argc - i;
@@ -252,8 +264,8 @@
while (lpCmdline->lpOptions[i].szName) {
DWORD l;
WCHAR szVar[SIZ_HUGLEN];
- lstrcpyW(szEnv, L"PR_");
- lstrcatW(szEnv, lpCmdline->lpOptions[i].szName);
+ lstrlcpyW(szEnv, SIZ_HUGLEN, L"PR_");
+ lstrlcatW(szEnv, SIZ_HUGLEN, lpCmdline->lpOptions[i].szName);
l = GetEnvironmentVariableW(szEnv, szVar, SIZ_HUGMAX);
if (l == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
apxLogWrite(APXLOG_MARK_ERROR "Error geting environment variable %S",
@@ -265,14 +277,17 @@
lpCmdline->lpOptions[i].szValue = apxPoolStrdupW(lpCmdline->hPool, szVar);
lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND;
}
+ else if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_INT)) {
+ lpCmdline->lpOptions[i].dwValue = (DWORD)apxAtoulW(szVar);
+ lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND;
+ }
else if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_MSZ)) {
LPWSTR pp;
BOOL insquote = FALSE, indquote = FALSE;
DWORD sp = 0;
+ lpCmdline->lpOptions[i].dwValue = (lstrlenW(szVar) + 2) * sizeof(WCHAR);
lpCmdline->lpOptions[i].szValue = apxPoolCalloc(lpCmdline->hPool,
- (lstrlenW(szVar) + 2) *
- sizeof(WCHAR));
- lstrcpyW(lpCmdline->lpOptions[i].szValue, szVar);
+ lpCmdline->lpOptions[i].dwValue);
pp = szVar;
while(*pp) {
if (*pp == L'\'')
@@ -292,4 +307,5 @@
++i;
}
-}
\ No newline at end of file
+}
+
Modified: trunk/utils/windows/native/service/procrun/src/handles.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/handles.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/handles.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -407,9 +407,12 @@
{
if (szSource) {
LPWSTR szDest;
- DWORD l = lstrlenA(szSource);
- szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
- AsciiToWide(szSource, szDest);
+ int cch = MultiByteToWideChar(CP_UTF8, 0, szSource, -1, NULL, 0);
+ szDest = (LPWSTR)apxPoolAlloc(hPool, cch * sizeof(WCHAR));
+ if (!MultiByteToWideChar(CP_UTF8, 0, szSource, -1, szDest, cch)) {
+ apxFree(szDest);
+ return NULL;
+ }
return szDest;
}
else
Modified: trunk/utils/windows/native/service/procrun/src/javajni.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/javajni.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/javajni.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -45,13 +45,17 @@
DYNOLAD_TYPE_DECLARE(JNI_GetCreatedJavaVMs, JNICALL, jint)(JavaVM **, jsize, jsize *);
static DYNLOAD_FPTR_DECLARE(JNI_GetCreatedJavaVMs) = NULL;
-static HANDLE _st_sys_jvmDllHandle = NULL;
+static HANDLE _st_sys_jvmDllHandle = NULL;
+static JavaVM *_st_sys_jvm = NULL;
+DYNOLAD_TYPE_DECLARE(SetDllDirectoryW, WINAPI, BOOL)(LPCWSTR);
+static DYNLOAD_FPTR_DECLARE(SetDllDirectoryW) = NULL;
+
#define JVM_DELETE_CLAZZ(jvm, cl) \
APXMACRO_BEGIN \
- if ((jvm)->lpEnv && (jvm)->##cl.jClazz) { \
- (*((jvm)->lpEnv))->DeleteGlobalRef((jvm)->lpEnv, (jvm)->##cl.jClazz); \
- (jvm)->##cl.jClazz = NULL; \
+ if ((jvm)->lpEnv && (jvm)->cl.jClazz) { \
+ (*((jvm)->lpEnv))->DeleteGlobalRef((jvm)->lpEnv, (jvm)->cl.jClazz); \
+ (jvm)->cl.jClazz = NULL; \
} APXMACRO_END
#define JVM_EXCEPTION_CHECK(jvm) \
@@ -80,21 +84,23 @@
(*(lpJava->lpEnv))->DeleteLocalRef(lpJava->lpEnv, obj)
#define JNICALL_0(fName) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv))
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv))
#define JNICALL_1(fName, a1) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1)))
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1)))
#define JNICALL_2(fName, a1, a2) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2)))
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1), (a2)))
#define JNICALL_3(fName, a1, a2, a3) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3)))
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1), (a2), (a3)))
#define JNICALL_4(fName, a1, a2, a3, a4) \
- ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3), (a4)))
+ ((*(lpJava->lpEnv))->fName(lpJava->lpEnv, (a1), (a2), (a3), (a4)))
typedef struct APXJAVASTDCLAZZ {
+ CHAR sClazz[1024];
+ CHAR sMethod[512];
jclass jClazz;
jmethodID jMethod;
jobject jObject;
@@ -117,11 +123,16 @@
} APXJAVAVM, *LPAPXJAVAVM;
#define JAVA_CLASSPATH "-Djava.class.path="
+#define JAVA_CLASSPATH_W L"-Djava.class.path="
#define JAVA_CLASSSTRING "java/lang/String"
static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
{
- jint _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
+ jint _iStatus;
+
+ if (!_st_sys_jvm)
+ return FALSE;
+ _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
(void **)&(lpJava->lpEnv),
lpJava->iVersion);
if (_iStatus != JNI_OK) {
@@ -139,8 +150,9 @@
static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
{
- jint _iStatus = (*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm);
- if (_iStatus != JNI_OK) {
+ if (!_st_sys_jvm)
+ return FALSE;
+ if ((*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm) != JNI_OK) {
lpJava->lpEnv = NULL;
return FALSE;
}
@@ -152,6 +164,7 @@
{
UINT errMode;
LPWSTR dllJvmPath = (LPWSTR)szJvmDllPath;
+ DYNLOAD_FPTR_DECLARE(SetDllDirectoryW);
if (!IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
return TRUE; /* jvm.dll is already loaded */
@@ -168,6 +181,25 @@
if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
_st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH);
+
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+ WCHAR jreBinPath[SIZ_PATHLEN];
+ DWORD i, l = 0;
+
+ lstrlcpyW(jreBinPath, SIZ_PATHLEN, dllJvmPath);
+ DYNLOAD_FPTR_ADDRESS(SetDllDirectoryW, KERNEL32);
+ for (i = lstrlenW(jreBinPath); i > 0, l < 2; i--) {
+ if (jreBinPath[i] == L'\\' || jreBinPath[i] == L'/') {
+ jreBinPath[i] = L'\0';
+ DYNLOAD_CALL(SetDllDirectoryW)(jreBinPath);
+ l++;
+ }
+ }
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
+ LOAD_WITH_ALTERED_SEARCH_PATH);
+ }
/* Restore the error mode signalization */
SetErrorMode(errMode);
if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
@@ -200,7 +232,7 @@
lpJava = APXHANDLE_DATA(hObject);
switch (uMsg) {
case WM_CLOSE:
- if (lpJava->lpJvm) {
+ if (_st_sys_jvm && lpJava->lpJvm) {
if (!IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
if (GetExitCodeThread(lpJava->hWorkerThread, &dwJvmRet) &&
dwJvmRet == STILL_ACTIVE) {
@@ -214,11 +246,6 @@
__apxJvmDetach(lpJava);
/* Check if this is the jvm loader */
if (!lpJava->iVmCount && _st_sys_jvmDllHandle) {
-#if 0
- /* Do not destroy if we terminated the worker thread */
- if (dwJvmRet != STILL_ACTIVE)
- (*(lpJava->lpJvm))->DestroyJavaVM(lpJava->lpJvm);
-#endif
/* Unload JVM dll */
FreeLibrary(_st_sys_jvmDllHandle);
_st_sys_jvmDllHandle = NULL;
@@ -260,9 +287,44 @@
lpJava = APXHANDLE_DATA(hJava);
lpJava->lpJvm = lpJvm;
lpJava->iVmCount = iVmCount;
+ if (!_st_sys_jvm)
+ _st_sys_jvm = lpJvm;
return hJava;
}
+static DWORD WINAPI __apxJavaDestroyThread(LPVOID lpParameter)
+{
+ JavaVM *lpJvm = (JavaVM *)lpParameter;
+ (*lpJvm)->DestroyJavaVM(lpJvm);
+ return 0;
+}
+
+BOOL
+apxDestroyJvm(DWORD dwTimeout)
+{
+ if (_st_sys_jvm) {
+ DWORD tid;
+ HANDLE hWaiter;
+ BOOL rv = FALSE;
+ JavaVM *lpJvm = _st_sys_jvm;
+
+ _st_sys_jvm = NULL;
+ (*lpJvm)->DetachCurrentThread(lpJvm);
+ hWaiter = CreateThread(NULL, 0, __apxJavaDestroyThread,
+ (void *)lpJvm, 0, &tid);
+ if (IS_INVALID_HANDLE(hWaiter)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ if (WaitForSingleObject(hWaiter, dwTimeout) == WAIT_OBJECT_0)
+ rv = TRUE;
+ CloseHandle(hWaiter);
+ return rv;
+ }
+ else
+ return FALSE;
+}
+
static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
LPCSTR lpString,
JavaVMOption **lppArray,
@@ -313,12 +375,12 @@
BOOL
apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
- DWORD dwSs)
+ DWORD dwSs, DWORD bJniVfprintf)
{
LPAPXJAVAVM lpJava;
JavaVMInitArgs vmArgs;
JavaVMOption *lpJvmOptions;
- DWORD i, nOptions, sOptions = 2;
+ DWORD i, nOptions, sOptions = 0;
BOOL rv = FALSE;
if (hJava->dwType != APXHANDLE_TYPE_JVM)
return FALSE;
@@ -355,17 +417,25 @@
++sOptions;
if (dwSs)
++sOptions;
+ if (bJniVfprintf)
+ ++sOptions;
+ if (szClassPath && *szClassPath)
+ ++sOptions;
nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
&lpJvmOptions, sOptions);
- szCp = apxPoolAlloc(hJava->hPool, sizeof(JAVA_CLASSPATH) + lstrlenA(szClassPath));
- lstrcpyA(szCp, JAVA_CLASSPATH);
- lstrcatA(szCp, szClassPath);
- lpJvmOptions[nOptions - sOptions].optionString = szCp;
- --sOptions;
- /* default JNI error printer */
- lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
- lpJvmOptions[nOptions - sOptions].extraInfo = __apxJniVfprintf;
- --sOptions;
+ if (szClassPath && *szClassPath) {
+ szCp = apxPoolAlloc(hJava->hPool, sizeof(JAVA_CLASSPATH) + lstrlenA(szClassPath));
+ lstrcpyA(szCp, JAVA_CLASSPATH);
+ lstrcatA(szCp, szClassPath);
+ lpJvmOptions[nOptions - sOptions].optionString = szCp;
+ --sOptions;
+ }
+ if (bJniVfprintf) {
+ /* default JNI error printer */
+ lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
+ lpJvmOptions[nOptions - sOptions].extraInfo = __apxJniVfprintf;
+ --sOptions;
+ }
if (dwMs) {
wsprintfA(iB[0], "-Xms%dm", dwMs);
lpJvmOptions[nOptions - sOptions].optionString = iB[0];
@@ -395,8 +465,11 @@
apxLogWrite(APXLOG_MARK_ERROR "CreateJavaVM Failed");
rv = FALSE;
}
- else
+ else {
rv = TRUE;
+ if (!_st_sys_jvm)
+ _st_sys_jvm = lpJava->lpJvm;
+ }
apxFree(szCp);
apxFree(lpJvmOptions);
}
@@ -420,6 +493,100 @@
return FALSE;
}
+/* ANSI version only */
+DWORD
+apxJavaCmdInitialize(APXHANDLE hPool, LPCWSTR szClassPath, LPCWSTR szClass,
+ LPCWSTR szOptions, DWORD dwMs, DWORD dwMx,
+ DWORD dwSs, LPCWSTR szCmdArgs, LPWSTR **lppArray)
+{
+
+ DWORD i, nJVM, nCmd, nTotal, lJVM, lCmd;
+ LPWSTR p;
+
+ /* Calculate the number of all arguments */
+ nTotal = 0;
+ if (szClassPath)
+ ++nTotal;
+ if (szClass)
+ ++nTotal;
+ lJVM = __apxGetMultiSzLengthW(szOptions, &nJVM);
+ nTotal += nJVM;
+ lCmd = __apxGetMultiSzLengthW(szCmdArgs, &nCmd);
+ nTotal += nCmd;
+ if (dwMs)
+ ++nTotal;
+ if (dwMx)
+ ++nTotal;
+ if (dwSs)
+ ++nTotal;
+
+ if (nTotal == 0)
+ return 0;
+
+ /* Allocate the array to store all arguments' pointers
+ */
+ *lppArray = (LPWSTR *)apxPoolAlloc(hPool, (nTotal + 2) * sizeof(LPWSTR));
+
+ /* Process JVM options */
+ if (nJVM && lJVM) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lJVM + 1) * sizeof(WCHAR));
+ AplCopyMemory(p, szOptions, (lJVM + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+ for (i = 0; i < nJVM; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ }
+
+ /* Process the 3 extra JVM options */
+ if (dwMs) {
+ p = (LPWSTR)apxPoolAlloc(hPool, 64 * sizeof(WCHAR));
+ wsprintfW(p, L"-Xms%dm", dwMs);
+ (*lppArray)[i++] = p;
+ }
+ if (dwMx) {
+ p = (LPWSTR)apxPoolAlloc(hPool, 64 * sizeof(WCHAR));
+ wsprintfW(p, L"-Xmx%dm", dwMx);
+ (*lppArray)[i++] = p;
+ }
+ if (dwSs) {
+ p = (LPWSTR)apxPoolAlloc(hPool, 64 * sizeof(WCHAR));
+ wsprintfW(p, L"-Xss%dk", dwSs);
+ (*lppArray)[i++] = p;
+ }
+
+ /* Process the classpath and class */
+ if (szClassPath) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lstrlenW(JAVA_CLASSPATH_W) + lstrlenW(szClassPath)) * sizeof(WCHAR));
+ lstrcpyW(p, JAVA_CLASSPATH_W);
+ lstrcatW(p, szClassPath);
+ (*lppArray)[i++] = p;
+ }
+ if (szClass) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lstrlenW(szClass)) * sizeof(WCHAR));
+ lstrcpyW(p, szClass);
+ (*lppArray)[i++] = p;
+ }
+
+ /* Process command arguments */
+ if (nCmd && lCmd) {
+ p = (LPWSTR)apxPoolAlloc(hPool, (lCmd + 1) * sizeof(WCHAR));
+ AplCopyMemory(p, szCmdArgs, (lCmd + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+ for (; i < nTotal; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ }
+
+ (*lppArray)[++i] = NULL;
+
+ return nTotal;
+}
+
+
BOOL
apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName,
LPCSTR szMethodName,
@@ -447,24 +614,24 @@
lpJava->clWorker.jClazz = JNICALL_1(NewGlobalRef, jClazz);
JNI_LOCAL_UNREF(jClazz);
- if (szMethodName)
- lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
- lpJava->clWorker.jClazz,
- szMethodName, "([Ljava/lang/String;)V");
- else
- lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
- lpJava->clWorker.jClazz,
- "main", "([Ljava/lang/String;)V");
+ if (!szMethodName)
+ szMethodName = "main";
+ lstrlcpyA(lpJava->clWorker.sClazz, 1024, szClassName);
+ lstrlcpyA(lpJava->clWorker.sMethod, 512, szMethodName);
+ lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
+ lpJava->clWorker.jClazz,
+ szMethodName, "([Ljava/lang/String;)V");
if (!lpJava->clWorker.jMethod) {
JVM_EXCEPTION_CLEAR(lpJava);
- apxLogWrite(APXLOG_MARK_ERROR "Static method 'void main(String[])' in Class %s not found", szClassName);
+ apxLogWrite(APXLOG_MARK_ERROR "Method 'static void %s(String[])' not found in Class %s",
+ szMethodName, szClassName);
return FALSE;
}
nArgs = apxMultiSzToArrayW(hJava->hPool, lpArguments, &lpArgs);
+ lpJava->clWorker.jArgs = JNICALL_3(NewObjectArray, nArgs,
+ lpJava->clString.jClazz, NULL);
if (nArgs) {
DWORD i;
- lpJava->clWorker.jArgs = JNICALL_3(NewObjectArray, nArgs,
- lpJava->clString.jClazz, NULL);
for (i = 0; i < nArgs; i++) {
jstring arg = JNICALL_2(NewString, lpArgs[i], lstrlenW(lpArgs[i]));
JNICALL_3(SetObjectArrayElement, lpJava->clWorker.jArgs, i, arg);
@@ -475,7 +642,6 @@
return TRUE;
}
-
/* Main java application worker thread
* It will launch Java main and wait until
* it finishes.
@@ -495,6 +661,8 @@
WORKER_EXIT(2);
if (!__apxJvmAttach(lpJava))
WORKER_EXIT(3);
+ apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread started %s:%s",
+ lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
lpJava->dwWorkerStatus = 1;
JNICALL_3(CallStaticVoidMethod,
lpJava->clWorker.jClazz,
@@ -503,9 +671,12 @@
JVM_EXCEPTION_CLEAR(lpJava);
__apxJvmDetach(lpJava);
+ apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread %s:%s finished",
+ lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
finished:
lpJava->dwWorkerStatus = 0;
- apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished");
+ apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished %s:%s",
+ lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
ExitThread(rv);
/* never gets here but keep the compiler happy */
return 0;
@@ -536,6 +707,20 @@
}
DWORD
+apxJavaSetOptions(APXHANDLE hJava, DWORD dwOptions)
+{
+ DWORD dwOrgOptions;
+ LPAPXJAVAVM lpJava;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return 0;
+ lpJava = APXHANDLE_DATA(hJava);
+ dwOrgOptions = lpJava->dwOptions;
+ lpJava->dwOptions = dwOptions;
+ return dwOrgOptions;
+}
+
+DWORD
apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill)
{
DWORD rv;
@@ -782,3 +967,4 @@
return TRUE;
}
+
Modified: trunk/utils/windows/native/service/procrun/src/log.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/log.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/log.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -12,12 +12,14 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
#include "apxwin.h"
#include "private.h"
+#include <stdio.h>
#define LINE_SEP "\n"
+#define LOGF_EXT L".%04d-%02d-%02d.log"
static LPCSTR _log_level[] = {
"[debug] ",
@@ -32,7 +34,7 @@
DWORD dwLogLevel;
BOOL bRotate;
SYSTEMTIME sysTime;
- WCHAR szPath[MAX_PATH + 1];
+ WCHAR szPath[SIZ_PATHLEN];
WCHAR szPrefix[MAX_PATH];
} apx_logfile_st;
@@ -46,50 +48,52 @@
APXHANDLE hPool,
LPCWSTR szPath,
LPCWSTR szPrefix,
- LPCWSTR szName)
+ LPCWSTR szName,
+ BOOL bTimeStamp)
{
LPWSTR sRet;
- WCHAR sPath[MAX_PATH+1];
- WCHAR sName[MAX_PATH+1];
+ WCHAR sPath[SIZ_PATHLEN];
+ WCHAR sName[SIZ_PATHLEN];
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
if (!szPath) {
if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
return INVALID_HANDLE_VALUE;
- lstrcatW(sPath, L"\\LogFiles\\");
- if (!szPrefix)
- lstrcatW(sPath, L"Apache");
- else
- lstrcatW(sPath, szPrefix);
- wsprintfW(sName, L"\\%s%04d%02d%02d.log",
+ lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\Apache");
+ }
+ else {
+ lstrlcpyW(sPath, MAX_PATH, szPath);
+ }
+ if (!szPrefix)
+ szPrefix = L"";
+ if (!szName)
+ szName = L"";
+ if (bTimeStamp)
+ wsprintfW(sName,
+ L"\\%s%s" LOGF_EXT,
+ szPrefix,
szName,
sysTime.wYear,
sysTime.wMonth,
sysTime.wDay);
- }
- else {
- lstrcpyW(sPath, szPath);
- if (szPrefix)
- wsprintfW(sName, L"\\%s", szPrefix);
- else
- wsprintfW(sName, L"\\%s%04d%02d%02d.log",
- szName,
- sysTime.wYear,
- sysTime.wMonth,
- sysTime.wDay);
- }
- sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
+ else
+ wsprintfW(sName,
+ L"\\%s%s",
+ szPrefix,
+ szName);
+
+ sRet = apxPoolAlloc(hPool, (SIZ_PATHLEN) * sizeof(WCHAR));
/* Set default level to info */
CreateDirectoryW(sPath, NULL);
-
- lstrcpyW(sRet, sPath);
- lstrcatW(sRet, sName);
+ lstrlcpyW(sRet, SIZ_PATHMAX, sPath);
+ lstrlcatW(sRet, SIZ_PATHMAX, sName);
+
return sRet;
}
-/* Open the log file
+/* Open the log file
* TODO: format like standard apache error.log
* Add the EventLogger
*/
@@ -99,8 +103,8 @@
LPCWSTR szPrefix)
{
- WCHAR sPath[MAX_PATH+1];
- WCHAR sName[MAX_PATH+1];
+ WCHAR sPath[SIZ_PATHLEN];
+ WCHAR sName[SIZ_PATHLEN];
SYSTEMTIME sysTime;
apx_logfile_st *h;
@@ -108,43 +112,34 @@
if (!szPath) {
if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
return INVALID_HANDLE_VALUE;
- lstrcatW(sPath, L"\\LogFiles\\");
- if (!szPrefix)
- lstrcatW(sPath, L"Apache");
- else
- lstrcatW(sPath, szPrefix);
- wsprintfW(sName, L"\\%04d%02d%02d.log",
- sysTime.wYear,
- sysTime.wMonth,
- sysTime.wDay);
+ lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\Apache");
}
else {
- lstrcpyW(sPath, szPath);
- if (szPrefix)
- wsprintfW(sName, L"\\%s", szPrefix);
- else
- wsprintfW(sName, L"\\jakarta_service_%04d%02d%02d.log",
- sysTime.wYear,
- sysTime.wMonth,
- sysTime.wDay);
+ lstrlcpyW(sPath, MAX_PATH, szPath);
}
+ if (!szPrefix)
+ szPrefix = L"commons-daemon";
+ wsprintfW(sName, L"\\%s" LOGF_EXT,
+ szPrefix,
+ sysTime.wYear,
+ sysTime.wMonth,
+ sysTime.wDay);
if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st))))
return NULL;
/* Set default level to info */
h->dwLogLevel = APXLOG_LEVEL_INFO;
CreateDirectoryW(sPath, NULL);
-
+
h->sysTime = sysTime;
- lstrcpyW(h->szPath, sPath);
- lstrcatW(sPath, sName);
- if (szPrefix)
- lstrcpyW(h->szPrefix, szPrefix);
+ lstrlcpyW(h->szPath, MAX_PATH, sPath);
+ lstrlcatW(sPath, MAX_PATH, sName);
+ lstrlcpyW(h->szPrefix, MAX_PATH, szPrefix);
h->hFile = CreateFileW(sPath,
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
/* Set this file as system log file */
if (!_st_sys_loghandle)
@@ -198,16 +193,16 @@
static BOOL apx_log_rotate(apx_logfile_st *l,
LPSYSTEMTIME lpCtime)
{
- WCHAR sPath[MAX_PATH+1];
-
+ WCHAR sPath[SIZ_PATHLEN];
+
/* rotate on daily basis */
if (l->sysTime.wDay == lpCtime->wDay)
return TRUE;
FlushFileBuffers(l->hFile);
- CloseHandle(l->hFile);
+ CloseHandle(l->hFile);
l->sysTime = *lpCtime;
- wsprintfW(sPath, L"%s\\%s%04d%02d%02d.log",
+ wsprintfW(sPath, L"%s\\%s" LOGF_EXT,
l->szPath,
l->szPrefix,
l->sysTime.wYear,
@@ -217,7 +212,7 @@
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+ FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if (IS_INVALID_HANDLE(l->hFile))
return FALSE;
@@ -240,12 +235,13 @@
LPSTR szBp;
int len = 0;
LPCSTR f = szFile;
- CHAR sb[MAX_PATH+1];
+ CHAR sb[SIZ_PATHLEN];
DWORD wr;
DWORD err;
BOOL dolock = TRUE;
apx_logfile_st *lf = (apx_logfile_st *)hFile;
+ err = GetLastError(); /* save the last Error code */
if (IS_INVALID_HANDLE(lf))
lf = _st_sys_loghandle;
if (IS_INVALID_HANDLE(lf)) {
@@ -255,20 +251,16 @@
}
if (dwLevel < lf->dwLogLevel)
return 0;
- err = GetLastError(); /* save the last Error code */
if (f) {
- f = (szFile + lstrlenA(szFile) - 1);
+ f = (szFile + lstrlenA(szFile) - 1);
while(f != szFile && '\\' != *f && '/' != *f)
f--;
if(f != szFile)
f++;
}
- lstrcpyA(buffer, _log_level[dwLevel]);
- if (!dolock)
- lstrcatA(buffer, "\n");
- szBp = &buffer[lstrlenA(buffer)];
+ szBp = &buffer[0];
if (!szFormat) {
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
@@ -300,18 +292,20 @@
APX_LOGLOCK(lf->hFile);
}
if (bTimeStamp) {
- wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
+ wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
t.wYear, t.wMonth, t.wDay,
t.wHour, t.wMinute, t.wSecond);
WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
}
- if (f) {
- wsprintfA(sb, "[%-4d %s] ", dwLine, f);
+ WriteFile(lf->hFile, _log_level[dwLevel],
+ strlen(_log_level[dwLevel]), &wr, NULL);
+ if (f && lf->dwLogLevel == APXLOG_LEVEL_DEBUG) {
+ wsprintfA(sb, "(%10s:%-4d) ", f, dwLine);
WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
}
-
WriteFile(lf->hFile, buffer, len, &wr, NULL);
- /* Terminate the line */
+
+ /* Terminate the line */
WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
#ifdef _DEBUG_FULL
FlushFileBuffers(lf->hFile);
@@ -323,7 +317,7 @@
#ifdef _DEBUG_FULL
{
char tid[1024 + 16];
- wsprintfA(tid, "[%04X] %s", GetCurrentThreadId(), buffer);
+ wsprintfA(tid, "[%04d] %s", GetCurrentThreadId(), buffer);
OutputDebugStringA(tid);
}
#endif
@@ -342,7 +336,7 @@
lf = _st_sys_loghandle;
if (IS_INVALID_HANDLE(lf))
return;
-
+
FlushFileBuffers(lf->hFile);
CloseHandle(lf->hFile);
if (lf == _st_sys_loghandle)
@@ -359,13 +353,13 @@
...)
{
va_list args;
- CHAR buffer[1024+16];
- CHAR sysbuf[2048];
+ CHAR buffer[SIZ_HUGLEN];
+ CHAR sysbuf[SIZ_HUGLEN];
int len = 0, nRet;
LPCSTR f = szFile;
DWORD err = GetLastError(); /* save the last Error code */
if (f) {
- f = (szFile + lstrlenA(szFile) - 1);
+ f = (szFile + lstrlenA(szFile) - 1);
while(f != szFile && '\\' != *f && '/' != *f)
f--;
if(f != szFile)
@@ -373,36 +367,51 @@
}
sysbuf[0] = '\0';
if (err != ERROR_SUCCESS) {
- len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
sysbuf,
- 1000,
+ SIZ_DESLEN,
NULL);
- sysbuf[len] = 0;
+ if (len > 0) {
+ sysbuf[len] = '\0';
+ if (sysbuf[len - 1] == '\n') {
+ sysbuf[len - 1] = '\0';
+ --len;
+ }
+ }
+ else
+ sysbuf[0] = '\0';
}
if (szFormat) {
va_start(args, szFormat);
wvsprintfA(buffer, szFormat, args);
va_end(args);
if (f) {
- CHAR sb[MAX_PATH+1];
- wsprintfA(sb, "\n%s (%d)", f, dwLine);
+ CHAR sb[SIZ_PATHLEN];
+ wsprintfA(sb, "%s (%d)", f, dwLine);
lstrcatA(sysbuf, sb);
}
- lstrcatA(sysbuf, "\n");
- lstrcatA(sysbuf, buffer);
+ lstrlcatA(sysbuf, SIZ_HUGLEN, "\n");
+ lstrlcatA(sysbuf, SIZ_HUGLEN, buffer);
}
len = lstrlenA(sysbuf);
#ifdef _DEBUG_FULL
OutputDebugStringA(sysbuf);
#endif
- if (len > 0 && bDisplay) {
- nRet = MessageBoxA(NULL, sysbuf,
- "Application System Error",
- MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
+ if (len > 0) {
+ if (bDisplay) {
+ nRet = MessageBoxA(NULL, sysbuf,
+ "Application System Error",
+ MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
+ }
+ else {
+ fputs(sysbuf, stderr);
+ fputc('\n', stderr);
+ fflush(stderr);
+ }
}
/* Restore the last Error code */
SetLastError(err);
Modified: trunk/utils/windows/native/service/procrun/src/mclib.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/mclib.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/mclib.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
@@ -54,7 +54,7 @@
#define wmask (wsize - 1)
LPVOID AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill)
-{
+{
SIZE_T t;
#ifdef WIN64
@@ -119,11 +119,11 @@
do {
*dst++ = Fill;
} while (--t != 0);
- return (Destination);
+ return (Destination);
}
void AplZeroMemory(PVOID Destination, SIZE_T Length)
-{
+{
SIZE_T t;
LPBYTE dst;
@@ -237,7 +237,7 @@
}
done:
return (Destination);
-}
+}
INT
@@ -252,7 +252,7 @@
} while (--nBytes != 0);
}
return 0;
-}
+}
/*
* Find the first occurrence of lpFind in lpMem.
@@ -277,7 +277,7 @@
s--;
}
return (LPBYTE)s;
-}
+}
LPSTR
AplRindexA(LPCSTR lpStr, int ch)
@@ -289,6 +289,121 @@
save = (LPSTR)lpStr;
if (!*lpStr)
return save;
- }
+ }
/* NOTREACHED */
-}
+}
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+LPSTR
+lstrlcatA(LPSTR dst, int siz, LPCSTR src)
+{
+ LPSTR d = dst;
+ LPCSTR s = src;
+ int n = siz;
+ int dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return NULL;
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return dst;
+}
+
+LPWSTR
+lstrlcatW(LPWSTR dst, int siz, LPCWSTR src)
+{
+ LPWSTR d = dst;
+ LPCWSTR s = src;
+ int n = siz;
+ int dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return NULL;
+ while (*s != L'\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = L'\0';
+
+ return dst;
+}
+
+LPSTR
+lstrlcpyA(LPSTR dst, int siz, LPCSTR src)
+{
+ LPSTR d = dst;
+ LPCSTR s = src;
+ int n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return d;
+}
+
+LPWSTR
+lstrlcpyW(LPWSTR dst, int siz, LPCWSTR src)
+{
+ LPWSTR d = dst;
+ LPCWSTR s = src;
+ int n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == L'\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = L'\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return d;
+}
Modified: trunk/utils/windows/native/service/procrun/src/private.h
===================================================================
--- trunk/utils/windows/native/service/procrun/src/private.h 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/private.h 2010-07-21 20:01:54 UTC (rev 2689)
@@ -234,11 +234,6 @@
#define APX_GET_OSLEVEL() ((_st_apx_oslevel == APX_WINVER_UNK) ? apxGetOsLevel() : _st_apx_oslevel)
-#ifdef _DEBUG
-void ErrorMessage(LPCTSTR szError, BOOL bFatal);
-#else
-#define ErrorMessage(szError, bFatal) ((void)0)
-#endif
/* zero separated, double zero terminated string */
struct APXMULTISZ {
DWORD dwAllocated; /* length including terminators */
Modified: trunk/utils/windows/native/service/procrun/src/registry.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/registry.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/registry.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -454,7 +454,7 @@
DWORD rc, dwType = REG_BINARY;
rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
lpReg->pCurrVal = lpData;
@@ -705,7 +705,7 @@
return FALSE;
}
else if (RegSetValueExA(hKey, szValueName, 0, dwType,
- (LPBYTE)szValue, lstrlenA(szValue)) != ERROR_SUCCESS)
+ (LPBYTE)szValue, lstrlenA(szValue) + 1) != ERROR_SUCCESS)
return FALSE;
return TRUE;
@@ -743,7 +743,7 @@
}
else if (RegSetValueExW(hKey, szValueName, 0, dwType,
(LPBYTE)szValue,
- lstrlenW(szValue) * sizeof(WCHAR)) != ERROR_SUCCESS)
+ (lstrlenW(szValue) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
return FALSE;
return TRUE;
@@ -815,39 +815,86 @@
}
+LONG apxDeleteRegistryRecursive(HKEY hKeyRoot, LPCWSTR szSubKey) {
+ LONG rc = ERROR_SUCCESS;
+ DWORD dwSize = 0;
+ WCHAR szName[SIZ_BUFLEN];
+ HKEY hKey = NULL;
+
+ if (ERROR_SUCCESS == RegDeleteKey(hKeyRoot, szSubKey)) {
+ return ERROR_SUCCESS;
+ }
+
+ rc = RegOpenKeyExW(hKeyRoot, szSubKey, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ if (rc == ERROR_FILE_NOT_FOUND) {
+ return ERROR_SUCCESS;
+ } else {
+ return rc;
+ }
+ }
+ while (rc == ERROR_SUCCESS) {
+ dwSize = SIZ_BUFLEN;
+ rc = RegEnumKeyExW(hKey, 0, szName, &dwSize, NULL, NULL, NULL, NULL );
+
+ if (rc == ERROR_NO_MORE_ITEMS) {
+ rc = RegDeleteKeyW(hKeyRoot, szSubKey);
+ break;
+ } else {
+ rc = apxDeleteRegistryRecursive(hKey, szName);
+ if (rc != ERROR_SUCCESS) {
+ break; // abort when we start failing
+ }
+ }
+ }
+ RegCloseKey(hKey);
+ return rc;
+}
+
+
BOOL
apxDeleteRegistryW(LPCWSTR szRoot,
LPCWSTR szKeyName,
- BOOL bDeleteEmpty)
+ REGSAM samDesired,
+ BOOL bDeleteEmptyRoot)
{
WCHAR buff[SIZ_BUFLEN];
- BOOL rv;
+ LONG rc = ERROR_SUCCESS;
+ HKEY hKey = NULL;
+ BOOL rv = TRUE;
+ HKEY hives[] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER, NULL}, *hive = NULL;
if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
return FALSE;
if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
return FALSE;
- lstrcpyW(buff, REGSOFTWARE_ROOT);
if (szRoot)
- lstrcatW(buff, szRoot);
+ lstrcpyW(buff, szRoot);
else
- lstrcatW(buff, REGAPACHE_ROOT);
+ lstrcpyW(buff, REGAPACHE_ROOT);
lstrcatW(buff, REGSEPARATOR);
- lstrcatW(buff, szKeyName);
- rv = SHDeleteKeyW(HKEY_LOCAL_MACHINE, buff);
- rv += SHDeleteKeyW(HKEY_CURRENT_USER, buff);
+ for (hive = &hives[0]; *hive; hive++) {
+ HKEY hkeySoftware = NULL;
- if (bDeleteEmpty) {
- lstrcpyW(buff, REGSOFTWARE_ROOT);
- if (szRoot)
- lstrcatW(buff, szRoot);
- else
- lstrcatW(buff, REGAPACHE_ROOT);
-
- SHDeleteEmptyKeyW(HKEY_LOCAL_MACHINE, buff);
- SHDeleteEmptyKeyW(HKEY_CURRENT_USER, buff);
+ rc = RegOpenKeyExW(*hive, REGSOFTWARE_ROOT, 0, KEY_READ | samDesired, &hkeySoftware);
+ if (rc != ERROR_SUCCESS) {
+ rv = FALSE;
+ } else {
+ rc = RegOpenKeyExW(hkeySoftware, buff, 0, samDesired | KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey);
+ if (rc == ERROR_SUCCESS) {
+ rc = apxDeleteRegistryRecursive(hKey, szKeyName);
+ RegCloseKey(hKey);
+ hKey = NULL;
+ rv |= (rc == ERROR_SUCCESS);
+ }
+ if (bDeleteEmptyRoot) {
+ // will fail if there are subkeys, just like we want
+ RegDeleteKeyW(hkeySoftware, buff);
+ }
+ RegCloseKey(hkeySoftware);
+ }
}
return rv;
}
@@ -855,7 +902,8 @@
BOOL
apxDeleteRegistryA(LPCSTR szRoot,
LPCSTR szKeyName,
- BOOL bDeleteEmpty)
+ REGSAM samDesired,
+ BOOL bDeleteEmptyRoot)
{
WCHAR wcRoot[SIZ_RESLEN];
WCHAR wcKey[SIZ_RESLEN];
@@ -866,7 +914,7 @@
}
AsciiToWide(szKeyName, wcKey);
- return apxDeleteRegistryW(wsRoot, wcKey, bDeleteEmpty);
+ return apxDeleteRegistryW(wsRoot, wcKey, samDesired, bDeleteEmptyRoot);
}
@@ -1030,10 +1078,10 @@
}
rc = RegSetValueExW(hKey, REGDESCRIPTION, 0, REG_SZ, (CONST BYTE *)szDescription,
- lstrlenW(szDescription) * sizeof(WCHAR));
+ (lstrlenW(szDescription) + 1) * sizeof(WCHAR));
SAFE_CLOSE_KEY(hKey);
- return rc = ERROR_SUCCESS;
+ return rc == ERROR_SUCCESS;
}
BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
Modified: trunk/utils/windows/native/service/procrun/src/rprocess.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/rprocess.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/rprocess.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "apxwin.h"
#include "private.h"
@@ -24,7 +24,7 @@
#define CHILD_TERMINATE_CODE 19640323 /* Could be any value like my birthday ;-)*/
DYNOLAD_TYPE_DECLARE(CreateRemoteThread,
- __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES,
+ __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES,
DWORD, LPTHREAD_START_ROUTINE,
LPVOID, DWORD, LPDWORD);
@@ -83,13 +83,13 @@
HANDLE hChildInpWr;
HANDLE hChildOutRd;
HANDLE hChildErrRd;
- /* Saved console pipes */
+ /* Saved console pipes */
HANDLE hParentStdSave[3];
HANDLE hWorkerThreads[3];
HANDLE hUserToken;
HANDLE hCurrentProcess;
BOOL bSaveHandles;
- /** callback function */
+ /** callback function */
LPAPXFNCALLBACK fnUserCallback;
LPSECURITY_ATTRIBUTES lpSA;
LPVOID lpSD;
@@ -135,13 +135,13 @@
LPAPXPROCESS lpProc;
APXCALLHOOK *lpCall;
INT ch;
- DWORD dwReaded;
+ DWORD dwReaded;
lpProc = APXHANDLE_DATA(hProcess);
while (lpProc->dwChildStatus & CHILD_RUNNING) {
ch = 0;
if (!ReadFile(lpProc->hChildOutRd, &ch, lpProc->chSize,
&dwReaded, NULL) || !dwReaded) {
-
+
break;
}
if (lpProc->fnUserCallback)
@@ -162,7 +162,7 @@
LPAPXPROCESS lpProc;
APXCALLHOOK *lpCall;
INT ch;
- DWORD dwReaded;
+ DWORD dwReaded;
lpProc = APXHANDLE_DATA(hProcess);
while (lpProc->dwChildStatus & CHILD_RUNNING) {
if (!ReadFile(lpProc->hChildErrRd, &ch, lpProc->chSize,
@@ -193,7 +193,7 @@
return 1;
}
}
-
+
return 0;
}
@@ -221,7 +221,7 @@
break;
}
}
-
+
return n;
}
@@ -231,7 +231,7 @@
DWORD n = 0;
if (!lpData || !dwLen)
return 0;
-
+
if (lpProc->dwChildStatus & CHILD_RUNNING) {
DWORD wr = 0;
while (lpProc->dwChildStatus & CHILD_RUNNING) {
@@ -249,7 +249,7 @@
break;
}
}
-
+
return n;
}
@@ -261,38 +261,38 @@
if (!CreatePipe(&(lpProc->hChildStdInp),
&(lpProc->hChildInpWr),
lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!SetHandleInformation(lpProc->hChildInpWr,
HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!CreatePipe(&(lpProc->hChildOutRd),
&(lpProc->hChildStdOut),
lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!SetHandleInformation(lpProc->hChildOutRd,
HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!CreatePipe(&(lpProc->hChildErrRd),
&(lpProc->hChildStdErr),
lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!SetHandleInformation(lpProc->hChildErrRd,
HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
rv = TRUE;
@@ -316,33 +316,33 @@
lpProc = APXHANDLE_DATA(hProcess);
CHECK_IF_ACTIVE(lpProc);
-
+
/* Try to close the child's stdin first */
SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
- /* Wait 1 sec for child process to
+ /* Wait 1 sec for child process to
* recognize that the stdin has been closed.
*/
if (WaitForSingleObject(lpProc->stProcInfo.hProcess, 1000) == WAIT_OBJECT_0)
goto cleanup;
CHECK_IF_ACTIVE(lpProc);
-
+
/* Try to create the remote thread in the child address space */
DYNLOAD_FPTR_ADDRESS(CreateRemoteThread, KERNEL32);
- if (DuplicateHandle(lpProc->hCurrentProcess,
- lpProc->stProcInfo.hProcess,
- lpProc->hCurrentProcess,
- &hDup,
- PROCESS_ALL_ACCESS,
+ if (DuplicateHandle(lpProc->hCurrentProcess,
+ lpProc->stProcInfo.hProcess,
+ lpProc->hCurrentProcess,
+ &hDup,
+ PROCESS_ALL_ACCESS,
FALSE, 0)) {
DYNLOAD_FPTR_ADDRESS(ExitProcess, KERNEL32);
/* Now call the ExitProcess from inside the client
* This will safely unload all the dll's.
*/
- hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup,
- NULL, 0,
+ hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup,
+ NULL, 0,
(LPTHREAD_START_ROUTINE)DYNLOAD_FPTR(ExitProcess),
- (PVOID)&uExitCode, 0, NULL);
+ (PVOID)&uExitCode, 0, NULL);
if (!IS_INVALID_HANDLE(hRemote)) {
if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
2000) == WAIT_OBJECT_0) {
@@ -356,9 +356,9 @@
CloseHandle(hDup);
goto cleanup;
}
-
+
TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
-
+
cleanup:
/* Close the process handle */
SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
@@ -384,8 +384,8 @@
}
SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
- /* Close parent side of the pipes */
- SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ /* Close parent side of the pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
@@ -401,7 +401,7 @@
if (lpProc->lpEnvironment)
FreeEnvironmentStringsW(lpProc->lpEnvironment);
- case WM_QUIT:
+ case WM_QUIT:
/* The process has finished
* This is a WorkerThread message
*/
@@ -414,7 +414,7 @@
if (wParam)
__apxProcessWrite(lpProc, (LPCVOID)lParam, (DWORD)wParam);
else
- __apxProcessPuts(lpProc, (LPCTSTR)lParam);
+ __apxProcessPuts(lpProc, (LPCTSTR)lParam);
break;
default:
break;
@@ -439,8 +439,8 @@
#ifndef _UNICODE
WCHAR wsUsername[256];
WCHAR wsPassword[256];
- AsciiToWide(szUsername, wsUsername);
- AsciiToWide(szPassword, wsPassword);
+ AsciiToWide(szUsername, wsUsername);
+ AsciiToWide(szPassword, wsPassword);
#else
LPCWSTR wsUsername = szUsername;
LPCWSTR wsPassword = szPassword;
@@ -459,8 +459,8 @@
if (szUsername && szPassword) {
WCHAR wsUsername[256];
WCHAR wsPassword[256];
- AsciiToWide(szUsername, wsUsername);
- AsciiToWide(szPassword, wsPassword);
+ AsciiToWide(szUsername, wsUsername);
+ AsciiToWide(szPassword, wsPassword);
return apxCreateProcessW(hPool, dwOptions, fnCallback,
wsUsername, wsPassword, bLogonAsService);
}
@@ -481,32 +481,32 @@
/* CreateProcessAsUser is supported only on NT */
if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
HANDLE hUser;
- if (!LogonUserW(szUsername,
- NULL,
- szPassword,
+ if (!LogonUserW(szUsername,
+ NULL,
+ szPassword,
bLogonAsService ? LOGON32_LOGON_SERVICE : LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&hUser)) {
/* Logon Failed */
- ErrorMessage(NULL, TRUE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
- if (!DuplicateTokenEx(hUser,
- TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
+ if (!DuplicateTokenEx(hUser,
+ TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
NULL,
SecurityImpersonation,
TokenPrimary,
&hUserToken)) {
CloseHandle(hUser);
/* Failed to duplicate the user token */
- ErrorMessage(NULL, TRUE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
if (!ImpersonateLoggedOnUser(hUserToken)) {
CloseHandle(hUser);
CloseHandle(hUserToken);
/* failed to impersonate the logged user */
- ErrorMessage(NULL, TRUE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
CloseHandle(hUser);
@@ -534,7 +534,7 @@
&lpProc->hCurrentProcess,
PROCESS_ALL_ACCESS,
FALSE,
- 0);
+ 0);
#else
lpProc->hCurrentProcess = GetCurrentProcess();
#endif
@@ -551,7 +551,7 @@
return hProcess;
}
-static WCHAR _desktop_name[] =
+static WCHAR _desktop_name[] =
{'W', 'i', 'n', 's', 't', 'a', '0', '\\', 'D', 'e', 'f', 'a', 'u', 'l', 't', 0};
BOOL
@@ -564,7 +564,7 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
/* don't allow multiple execute calls on the same object */
if (lpProc->dwChildStatus & PROC_INITIALIZED)
@@ -582,7 +582,7 @@
/* Set the redirected handles */
si.hStdOutput = lpProc->hChildStdOut;
si.hStdError = lpProc->hChildStdErr;
- si.hStdInput = lpProc->hChildStdInp;
+ si.hStdInput = lpProc->hChildStdInp;
if (lpProc->lpEnvironment)
FreeEnvironmentStringsW(lpProc->lpEnvironment);
@@ -618,7 +618,7 @@
&(lpProc->stProcInfo));
}
/* Close unused sides of pipes */
- SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);
+ SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);
SAFE_CLOSE_HANDLE(lpProc->hChildStdOut);
SAFE_CLOSE_HANDLE(lpProc->hChildStdErr);
if (!bS)
@@ -627,10 +627,10 @@
lpProc->dwChildStatus |= (CHILD_RUNNING | PROC_INITIALIZED);
lpProc->hWorkerThreads[0] = CreateThread(NULL, 0, __apxProcStdoutThread,
- hProcess, 0, &id);
+ hProcess, 0, &id);
lpProc->hWorkerThreads[1] = CreateThread(NULL, 0, __apxProcStderrThread,
- hProcess, 0, &id);
- ResumeThread(lpProc->stProcInfo.hThread);
+ hProcess, 0, &id);
+ ResumeThread(lpProc->stProcInfo.hThread);
lpProc->hWorkerThreads[2] = CreateThread(NULL, 0, __apxProcWorkerThread,
hProcess, 0, &id);
@@ -638,8 +638,8 @@
/* Close child handles first */
return TRUE;
cleanup:
- /* Close parent side of the pipes */
- SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ /* Close parent side of the pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
@@ -653,7 +653,7 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
apxFree(lpProc->szApplicationExec);
lpProc->szApplicationExec = apxPoolWStrdupA(hProcess->hPool, szName);
@@ -668,7 +668,7 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
apxFree(lpProc->szApplicationExec);
lpProc->szApplicationExec = apxPoolStrdupW(hProcess->hPool, szName);
@@ -683,11 +683,11 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
apxFree(lpProc->szCommandLine);
lpProc->szCommandLine = apxPoolWStrdupA(hProcess->hPool, szCmdline);
-
+
return lpProc->szCommandLine != NULL;
}
@@ -698,11 +698,11 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
apxFree(lpProc->szCommandLine);
lpProc->szCommandLine = apxPoolStrdupW(hProcess->hPool, szCmdline);
-
+
return lpProc->szCommandLine != NULL;
}
@@ -713,11 +713,11 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
apxFree(lpProc->szWorkingPath);
lpProc->szWorkingPath = apxPoolWStrdupA(hProcess->hPool, szPath);
-
+
return lpProc->szWorkingPath != NULL;
}
@@ -728,7 +728,7 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
apxFree(lpProc->szWorkingPath);
if (!szPath) {
@@ -737,7 +737,7 @@
return TRUE;
}
lpProc->szWorkingPath = apxPoolWStrdupW(hProcess->hPool, szPath);
-
+
return lpProc->szWorkingPath != NULL;
}
@@ -748,7 +748,7 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return 0;
-
+
lpProc = APXHANDLE_DATA(hProcess);
return __apxProcessPutc(lpProc, ch, sizeof(CHAR));
}
@@ -760,7 +760,7 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return 0;
-
+
lpProc = APXHANDLE_DATA(hProcess);
return __apxProcessPutc(lpProc, ch, sizeof(WCHAR));
}
@@ -807,7 +807,7 @@
LPAPXPROCESS lpProc;
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return 0;
-
+
lpProc = APXHANDLE_DATA(hProcess);
return __apxProcessWrite(lpProc, lpData, dwLen);
@@ -820,13 +820,13 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
-
+
if (lpProc->dwChildStatus & CHILD_RUNNING) {
return FlushFileBuffers(lpProc->hChildInpWr);
}
-
+
return FALSE;
}
@@ -847,9 +847,9 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return WAIT_ABANDONED;
-
+
lpProc = APXHANDLE_DATA(hProcess);
-
+
if (lpProc->dwChildStatus & CHILD_RUNNING) {
DWORD rv = WaitForMultipleObjects(3, lpProc->hWorkerThreads,
TRUE, dwMilliseconds);
@@ -869,34 +869,45 @@
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
-
- return (lpProc->dwChildStatus & CHILD_RUNNING);
+
+ return (lpProc->dwChildStatus & CHILD_RUNNING);
}
+DWORD
+apxProcessGetPid(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ return lpProc->stProcInfo.dwProcessId;
+}
+
static LPWSTR __apxStrQuote(LPWSTR lpDest, LPCWSTR szSrc)
{
LPWSTR p;
- BOOL q = FALSE;
+ BOOL space = FALSE, quote = FALSE;
- /* Find if string has embeded spaces
+ /* Find if string has embeded spaces, add quotes only if no quotes found
*/
for (p = (LPWSTR)szSrc; *p; p++) {
- if (*p == L' ' || *p == '\t' ||
- *p == '"' || *p == '\\') {
- q = TRUE;
- break;
+ if (*p == L' ' || *p == '\t') {
+ space = TRUE;
+ } else if (*p == L'"') {
+ quote = TRUE;
}
}
p = lpDest;
- if (q) *p++ = L'"';
+ if (space && !quote) *p++ = L'"';
while (*szSrc) {
- if (*szSrc == '"' || *szSrc == '\\')
- *p++ = L'\\';
*p++ = *szSrc++;
}
- if (q) *p++ = L'"';
+ if (space && !quote) *p++ = L'"';
return p;
}
@@ -909,22 +920,14 @@
LPWSTR p;
if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
return FALSE;
-
+
lpProc = APXHANDLE_DATA(hProcess);
apxFree(lpProc->szCommandLine);
-
+
l = lstrlenW(szTitle) + 3;
- for (i = 0; i < (DWORD)lstrlenW(szTitle); i++) {
- if (szTitle[i] == L'"')
- ++l;
- }
for (i = 0; i < dwArgc; i++) {
- int x, q = 0;
+ int q = 0;
l += (lstrlenW(lpArgs[i]) + 3);
- for (x = 0; x < lstrlenW(lpArgs[i]); x++) {
- if (lpArgs[i][x] == L'"')
- ++q;
- }
l += q;
}
p = lpProc->szCommandLine = apxPoolAlloc(hProcess->hPool, l * sizeof(WCHAR));
@@ -937,3 +940,4 @@
OutputDebugStringW(lpProc->szCommandLine);
return lpProc->szCommandLine != NULL;
}
+
Modified: trunk/utils/windows/native/service/procrun/src/service.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/service.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/service.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "apxwin.h"
#include "private.h"
@@ -34,7 +34,7 @@
/* Handle to the current service */
SC_HANDLE hService;
/* Handle of the Service manager */
- SC_HANDLE hManager;
+ SC_HANDLE hManager;
APXSERVENTRY stServiceEntry;
} APXSERVICE, *LPAPXSERVICE;
@@ -43,7 +43,7 @@
{
do {
if (!IsCharAlphaNumericW(*szServiceName)) {
- apxDisplayError(TRUE, NULL, 0, "NonAlpha %d", *szServiceName);
+ apxDisplayError(FALSE, NULL, 0, "NonAlpha %d", *szServiceName);
return FALSE;
}
} while( *(++szServiceName));
@@ -74,7 +74,7 @@
{
APXHANDLE hService;
LPAPXSERVICE lpService;
- SC_HANDLE hManager;
+ SC_HANDLE hManager;
if (!(hManager = OpenSCManager(NULL, NULL, dwOptions))) {
apxLogWrite(APXLOG_MARK_SYSERR);
@@ -126,17 +126,17 @@
apxLogWrite(APXLOG_MARK_SYSERR);
return FALSE;
}
- lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
+ lstrlcpyW(lpService->stServiceEntry.szServiceName, SIZ_RESLEN, szServiceName);
if (!apxGetServiceDescriptionW(szServiceName,
lpService->stServiceEntry.szServiceDescription,
SIZ_DESLEN)) {
- apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service description");
+ apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service description");
lpService->stServiceEntry.szServiceDescription[0] = L'\0';
}
if (!apxGetServiceUserW(szServiceName,
lpService->stServiceEntry.szObjectName,
SIZ_RESLEN)) {
- apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service user name");
+ apxLogWrite(APXLOG_MARK_WARN "Failed to obtain service user name");
lpService->stServiceEntry.szObjectName[0] = L'\0';
}
if (!QueryServiceConfigW(lpService->hService, NULL, 0, &dwNeeded)) {
@@ -173,7 +173,7 @@
return &lpService->stServiceEntry;
}
-/* Set the service names etc...
+/* Set the service names etc...
* If the ImagePath contains a space, it must be quoted
*/
BOOL
@@ -235,6 +235,104 @@
NULL, NULL);
}
+static BOOL
+__apxStopDependentServices(LPAPXSERVICE lpService)
+{
+ DWORD i;
+ DWORD dwBytesNeeded;
+ DWORD dwCount;
+
+ LPENUM_SERVICE_STATUS lpDependencies = NULL;
+ ENUM_SERVICE_STATUS ess;
+ SC_HANDLE hDepService;
+ SERVICE_STATUS_PROCESS ssp;
+
+ DWORD dwStartTime = GetTickCount();
+ /* Use the 30-second time-out */
+ DWORD dwTimeout = 30000;
+
+ /* Pass a zero-length buffer to get the required buffer size.
+ */
+ if (EnumDependentServices(lpService->hService,
+ SERVICE_ACTIVE,
+ lpDependencies, 0,
+ &dwBytesNeeded,
+ &dwCount)) {
+ /* If the Enum call succeeds, then there are no dependent
+ * services, so do nothing.
+ */
+ return TRUE;
+ }
+ else {
+ if (GetLastError() != ERROR_MORE_DATA)
+ return FALSE; // Unexpected error
+
+ /* Allocate a buffer for the dependencies.
+ */
+ lpDependencies = (LPENUM_SERVICE_STATUS) HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ dwBytesNeeded);
+ if (!lpDependencies)
+ return FALSE;
+
+ __try {
+ /* Enumerate the dependencies. */
+ if (!EnumDependentServices(lpService->hService,
+ SERVICE_ACTIVE,
+ lpDependencies,
+ dwBytesNeeded,
+ &dwBytesNeeded,
+ &dwCount))
+ return FALSE;
+
+ for (i = 0; i < dwCount; i++) {
+ ess = *(lpDependencies + i);
+ /* Open the service. */
+ hDepService = OpenService(lpService->hManager,
+ ess.lpServiceName,
+ SERVICE_STOP | SERVICE_QUERY_STATUS);
+
+ if (!hDepService)
+ return FALSE;
+
+ __try {
+ /* Send a stop code. */
+ if (!ControlService(hDepService,
+ SERVICE_CONTROL_STOP,
+ (LPSERVICE_STATUS) &ssp))
+ return FALSE;
+
+ /* Wait for the service to stop. */
+ while (ssp.dwCurrentState != SERVICE_STOPPED) {
+ Sleep(ssp.dwWaitHint);
+ if (!QueryServiceStatusEx(hDepService,
+ SC_STATUS_PROCESS_INFO,
+ (LPBYTE)&ssp,
+ sizeof(SERVICE_STATUS_PROCESS),
+ &dwBytesNeeded))
+ return FALSE;
+
+ if (ssp.dwCurrentState == SERVICE_STOPPED)
+ break;
+
+ if (GetTickCount() - dwStartTime > dwTimeout)
+ return FALSE;
+ }
+ }
+ __finally {
+ /* Always release the service handle. */
+ CloseServiceHandle(hDepService);
+ }
+ }
+ }
+ __finally {
+ /* Always free the enumeration buffer. */
+ HeapFree(GetProcessHeap(), 0, lpDependencies);
+ }
+ }
+ return TRUE;
+}
+
BOOL
apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
LPAPXFNCALLBACK fnControlCallback,
@@ -255,7 +353,7 @@
/* Manager mode cannot handle services */
if (lpService->bManagerMode)
return FALSE;
- /* Check if the ServixeOpen has been called */
+ /* Check if the ServiceOpen has been called */
if (IS_INVALID_HANDLE(lpService->hService))
return FALSE;
switch (dwControl) {
@@ -298,7 +396,7 @@
break;
default:
break;
- }
+ }
}
if (!dwPending && !dwState)
return FALSE;
@@ -310,20 +408,28 @@
/* signal that we are about to control the service */
if (fnControlCallback)
(*fnControlCallback)(lpCbData, uMsg, (WPARAM)1, (LPARAM)dwState);
- if (dwControl == SERVICE_CONTROL_CONTINUE &&
+ if (dwControl == SERVICE_CONTROL_CONTINUE &&
stStatus.dwCurrentState != SERVICE_PAUSED)
bStatus = StartService(lpService->hService, 0, NULL);
- else
- bStatus = ControlService(lpService->hService, dwControl, &stStatus);
+ else {
+ bStatus = TRUE;
+ if (dwControl == SERVICE_CONTROL_STOP) {
+ /* First stop dependent services
+ */
+ bStatus = __apxStopDependentServices(lpService);
+ }
+ if (bStatus)
+ bStatus = ControlService(lpService->hService, dwControl, &stStatus);
+ }
dwStart = GetTickCount();
dwCheck = stStatus.dwCheckPoint;
if (bStatus) {
Sleep(100); /* Initial Sleep period */
while (QueryServiceStatus(lpService->hService, &stStatus)) {
if (stStatus.dwCurrentState == dwPending) {
- /* Do not wait longer than the wait hint. A good interval is
- * one tenth the wait hint, but no less than 1 second and no
- * more than 10 seconds.
+ /* Do not wait longer than the wait hint. A good interval is
+ * one tenth the wait hint, but no less than 1 second and no
+ * more than 10 seconds.
*/
dwWait = stStatus.dwWaitHint / 10;
@@ -354,7 +460,7 @@
}
else
break;
- }
+ }
}
/* signal that we are done with controling the service */
if (fnControlCallback)
@@ -418,12 +524,11 @@
if (IS_INVALID_HANDLE(lpService->hService)) {
apxLogWrite(APXLOG_MARK_SYSERR);
-
- ErrorMessage(NULL, FALSE);
return FALSE;
}
else {
- lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
+ lstrlcpyW(lpService->stServiceEntry.szServiceName,
+ SIZ_RESLEN, szServiceName);
lpService->stServiceEntry.dwStart = dwStartType;
return TRUE;
}
@@ -451,7 +556,7 @@
rv = DeleteService(lpService->hService);
SAFE_CLOSE_SCH(lpService->hService);
SAFE_CLOSE_SCH(lpService->hManager);
-
+
return rv;
}
return FALSE;
@@ -459,7 +564,7 @@
/* Browse the services */
DWORD
-apxServiceBrowse(APXHANDLE hService,
+apxServiceBrowse(APXHANDLE hService,
LPCWSTR szIncludeNamePattern,
LPCWSTR szIncludeImagePattern,
LPCWSTR szExcludeNamePattern,
@@ -484,7 +589,6 @@
if (IS_INVALID_HANDLE(hLock)) {
apxLogWrite(APXLOG_MARK_SYSERR);
- ErrorMessage(NULL, FALSE);
return 0;
}
AplZeroMemory(&stEnum, sizeof(APXREGENUM));
@@ -539,7 +643,7 @@
if (_st_apx_oslevel >= 4) {
DWORD dwNeed;
QueryServiceStatusEx(hSrv, SC_STATUS_PROCESS_INFO,
- (LPBYTE)(&(stEntry.stStatusProcess)),
+ (LPBYTE)(&(stEntry.stStatusProcess)),
sizeof(SERVICE_STATUS_PROCESS),
&dwNeed);
}
Modified: trunk/utils/windows/native/service/procrun/src/utils.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/utils.c 2010-06-16 10:02:46 UTC (rev 2688)
+++ trunk/utils/windows/native/service/procrun/src/utils.c 2010-07-21 20:01:54 UTC (rev 2689)
@@ -81,8 +81,8 @@
if (!(wsRet = apxPoolAlloc(hPool, (rc + 1) * sizeof(WCHAR))))
return NULL;
if (!GetEnvironmentVariableW(wsName, wsRet, rc)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
apxFree(wsRet);
- ErrorMessage(NULL, FALSE);
return NULL;
}
return wsRet;
@@ -100,8 +100,8 @@
if (!(szRet = apxPoolAlloc(hPool, rc + 1)))
return NULL;
if (!GetEnvironmentVariableA(szName, szRet, rc)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
apxFree(szRet);
- ErrorMessage(NULL, FALSE);
return NULL;
}
return szRet;
@@ -149,6 +149,19 @@
return s;
}
+LPWSTR UTF8ToWide(LPCSTR cs)
+{
+
+ LPWSTR s;
+ int cch = MultiByteToWideChar(CP_UTF8, 0, cs, -1, NULL, 0);
+ s = (LPWSTR)apxAlloc(cch * sizeof(WCHAR));
+ if (!MultiByteToWideChar(CP_UTF8, 0, cs, -1, s, cch)) {
+ apxFree(s);
+ return NULL;
+ }
+ return s;
+}
+
LPSTR MzWideToAscii(LPCWSTR ws, LPSTR s)
{
LPSTR pszSave = s;
@@ -197,39 +210,6 @@
return str;
}
-#ifdef _DEBUG
-
-void ErrorMessage(LPCTSTR szError, BOOL bFatal)
-{
- LPVOID lpMsgBuf = NULL;
- UINT nType;
- int nRet;
- DWORD dwErr = GetLastError();
- if (bFatal)
- nType = MB_ICONERROR | MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL;
- else
- nType = MB_ICONEXCLAMATION | MB_OK;
- if (szError) {
- nRet = MessageBox(NULL, szError, TEXT("Application Error"), nType);
- }
- else {
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwErr,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
- (LPTSTR) &lpMsgBuf, 0, NULL);
- nRet = MessageBox(NULL, (LPCTSTR)lpMsgBuf,
- TEXT("Application System Error"), nType);
- LocalFree(lpMsgBuf);
- }
- if (bFatal && (nRet == IDCANCEL || nRet == IDABORT)) {
- ExitProcess(dwErr);
- }
-}
-#endif /* _DEBUG */
-
DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount)
{
LPCSTR p = lpStr;
@@ -1011,13 +991,13 @@
}
SetLastError(0);
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
- || GetLastError()) {
+ || GetLastError()) {
LocalFree( pSD );
LocalFree( sa );
return NULL;
}
if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)
- || GetLastError()) {
+ || GetLastError()) {
LocalFree( pSD );
LocalFree( sa );
return NULL;
14 years, 4 months