httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apache-1.3/src/os/win32 service.c
Date Mon, 26 Mar 2001 17:13:46 GMT
wrowe       01/03/26 09:13:46

  Modified:    src      CHANGES
               src/os/win32 service.c
  Log:
    Fixed the Description service value to apply to all Win32 platforms.
  
  Revision  Changes    Path
  1.1669    +6 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1668
  retrieving revision 1.1669
  diff -u -r1.1668 -r1.1669
  --- CHANGES	2001/03/22 19:53:33	1.1668
  +++ CHANGES	2001/03/26 17:13:41	1.1669
  @@ -1,4 +1,10 @@
   Changes with Apache 1.3.20
  +
  +  *) Populate the Win32 HKLM\System\CurrentControlSet\Services\[apachesvc]
  +     key with the Description value of the running server across all Win32
  +     platforms, including NT, ME and 9x.  This value is the server_version
  +     string including loaded modules.  [William Rowe]
  +
     *) Fix ndbm.h include problems with various Linux distributions and 
        brain-dead glibc >= 2.1, which sometimes have ndbm.h in a
        non-standard db1/ subdir. PR#6929
  
  
  
  1.48      +82 -43    apache-1.3/src/os/win32/service.c
  
  Index: service.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/os/win32/service.c,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- service.c	2001/02/27 06:53:08	1.47
  +++ service.c	2001/03/26 17:13:44	1.48
  @@ -670,11 +670,92 @@
   }
   
   
  +/* Set the service description regardless of platform.
  + * We revert to set_service_description_string on NT/9x, the
  + * very long way so any Apache management program can grab the
  + * description.  This would be bad on Win2000, since it wouldn't
  + * notify the service control manager of the name change.
  + */
  +static void set_service_description_string(const char *description)
  +{
  +    char szPath[MAX_PATH];
  +    HKEY hkey;
  +
  +    /* Create/Find the Service key that Monitor Applications iterate */
  +    ap_snprintf(szPath, sizeof(szPath), 
  +                "SYSTEM\\CurrentControlSet\\Services\\%s", globdat.name);
  +    ap_remove_spaces(szPath, szPath);
  +    if (RegCreateKey(HKEY_LOCAL_MACHINE, szPath, &hkey) != ERROR_SUCCESS) {
  +        return;
  +    }
  +
  +    /* Attempt to set the Description value for our service */
  +    RegSetValueEx(hkey, "Description", 0, REG_SZ,  
  +                  (unsigned char *) description, 
  +                  strlen(description) + 1);
  +    RegCloseKey(hkey);
  +}
  +
  +
  +/* ChangeServiceConfig2() prototype:
  + */
  +typedef WINADVAPI BOOL (*CSD_T)(SC_HANDLE, DWORD, LPCVOID);
  +
  +
  +/* Windows 2000 alone supports ChangeServiceConfig2 in order to
  + * register our server_version string... so we need some fixups
  + * to avoid binding to that function if we are on WinNT/9x.
  + * Fall back on set_service_description_string if we fail.
  + */
   void service_set_status(int status)
   {
  +    const char *full_description;
  +    SC_HANDLE schSCManager;
  +    CSD_T ChangeServiceDescription;
  +    HANDLE hwin2000scm;
  +    BOOL ret;
  +
  +    /* Nothing to do if we are a console
  +     */
  +    if (!is_service)
  +        return;
  +
       ReportStatusToSCMgr(status, NO_ERROR, 3000);
  -}
   
  +    if (status != SERVICE_RUNNING)
  +        return;
  +
  +    /* Time to fix up the description, upon each successful restart
  +     */
  +    full_description = ap_get_server_version();
  +    hwin2000scm = LoadLibrary("ADVAPI32.DLL");
  +    if (!hwin2000scm) {
  +        set_service_description_string(full_description);
  +        return;
  +    }
  +    ChangeServiceDescription = (CSD_T) GetProcAddress(hwin2000scm, 
  +                                                      "ChangeServiceConfig2A");
  +    if (!ChangeServiceDescription) {
  +        FreeLibrary(hwin2000scm);
  +        set_service_description_string(full_description);
  +        return;
  +    }
  +    schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  +    if (schSCManager) {
  +        SC_HANDLE schService = OpenService(schSCManager, globdat.name,
  +                                           SERVICE_ALL_ACCESS);
  +        if (schService) {
  +            ret = ChangeServiceDescription(schService,
  +                                           SERVICE_CONFIG_DESCRIPTION,
  +                                           &full_description);
  +            CloseServiceHandle(schService);
  +        }
  +        CloseServiceHandle(schSCManager);
  +    }
  +    if (!ret)
  +        set_service_description_string(full_description);
  +    FreeLibrary(hwin2000scm);
  +}
   
   
   //
  @@ -732,46 +813,8 @@
   }
   
   
  -typedef WINADVAPI BOOL (*CSD_T)(SC_HANDLE, DWORD, LPCVOID);
  -    
  -/* Windows 2000 only supports ChangeServiceConfig2 in order to
  - * register our server_version string... so we need some fixups
  - * to avoid binding to that function if we are on WinNT/9x
  - */
  -void ReportDescriptionToSCM()
  -{
  -    const char *full_description = ap_get_server_version();
  -    SC_HANDLE schSCManager;
  -    CSD_T ChangeServiceDescription;    
  -    HANDLE hwin2000scm = LoadLibrary("ADVAPI32.DLL");
  -    if (!hwin2000scm) 
  -        return;
  -    ChangeServiceDescription = (CSD_T) GetProcAddress(hwin2000scm, 
  -                                                      "ChangeServiceConfig2A");
  -    if (!ChangeServiceDescription) {
  -        FreeLibrary(hwin2000scm);
  -        return;
  -    }
  -    schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  -    if (schSCManager) {
  -        SC_HANDLE schService = OpenService(schSCManager, globdat.name,
  -                                           SERVICE_ALL_ACCESS);
  -        if (schService) {
  -            /* In advapi32 -only- on Win2000 */
  -            ChangeServiceDescription(schService,
  -                                     SERVICE_CONFIG_DESCRIPTION,
  -                                     &full_description);
  -            CloseServiceHandle(schService);
  -        }
  -        CloseServiceHandle(schSCManager);
  -    }
  -    FreeLibrary(hwin2000scm);
  -}
  -
  -
   int ReportStatusToSCMgr(int currentState, int exitCode, int waitHint)
   {
  -    static int onceStarted = 1;
       static int firstTime = 1;
       static int checkPoint = 1;
       int rv;
  @@ -808,10 +851,6 @@
               globdat.ssStatus.dwCheckPoint = ++checkPoint;
   
           rv = SetServiceStatus(globdat.hServiceStatus, &globdat.ssStatus);
  -
  -        if (currentState == SERVICE_RUNNING && onceStarted) {
  -            onceStarted = 0;
  -        }
       }
       return(1);
   }
  
  
  

Mime
View raw message