]> granicus.if.org Git - apache/blobdiff - server/mpm/winnt/service.c
Cleanup effort in prep for GA push:
[apache] / server / mpm / winnt / service.c
index a4ffd0400f272b62cdff057379f45a94ae880b76..1c145be9b798c0c53347a7bfa340b9433f0ab813 100644 (file)
@@ -33,6 +33,7 @@
 #endif
 #undef _WINUSER_
 #include <winuser.h>
+#include <time.h>
 
 APLOG_USE_MODULE(mpm_winnt);
 
@@ -56,43 +57,6 @@ static nt_service_ctx_t globdat;
 static int ReportStatusToSCMgr(int currentState, int waitHint,
                                nt_service_ctx_t *ctx);
 
-
-#define PRODREGKEY "SOFTWARE\\" AP_SERVER_BASEVENDOR "\\" \
-                   AP_SERVER_BASEPRODUCT "\\" AP_SERVER_BASEREVISION
-
-/*
- * Get the server root from the registry into 'dir' which is
- * size bytes long. Returns 0 if the server root was found
- * or if the serverroot key does not exist (in which case
- * dir will contain an empty string), or -1 if there was
- * an error getting the key.
- */
-apr_status_t ap_registry_get_server_root(apr_pool_t *p, char **buf)
-{
-    apr_status_t rv;
-    ap_regkey_t *key;
-
-    if ((rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, PRODREGKEY,
-                             APR_READ, p)) == APR_SUCCESS) {
-        rv = ap_regkey_value_get(buf, key, "ServerRoot", p);
-        ap_regkey_close(key);
-        if (rv == APR_SUCCESS)
-            return rv;
-    }
-
-    if ((rv = ap_regkey_open(&key, AP_REGKEY_CURRENT_USER, PRODREGKEY,
-                             APR_READ, p)) == APR_SUCCESS) {
-        rv = ap_regkey_value_get(buf, key, "ServerRoot", p);
-        ap_regkey_close(key);
-        if (rv == APR_SUCCESS)
-            return rv;
-    }
-
-    *buf = NULL;
-    return rv;
-}
-
-
 /* exit() for Win32 is macro mapped (horrible, we agree) that allows us
  * to catch the non-zero conditions and inform the console process that
  * the application died, and hang on to the console a bit longer.
@@ -148,7 +112,8 @@ void hold_console_open_on_error(void)
                 return;
         }
         remains = ((start + 30) - time(NULL));
-        sprintf (count, "%d...", remains);
+        sprintf(count, "%d...",
+                (int)remains); /* 30 or less, so can't overflow int */
         if (!SetConsoleCursorPosition(hConErr, coninfo.dwCursorPosition))
             return;
         if (!WriteConsole(hConErr, count, (DWORD)strlen(count), &result, NULL)
@@ -158,8 +123,6 @@ void hold_console_open_on_error(void)
     while ((remains > 0) && WaitForSingleObject(hConIn, 1000) != WAIT_FAILED);
 }
 
-static BOOL  die_on_logoff = FALSE;
-
 static BOOL CALLBACK console_control_handler(DWORD ctrl_type)
 {
     switch (ctrl_type)
@@ -209,39 +172,6 @@ void mpm_start_console_handler(void)
 }
 
 
