You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2019/06/13 10:07:41 UTC

[commons-daemon] branch master updated (527c8f5 -> 840e290)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git.


    from 527c8f5  Add workaround for https://issues.apache.org/jira/browse/DAEMON-398
     new 71c01bc  Remove unused code
     new 3f12f27  Remove unused code
     new acfefa3  Remove unused code
     new a71e19c  Remove structure element that is written but not read
     new 840e290  Fix https://issues.apache.org/jira/browse/DAEMON-303

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                   |   6 +-
 src/native/windows/apps/prunmgr/prunmgr.c |  35 +++++--
 src/native/windows/apps/prunsrv/prunsrv.c |   9 +-
 src/native/windows/include/service.h      |  16 +--
 src/native/windows/src/private.h          |  43 +++-----
 src/native/windows/src/registry.c         |  65 ------------
 src/native/windows/src/service.c          | 162 +++++++++---------------------
 src/site/xdoc/procrun.xml                 |   2 +-
 8 files changed, 106 insertions(+), 232 deletions(-)


[commons-daemon] 02/05: Remove unused code

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit 3f12f27d5da63daedd4e40dd8ed58c30674bb675
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 12 22:46:08 2019 +0100

    Remove unused code
---
 src/native/windows/include/service.h |  11 +---
 src/native/windows/src/service.c     | 103 -----------------------------------
 2 files changed, 1 insertion(+), 113 deletions(-)

diff --git a/src/native/windows/include/service.h b/src/native/windows/include/service.h
index 826fb1c..5327ffc 100644
--- a/src/native/windows/include/service.h
+++ b/src/native/windows/include/service.h
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #ifndef _SERVICE_H_INCLUDED_
 #define _SERVICE_H_INCLUDED_
 
@@ -59,15 +59,6 @@ LPAPXSERVENTRY  apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus);
  */
 BOOL        apxServiceDelete(APXHANDLE hService);
 
-DWORD       apxServiceBrowse(APXHANDLE hService,
-                             LPCWSTR szIncludeNamePattern,
-                             LPCWSTR szIncludeImagePattern,
-                             LPCWSTR szExcludeNamePattern,
-                             LPCWSTR szExcludeImagePattern,
-                             UINT uMsg,
-                             LPAPXFNCALLBACK fnDisplayCallback,
-                             LPVOID lpCbData);
-
 DWORD       apxGetMaxServiceTimeout(APXHANDLE hPool);
 
 __APXEND_DECLS