-/* Special situation - children of services need to mind their
- * P's & Q's and wait quietly, ignoring the mean OS signaling
- * shutdown and other horrors, to kill them gracefully...
- */
-
-static BOOL CALLBACK child_control_handler(DWORD ctrl_type)
-{
-    switch (ctrl_type)
-    {
-        case CTRL_C_EVENT:
-        case CTRL_BREAK_EVENT:
-            /* for Interrupt signals, ignore them.
-             * The system will also signal the parent process,
-             * which will terminate Apache.
-             */
-            return TRUE;
-
-        case CTRL_CLOSE_EVENT:
-        case CTRL_LOGOFF_EVENT:
-        case CTRL_SHUTDOWN_EVENT:
-            /* for Shutdown signals, ignore them, but...             .
-             * The system will also signal the parent process,
-             * which will terminate Apache, so we need to wait.
-             */
-            Sleep(30000);
-            return TRUE;
-    }
-
-    /* We should never get here, but this is (mostly) harmless */
-    return FALSE;
-}
-
-
 void mpm_start_child_console_handler(void)
 {
     FreeConsole();
@@ -290,7 +220,7 @@ static int ReportStatusToSCMgr(int currentState, int waitHint,
 }
 
 /* Note this works on Win2000 and later due to ChangeServiceConfig2
- * Continue to test it's existence, but at least drop the feature
+ * Continue to test its existence, but at least drop the feature
  * of revising service description tags prior to Win2000.
  */
 
@@ -301,7 +231,6 @@ static void set_service_description(void)
 {
     const char *full_description;
     SC_HANDLE schSCManager;
-    BOOL ret = 0;
 
     /* Nothing to do if we are a console
      */
@@ -333,7 +262,7 @@ static void set_service_description(void)
 
 /* handle the SCM's ControlService() callbacks to our service */
 
-static DWORD WINAPI service_nt_ctrl(DWORD dwCtrlCode, DWORD dwEventType, 
+static DWORD WINAPI service_nt_ctrl(DWORD dwCtrlCode, DWORD dwEventType,
                                    LPVOID lpEventData, LPVOID lpContext)
 {
     nt_service_ctx_t *ctx = lpContext;
@@ -425,7 +354,7 @@ static void __stdcall service_nt_main_fn(DWORD argc, LPTSTR *argv)
 }
 
 
-DWORD WINAPI service_nt_dispatch_thread(LPVOID nada)
+static DWORD WINAPI service_nt_dispatch_thread(LPVOID nada)
 {
     apr_status_t rv = APR_SUCCESS;
 
@@ -545,7 +474,7 @@ apr_status_t mpm_merge_service_args(apr_pool_t *p,
 }
 
 
-void service_stopped(void)
+static void service_stopped(void)
 {
     /* Still have a thread & window to clean up, so signal now */
     if (globdat.service_thread)
@@ -693,19 +622,19 @@ apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc,
          * depend on it.
          */
         /* ###: utf-ize */
-        schService = CreateService(schSCManager,         // SCManager database
-                                   mpm_service_name,     // name of service
-                                   mpm_display_name,     // name to display
-                                   SERVICE_ALL_ACCESS,   // access required
-                                   SERVICE_WIN32_OWN_PROCESS,  // service type
-                                   SERVICE_AUTO_START,   // start type
-                                   SERVICE_ERROR_NORMAL, // error control type
-                                   launch_cmd,           // service's binary
-                                   NULL,                 // no load svc group
-                                   NULL,                 // no tag identifier
-                                   "Tcpip\0Afd\0",       // dependencies
-                                   NULL,                 // use SYSTEM account
-                                   NULL);                // no password
+        schService = CreateService(schSCManager,         /* SCManager database */
+                                   mpm_service_name,     /* name of service    */
+                                   mpm_display_name,     /* name to display    */
+                                   SERVICE_ALL_ACCESS,   /* access required    */
+                                   SERVICE_WIN32_OWN_PROCESS,  /* service type */
+                                   SERVICE_AUTO_START,   /* start type         */
+                                   SERVICE_ERROR_NORMAL, /* error control type */
+                                   launch_cmd,           /* service's binary   */
+                                   NULL,                 /* no load svc group  */
+                                   NULL,                 /* no tag identifier  */
+                                   "Tcpip\0Afd\0",       /* dependencies       */
+                                   NULL,                 /* use SYSTEM account */
+                                   NULL);                /* no password        */
 
         if (!schService)
         {
@@ -821,7 +750,7 @@ apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc,
                                const char * const * argv)
 {
     apr_status_t rv;
-    char **start_argv;
+    CHAR **start_argv;
     SC_HANDLE   schService;
     SC_HANDLE   schSCManager;
 
@@ -892,7 +821,7 @@ void mpm_signal_service(apr_pool_t *ptemp, int signal)
     SC_HANDLE   schService;
     SC_HANDLE   schSCManager;
 
-    schSCManager = OpenSCManager(NULL, NULL, // default machine & database
+    schSCManager = OpenSCManager(NULL, NULL, /* default machine & database */
                                  SC_MANAGER_CONNECT);
 
     if (!schSCManager) {