diff --git a/src/native/windows/src/service.c b/src/native/windows/src/service.c
index d775253..e154732 100644
--- a/src/native/windows/src/service.c
+++ b/src/native/windows/src/service.c
@@ -621,106 +621,3 @@ apxServiceDelete(APXHANDLE hService)
     }
     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 again 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) {
-                        DWORD dwNeed;
-                        QueryServiceStatus(hSrv, &(stEntry.stServiceStatus));
-						QueryServiceStatusEx(hSrv, SC_STATUS_PROCESS_INFO,
-											 (LPBYTE)(&(stEntry.stStatusProcess)),
-											 sizeof(SERVICE_STATUS_PROCESS),
-											 &dwNeed);
-                        /* finally 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;
-}


[commons-daemon] 04/05: Remove structure element that is written but not read

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit a71e19c62cc994edaef5ee1737738bd7a25b3db9
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 13 09:01:04 2019 +0100

    Remove structure element that is written but not read
---
 src/native/windows/include/service.h | 1 -
 src/native/windows/src/service.c     | 1 -
 2 files changed, 2 deletions(-)

diff --git a/src/native/windows/include/service.h b/src/native/windows/include/service.h
index 5327ffc..faebef4 100644
--- a/src/native/windows/include/service.h
+++ b/src/native/windows/include/service.h
@@ -23,7 +23,6 @@ typedef struct APXSERVENTRY {
     WCHAR   szServiceName[SIZ_RESLEN];
     WCHAR   szObjectName[SIZ_RESLEN];
     WCHAR   szServiceDescription[SIZ_DESLEN];
-    DWORD   dwStart;
     LPQUERY_SERVICE_CONFIGW lpConfig;
     SERVICE_STATUS          stServiceStatus;
     SERVICE_STATUS_PROCESS  stStatusProcess;
diff --git a/src/native/windows/src/service.c b/src/native/windows/src/service.c
index e154732..1fcc1c3 100644
--- a/src/native/windows/src/service.c
+++ b/src/native/windows/src/service.c
@@ -589,7 +589,6 @@ apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
     else {
         lstrlcpyW(lpService->stServiceEntry.szServiceName,
                   SIZ_RESLEN, szServiceName);
-        lpService->stServiceEntry.dwStart = dwStartType;
         return TRUE;
     }
 }


[commons-daemon] 01/05: Remove unused code

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit 71c01bcebdc636d6a63956ef42685e61bc8220fe
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 12 19:00:01 2019 +0100

    Remove unused code
---
 src/native/windows/apps/prunmgr/prunmgr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/native/windows/apps/prunmgr/prunmgr.c b/src/native/windows/apps/prunmgr/prunmgr.c
index 4f317bd..0b520c6 100644
--- a/src/native/windows/apps/prunmgr/prunmgr.c
+++ b/src/native/windows/apps/prunmgr/prunmgr.c
@@ -54,8 +54,7 @@ LPAPXGUISTORE _gui_store  = NULL;
 #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


[commons-daemon] 05/05: Fix https://issues.apache.org/jira/browse/DAEMON-303

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit 840e29005da54f82ba7ca49332bfe67bbd6b9dd0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 13 11:06:43 2019 +0100

    Fix https://issues.apache.org/jira/browse/DAEMON-303
    
    Add an option to configure the service to start using the "Automatic
    (Delayed Start)" mode.
---
 src/changes/changes.xml                   |  6 +++-
 src/native/windows/apps/prunmgr/prunmgr.c | 32 ++++++++++++-----
 src/native/windows/apps/prunsrv/prunsrv.c |  9 ++++-
 src/native/windows/include/service.h      |  4 ++-
 src/native/windows/src/service.c          | 58 ++++++++++++++++++++++++++-----
 src/site/xdoc/procrun.xml                 |  2 +-
 6 files changed, 89 insertions(+), 22 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 19d0720..40c11e1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -38,7 +38,7 @@
     <title>Apache Commons Daemon Release Notes</title>
   </properties>
   <body>
-    <release version="1.1.1" date="TBD" description="Bug fix release">
+    <release version="1.1.1" date="TBD" description="Feature and bug fix release">
       <action type="fix" dev="markt" due-to="mturk" >
         Procrun. Add to OPT_LFLAGS rather than overwrite OPT_LFLAGS when setting
         /OPT:REF in the make file for Windows.
@@ -122,6 +122,10 @@
         JNI to create the JVM as a workaround for startup error messages not
         being visible on stdout or stderr.
       </action>
+      <action issue="DAEMON-303" type="add" dev="markt">
+        Procrun. Add an option to configure the service to use the 'Automatic
+        (Delayed Start)' startup mode.
+      </action>
     </release>
     <release version="1.1.0" date="2017-11-15" description="Feature and bug fix release">
       <action issue="DAEMON-368" type="add" dev="ggregory">
diff --git a/src/native/windows/apps/prunmgr/prunmgr.c b/src/native/windows/apps/prunmgr/prunmgr.c
index 0b520c6..afae8c7 100644
--- a/src/native/windows/apps/prunmgr/prunmgr.c
+++ b/src/native/windows/apps/prunmgr/prunmgr.c
@@ -51,6 +51,7 @@ LPAPXGUISTORE _gui_store  = NULL;
 #define LOGL_INFO           L"Info"
 #define LOGL_WARN           L"Warn"
 
+#define START_DELAYED        L"Automatic (Delayed Start)"
 #define START_AUTO           L"Automatic"
 #define START_MANUAL         L"Manual"
 #define START_DISABLED       L"Disabled"
@@ -298,6 +299,8 @@ BOOL __generalPropertySave(HWND hDlg)
     WCHAR szN[SIZ_RESLEN];
     WCHAR szD[SIZ_DESLEN];
     DWORD dwStartType = SERVICE_NO_CHANGE;
+    BOOL  bDelayedStart = FALSE;
+
     int i;
 
     if (!(TST_BIT_FLAG(_propertyChanged, 1)))
@@ -309,14 +312,18 @@ BOOL __generalPropertySave(HWND hDlg)
     GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, SIZ_RESMAX);
     GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, SIZ_DESMAX);
     i = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST));
-    if (i == 0)
+    if (i == 0) {
         dwStartType = SERVICE_AUTO_START;
+        bDelayedStart = TRUE;
+    }
     else if (i == 1)
-        dwStartType = SERVICE_DEMAND_START;
+            dwStartType = SERVICE_AUTO_START;
     else if (i == 2)
+        dwStartType = SERVICE_DEMAND_START;
+    else if (i == 3)
         dwStartType = SERVICE_DISABLED;
     apxServiceSetNames(hService, NULL, szN, szD, NULL, NULL);
-    apxServiceSetOptions(hService, SERVICE_NO_CHANGE, dwStartType, SERVICE_NO_CHANGE);
+    apxServiceSetOptions(hService, SERVICE_NO_CHANGE, dwStartType, bDelayedStart, SERVICE_NO_CHANGE);
 
     if (!(TST_BIT_FLAG(_propertyChanged, 2)))
         PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
@@ -355,12 +362,12 @@ BOOL __generalLogonSave(HWND hDlg)
         if (IsDlgButtonChecked(hDlg, IDC_PPSLID) == BST_CHECKED) {
             apxServiceSetOptions(hService,
                 _currentEntry->stServiceStatus.dwServiceType | SERVICE_INTERACTIVE_PROCESS,
-                SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+                SERVICE_NO_CHANGE, FALSE, SERVICE_NO_CHANGE);
         }
         else {
             apxServiceSetOptions(hService,
                 _currentEntry->stServiceStatus.dwServiceType & ~SERVICE_INTERACTIVE_PROCESS,
-                SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+                SERVICE_NO_CHANGE, FALSE, SERVICE_NO_CHANGE);
         }
     } else {
         if (szP[0] != L' ' &&  szC[0] != L' ' && !lstrcmpW(szP, szC)) {
@@ -607,15 +614,22 @@ LRESULT CALLBACK __generalProperty(HWND hDlg,
                 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_DELAYED);
                 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);
+                if (_currentEntry->lpConfig->dwStartType == SERVICE_AUTO_START) {
+                	if (_currentEntry->bDelayedStart) {
+                		ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 0);
+                	}
+                	else {
+                		ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 1);
+                	}
+                }
                 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);
+                else if (_currentEntry->lpConfig->dwStartType == SERVICE_DISABLED)
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 3);
 
                 SetDlgItemTextW(hDlg, IDC_PPSGNAME, _currentEntry->szServiceName);
                 SetDlgItemTextW(hDlg, IDC_PPSGDISP, _currentEntry->lpConfig->lpDisplayName);
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index dab90e5..cf1ef48 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -64,6 +64,7 @@ static LPCWSTR  PRSRV_JAVA        = L"java";
 static LPCWSTR  PRSRV_JVM         = L"jvm";
 static LPCWSTR  PRSRV_JDK         = L"jdk";
 static LPCWSTR  PRSRV_JRE         = L"jre";
+static LPCWSTR  PRSRV_DELAYED     = L"delayed";
 static LPCWSTR  PRSRV_MANUAL      = L"manual";
 static LPCWSTR  PRSRV_JBIN        = L"\\bin\\java.exe";
 static LPCWSTR  PRSRV_PBIN        = L"\\bin";
@@ -834,6 +835,7 @@ static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
     }
     else {
         DWORD dwStart = SERVICE_NO_CHANGE;
+        BOOL  bDelayedStart = FALSE;
         DWORD dwType  = SERVICE_NO_CHANGE;
         LPCWSTR su = NULL;
         LPCWSTR sp = NULL;
@@ -855,7 +857,11 @@ static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
                                        sp));
         /* Update the --Startup mode */
         if (ST_STARTUP & APXCMDOPT_FOUND) {
-            if (!lstrcmpiW(SO_STARTUP, PRSRV_AUTO))
+            if (!lstrcmpiW(SO_STARTUP, PRSRV_DELAYED)) {
+                dwStart = SERVICE_AUTO_START;
+                bDelayedStart = TRUE;
+            }
+            else if (!lstrcmpiW(SO_STARTUP, PRSRV_AUTO))
                 dwStart = SERVICE_AUTO_START;
             else if (!lstrcmpiW(SO_STARTUP, PRSRV_MANUAL))
                 dwStart = SERVICE_DEMAND_START;
@@ -867,6 +873,7 @@ static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
         rv = (rv && apxServiceSetOptions(hService,
                                          dwType,
                                          dwStart,
+										 bDelayedStart,
                                          SERVICE_NO_CHANGE));
 
         apxLogWrite(APXLOG_MARK_INFO "Service '%S' updated",
diff --git a/src/native/windows/include/service.h b/src/native/windows/include/service.h
index faebef4..8da60f4 100644
--- a/src/native/windows/include/service.h
+++ b/src/native/windows/include/service.h
@@ -24,6 +24,7 @@ typedef struct APXSERVENTRY {
     WCHAR   szObjectName[SIZ_RESLEN];
     WCHAR   szServiceDescription[SIZ_DESLEN];
     LPQUERY_SERVICE_CONFIGW lpConfig;
+    BOOL					bDelayedStart;
     SERVICE_STATUS          stServiceStatus;
     SERVICE_STATUS_PROCESS  stStatusProcess;
 
@@ -41,7 +42,8 @@ BOOL        apxServiceSetNames(APXHANDLE hService, LPCWSTR szImagePath,
                                LPCWSTR szUsername, LPCWSTR szPassword);
 
 BOOL        apxServiceSetOptions(APXHANDLE hService, DWORD dwServiceType,
-                                 DWORD dwStartType, DWORD dwErrorControl);
+								 DWORD dwStartType, BOOL bDelayedStart,
+								 DWORD dwErrorControl);
 
 BOOL        apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
                               LPAPXFNCALLBACK fnControlCallback,
diff --git a/src/native/windows/src/service.c b/src/native/windows/src/service.c
index 1fcc1c3..6317d58 100644
--- a/src/native/windows/src/service.c
+++ b/src/native/windows/src/service.c
@@ -107,6 +107,7 @@ apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions)
 {
     LPAPXSERVICE lpService;
     DWORD dwNeeded;
+    LPSERVICE_DELAYED_AUTO_START_INFO lpDelayedInfo;
 
     if (hService->dwType != APXHANDLE_TYPE_SERVICE)
         return FALSE;
@@ -157,11 +158,36 @@ apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions)
             apxLogWrite(APXLOG_MARK_SYSERR);
         }
     }
-    lpService->stServiceEntry.lpConfig =  (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
-                                                                                dwNeeded);
-    return QueryServiceConfigW(lpService->hService,
-                               lpService->stServiceEntry.lpConfig,
-                               dwNeeded, &dwNeeded);
+    lpService->stServiceEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
+                                                                               dwNeeded);
+    if (!QueryServiceConfigW(lpService->hService,
+                             lpService->stServiceEntry.lpConfig,
+                             dwNeeded, &dwNeeded)) {
+    	return FALSE;
+    }
+
+    if (!QueryServiceConfig2W(lpService->hService, SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
+                              NULL, 0, &dwNeeded)) {
+        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+            // This is expected. The call is expected to fail with the required
+            // buffer size set in dwNeeded.
+            // Clear the last error to prevent it being logged if a genuine
+            // error occurs
+            SetLastError(ERROR_SUCCESS);
+        } else {
+            apxLogWrite(APXLOG_MARK_SYSERR);
+        }
+    }
+    lpDelayedInfo = (LPSERVICE_DELAYED_AUTO_START_INFO) apxPoolAlloc(hService->hPool, dwNeeded);
+
+    if (!QueryServiceConfig2W(lpService->hService, SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
+                              (LPBYTE) lpDelayedInfo, dwNeeded, &dwNeeded)) {
+    	return FALSE;
+    }
+
+    lpService->stServiceEntry.bDelayedStart = lpDelayedInfo->fDelayedAutostart;
+    apxFree(lpDelayedInfo);
+    return TRUE;
 }
 
 LPAPXSERVENTRY
@@ -240,9 +266,11 @@ BOOL
 apxServiceSetOptions(APXHANDLE hService,
                      DWORD dwServiceType,
                      DWORD dwStartType,
+					 BOOL bDelayedStart,
                      DWORD dwErrorControl)
 {
     LPAPXSERVICE lpService;
+    SERVICE_DELAYED_AUTO_START_INFO sDelayedInfo;
 
     if (hService->dwType != APXHANDLE_TYPE_SERVICE)
         return FALSE;
@@ -254,10 +282,22 @@ apxServiceSetOptions(APXHANDLE hService,
     /* 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);
+
+    if (!ChangeServiceConfig(lpService->hService, dwServiceType,
+                                   dwStartType, dwErrorControl,
+                                   NULL, NULL, NULL, NULL, NULL,
+                                   NULL, NULL)) {
+    	return FALSE;
+    }
+
+    if (dwStartType == SERVICE_AUTO_START) {
+    	sDelayedInfo.fDelayedAutostart = bDelayedStart;
+    	return ChangeServiceConfig2A(lpService->hService,
+                                     SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
+                                     &sDelayedInfo);
+    }
+
+    return TRUE;
 }
 
 static BOOL
diff --git a/src/site/xdoc/procrun.xml b/src/site/xdoc/procrun.xml
index 5838b24..9a49b81 100644
--- a/src/site/xdoc/procrun.xml
+++ b/src/site/xdoc/procrun.xml
@@ -312,7 +312,7 @@ will add the new value(s) to any existing value(s).
     <tr>
     <td>--Startup</td>
     <td>manual</td>
-    <td>Service startup mode can be either <b>auto</b> or <b>manual</b></td>
+    <td>Service startup mode can be either <b>delayed</b>, <b>auto</b> or <b>manual</b></td>
     </tr>
     <tr>
     <td>--Type</td>


[commons-daemon] 03/05: Remove unused code

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit acfefa3114d5e2adb881a83a9c505873c58d4d05
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 12 22:48:14 2019 +0100

    Remove unused code
---
 src/native/windows/src/private.h  | 43 +++++++++-----------------
 src/native/windows/src/registry.c | 65 ---------------------------------------
 2 files changed, 15 insertions(+), 93 deletions(-)

diff --git a/src/native/windows/src/private.h b/src/native/windows/src/private.h
index 7c0db81..175df9f 100644
--- a/src/native/windows/src/private.h
+++ b/src/native/windows/src/private.h
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #ifndef _PRIVATE_H_INCLUDED_
 #define _PRIVATE_H_INCLUDED_
 
@@ -139,7 +139,7 @@ struct {                                                                \
         }                                                               \
         *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);              \
 } while (0)
-  
+
 /** Some usefull macros */
 
 #define APXHANDLE_SPINLOCK(h)               \
@@ -169,7 +169,7 @@ struct {                                                                \
 /*
  * 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);
@@ -187,36 +187,36 @@ struct APXCALLHOOK {
 };
 
 struct stAPXHANDLE {
-    /** The type of the handle */ 
-    DWORD               dwType;         
-    /** Handle Flags */ 
+    /** The type of the handle */
+    DWORD               dwType;
+    /** Handle Flags */
     DWORD               dwFlags;
-    /** Handle user data size */ 
+    /** Handle user data size */
     DWORD               dwSize;
-    /** parameters for event callback */ 
+    /** parameters for event callback */
     WPARAM              wParam;
     LPARAM              lParam;
     UINT                uMsg;
-    /** main callback function (using default if not specified) */ 
+    /** 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 */ 
+    /** interlocking value */
     LONG volatile       lvSpin;
 
-    /** message event handle  */ 
+    /** message event handle  */
     HANDLE              hEventHandle;
-    /** message event thread  */ 
+    /** message event thread  */
     HANDLE              hEventThread;
-    /** message event thread id  */ 
+    /** message event thread id  */
     DWORD               hEventThreadId;
     /** private local heap */
     HANDLE              hHeap;
-    /** list enty for pool  */ 
+    /** list enty for pool  */
     TAILQ_ENTRY(stAPXHANDLE)  queue;
-    /** small userdata pointer  */ 
+    /** small userdata pointer  */
     union   {
         LPVOID          lpPtr;
         HANDLE          hWinHandle;
@@ -236,19 +236,6 @@ struct APXMULTISZ {
     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    apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
                                   DWORD dwDescriptionLength);
 BOOL    apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
diff --git a/src/native/windows/src/registry.c b/src/native/windows/src/registry.c
index eb4ed46..d5f1958 100644
--- a/src/native/windows/src/registry.c
+++ b/src/native/windows/src/registry.c
@@ -848,71 +848,6 @@ LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool)
     return NULL;
 }
 
-/* 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;
-}
-
 BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
                                DWORD dwDescriptionLength)
 {