You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2002/06/24 09:53:50 UTC
cvs commit: httpd-2.0/server/mpm/winnt mpm_winnt.c mpm_winnt.h service.c registry.c
wrowe 2002/06/24 00:53:50
Modified: . libhttpd.dsp
server/mpm/winnt mpm_winnt.c mpm_winnt.h service.c
Removed: server/mpm/winnt registry.c
Log:
Move the last little useful bit of registry.c into services.c, and
blast it. All Win32 registry foo is going through ap_regkey now.
Revision Changes Path
1.42 +29 -8 httpd-2.0/libhttpd.dsp
Index: libhttpd.dsp
===================================================================
RCS file: /home/cvs/httpd-2.0/libhttpd.dsp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- libhttpd.dsp 24 Jun 2002 04:55:52 -0000 1.41
+++ libhttpd.dsp 24 Jun 2002 07:53:49 -0000 1.42
@@ -223,6 +223,35 @@
# End Source File
# Begin Source File
+SOURCE=.\os\win32\ap_regkey.h
+
+!IF "$(CFG)" == "libhttpd - Win32 Release"
+
+# PROP Ignore_Default_Tool 1
+# Begin Custom Build - Creating include/ap_regkey.h
+InputPath=.\os\win32\ap_regkey.h
+
+".\include\ap_regkey.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ type .\os\win32\ap_regkey.h > .\include\ap_regkey.h
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "libhttpd - Win32 Debug"
+
+# PROP Ignore_Default_Tool 1
+# Begin Custom Build - Creating include/ap_regkey.h
+InputPath=.\os\win32\ap_regkey.h
+
+".\include\ap_regkey.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ type .\os\win32\ap_regkey.h > .\include\ap_regkey.h
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
SOURCE=.\modules\http\mod_core.h
!IF "$(CFG)" == "libhttpd - Win32 Release"
@@ -499,10 +528,6 @@
# End Source File
# Begin Source File
-SOURCE=.\os\win32\ap_regkey.h
-# End Source File
-# Begin Source File
-
SOURCE=.\server\error_bucket.c
# End Source File
# Begin Source File
@@ -620,10 +645,6 @@
# Begin Source File
SOURCE=.\server\mpm\winnt\nt_eventlog.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\server\mpm\winnt\registry.c
# End Source File
# Begin Source File
1.279 +3 -1 httpd-2.0/server/mpm/winnt/mpm_winnt.c
Index: mpm_winnt.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm_winnt.c,v
retrieving revision 1.278
retrieving revision 1.279
diff -u -r1.278 -r1.279
--- mpm_winnt.c 23 Jun 2002 10:24:07 -0000 1.278
+++ mpm_winnt.c 24 Jun 2002 07:53:50 -0000 1.279
@@ -110,7 +110,7 @@
typedef HANDLE thread;
/* Definitions of WINNT MPM specific config globals */
-static apr_pool_t *pconf;
+apr_pool_t *pconf;
static apr_pool_t *pchild = NULL;
static int workers_may_exit = 0;
static int shutdown_in_progress = 0;
@@ -2070,6 +2070,8 @@
apr_getopt_t *opt;
int running_as_service = 1;
int errout = 0;
+
+ pconf = process->pconf;
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osver);
1.38 +0 -18 httpd-2.0/server/mpm/winnt/mpm_winnt.h
Index: mpm_winnt.h
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm_winnt.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- mpm_winnt.h 23 Jun 2002 10:24:07 -0000 1.37
+++ mpm_winnt.h 24 Jun 2002 07:53:50 -0000 1.38
@@ -61,24 +61,6 @@
#include "ap_listen.h"
-/* From registry.c: */
-
-apr_status_t ap_registry_create_key(const char *key);
-apr_status_t ap_registry_delete_key(const char *key);
-
-apr_status_t ap_registry_store_value(const char *key, const char *name,
- const char *value);
-apr_status_t ap_registry_get_value(apr_pool_t *p, const char *key,
- const char *name, char **ppValue);
-apr_status_t ap_registry_store_array(apr_pool_t *p, const char *key,
- const char *name, int nelts,
- char const* const* elts);
-apr_status_t ap_registry_get_array(apr_pool_t *p, const char *key,
- const char *name,
- apr_array_header_t **parray);
-apr_status_t ap_registry_delete_value(const char *key, const char *name);
-
-
/* From service.c: */
#define SERVICE_APACHE_RESTART 128
1.55 +119 -26 httpd-2.0/server/mpm/winnt/service.c
Index: service.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/service.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- service.c 23 Jun 2002 10:24:07 -0000 1.54
+++ service.c 24 Jun 2002 07:53:50 -0000 1.55
@@ -69,6 +69,7 @@
#include "mpm_winnt.h"
#include "apr_strings.h"
#include "apr_lib.h"
+#include "ap_regkey.h"
#ifdef NOUSER
#undef NOUSER
@@ -92,6 +93,43 @@
static int ReportStatusToSCMgr(int currentState, int exitCode, int waitHint);
+
+#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;
+}
+
+
/* The service configuration's is stored under the following trees:
*
* HKLM\System\CurrentControlSet\Services\[service name]
@@ -420,6 +458,9 @@
* notify the service control manager of the name change.
*/
+/* borrowed from mpm_winnt.c */
+extern apr_pool_t *pconf;
+
/* 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.
@@ -450,6 +491,7 @@
/* Cast is necessary, ChangeServiceConfig2 handles multiple
* object types, some volatile, some not.
*/
+ /* ###: utf-ize */
if (ChangeServiceConfig2(schService,
1 /* SERVICE_CONFIG_DESCRIPTION */,
(LPVOID) &full_description)) {
@@ -463,22 +505,21 @@
if (full_description)
{
char szPath[MAX_PATH];
- HKEY hkey;
+ ap_regkey_t *svckey;
+ apr_status_t rv;
- /* Create/Find the Service key that Monitor Applications iterate */
+ /* Find the Service key that Monitor Applications iterate */
apr_snprintf(szPath, sizeof(szPath),
"SYSTEM\\CurrentControlSet\\Services\\%s",
mpm_service_name);
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szPath, 0, KEY_SET_VALUE, &hkey)
- != ERROR_SUCCESS) {
+ rv = ap_regkey_open(&svckey, AP_REGKEY_LOCAL_MACHINE, szPath,
+ APR_WRITE, pconf);
+ if (rv != APR_SUCCESS) {
return;
}
-
/* Attempt to set the Description value for our service */
- RegSetValueEx(hkey, "Description", 0, REG_SZ,
- (unsigned char *) full_description,
- strlen(full_description) + 1);
- RegCloseKey(hkey);
+ ap_regkey_value_set(svckey, "Description", full_description, pconf);
+ ap_regkey_close(svckey);
}
}
@@ -509,6 +550,7 @@
*/
extern apr_array_header_t *mpm_new_argv;
+/* ###: utf-ize */
static void __stdcall service_nt_main_fn(DWORD argc, LPTSTR *argv)
{
const char *ignored;
@@ -521,6 +563,7 @@
globdat.ssStatus.dwCurrentState = SERVICE_START_PENDING;
globdat.ssStatus.dwCheckPoint = 1;
+ /* ###: utf-ize */
if (!(globdat.hServiceStatus = RegisterServiceCtrlHandler(argv[0], service_nt_ctrl)))
{
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(),
@@ -574,6 +617,7 @@
{ NULL, NULL }
};
+ /* ###: utf-ize */
if (!StartServiceCtrlDispatcher(dispatchTable))
{
/* This is a genuine failure of the SCM. */
@@ -590,6 +634,7 @@
const char *set_name)
{
char key_name[MAX_PATH];
+ ap_regkey_t *key;
apr_status_t rv;
/* ### Needs improvement, on Win2K the user can _easily_
@@ -599,11 +644,15 @@
mpm_service_name = apr_palloc(p, strlen(set_name) + 1);
apr_collapse_spaces((char*) mpm_service_name, set_name);
apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, mpm_service_name);
- rv = ap_registry_get_value(p, key_name, "DisplayName", &mpm_display_name);
+ rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, key_name, APR_READ, pconf);
+ if (rv == APR_SUCCESS) {
+ rv = ap_regkey_value_get(&mpm_display_name, key, "DisplayName", pconf);
+ ap_regkey_close(key);
+ }
if (rv != APR_SUCCESS) {
/* Take the given literal name if there is no service entry */
mpm_display_name = apr_pstrdup(p, set_name);
- }
+ }
*display_name = mpm_display_name;
return rv;
}
@@ -617,9 +666,14 @@
char conf_key[MAX_PATH];
char **cmb_data;
apr_status_t rv;
+ ap_regkey_t *key;
apr_snprintf(conf_key, sizeof(conf_key), SERVICEPARAMS, mpm_service_name);
- rv = ap_registry_get_array(p, conf_key, "ConfigArgs", &svc_args);
+ rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, conf_key, APR_READ, p);
+ if (rv == APR_SUCCESS) {
+ rv = ap_regkey_value_array_get(&svc_args, key, "ConfigArgs", p);
+ ap_regkey_close(key);
+ }
if (rv != APR_SUCCESS) {
if (rv == ERROR_FILE_NOT_FOUND) {
ap_log_error(APLOG_MARK, APLOG_INFO, 0, NULL,
@@ -781,11 +835,13 @@
char key_name[MAX_PATH];
char exe_path[MAX_PATH];
char *launch_cmd;
- apr_status_t(rv);
+ ap_regkey_t *key;
+ apr_status_t rv;
fprintf(stderr,reconfig ? "Reconfiguring the %s service\n"
: "Installing the %s service\n", mpm_display_name);
+ /* ###: utf-ize */
if (GetModuleFileName(NULL, exe_path, sizeof(exe_path)) == 0)
{
apr_status_t rv = apr_get_os_error();
@@ -812,6 +868,7 @@
launch_cmd = apr_psprintf(ptemp, "\"%s\" -k runservice", exe_path);
if (reconfig) {
+ /* ###: utf-ize */
schService = OpenService(schSCManager, mpm_service_name,
SERVICE_ALL_ACCESS);
if (!schService) {
@@ -819,6 +876,7 @@
apr_get_os_error(), NULL,
"OpenService failed");
}
+ /* ###: utf-ize */
else if (!ChangeServiceConfig(schService,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
@@ -841,6 +899,7 @@
* be warned that future apache modules or ISAPI dll's may
* depend on it.
*/
+ /* ###: utf-ize */
schService = CreateService(schSCManager, // SCManager database
mpm_service_name, // name of service
mpm_display_name, // name to display
@@ -873,7 +932,12 @@
/* Store the launch command in the registry */
launch_cmd = apr_psprintf(ptemp, "\"%s\" -n %s -k runservice",
exe_path, mpm_service_name);
- rv = ap_registry_store_value(SERVICECONFIG9X, mpm_service_name, launch_cmd);
+ rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, SERVICECONFIG9X,
+ APR_READ, pconf);
+ if (rv == APR_SUCCESS) {
+ rv = ap_regkey_value_set(key, mpm_service_name, launch_cmd, pconf);
+ ap_regkey_close(key);
+ }
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to add the RunServices registry entry.",
@@ -882,14 +946,24 @@
}
apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, mpm_service_name);
- rv = ap_registry_store_value(key_name, "ImagePath", launch_cmd);
+ rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, key_name,
+ APR_READ, pconf);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
+ "%s: Failed to create the registry service key.",
+ mpm_display_name);
+ return (rv);
+ }
+ rv = ap_regkey_value_set(key, "ImagePath", launch_cmd, pconf);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to store ImagePath in the registry.",
mpm_display_name);
+ ap_regkey_close(key);
return (rv);
}
- rv = ap_registry_store_value(key_name, "DisplayName", mpm_display_name);
+ rv = ap_regkey_value_set(key, "DisplayName", mpm_display_name, pconf);
+ ap_regkey_close(key);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to store DisplayName in the registry.",
@@ -903,7 +977,12 @@
/* For both WinNT & Win9x store the service ConfigArgs in the registry...
*/
apr_snprintf(key_name, sizeof(key_name), SERVICEPARAMS, mpm_service_name);
- rv = ap_registry_store_array(ptemp, key_name, "ConfigArgs", argc, argv);
+ rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, key_name,
+ APR_READ, pconf);
+ if (rv == APR_SUCCESS) {
+ rv = ap_regkey_value_array_set(key, "ConfigArgs", argc, argv, pconf);
+ ap_regkey_close(key);
+ }
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to store the ConfigArgs in the registry.",
@@ -937,6 +1016,7 @@
return (rv);
}
+ /* ###: utf-ize */
schService = OpenService(schSCManager, mpm_service_name, SERVICE_ALL_ACCESS);
if (!schService) {
@@ -968,28 +1048,38 @@
}
else /* osver.dwPlatformId != VER_PLATFORM_WIN32_NT */
{
+ apr_status_t rv2, rv3;
+ ap_regkey_t *key;
fprintf(stderr,"Removing the %s service\n", mpm_display_name);
/* TODO: assure the service is stopped before continuing */
- if (ap_registry_delete_value(SERVICECONFIG9X, mpm_service_name)) {
- rv = apr_get_os_error();
+ rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, SERVICECONFIG9X,
+ APR_WRITE, pconf);
+ if (rv == APR_SUCCESS) {
+ rv = ap_regkey_value_remove(key, mpm_service_name, pconf);
+ ap_regkey_close(key);
+ }
+ if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to remove the RunServices registry "
"entry.", mpm_display_name);
- return (rv);
}
/* we blast Services/us, not just the Services/us/Parameters branch */
+ apr_snprintf(key_name, sizeof(key_name), SERVICEPARAMS, mpm_service_name);
+ rv2 = ap_regkey_remove(AP_REGKEY_LOCAL_MACHINE, key_name, pconf);
apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, mpm_service_name);
- if (ap_registry_delete_key(key_name))
- {
- rv = apr_get_os_error();
- ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
+ rv3 = ap_regkey_remove(AP_REGKEY_LOCAL_MACHINE, key_name, pconf);
+ rv2 = (rv2 != APR_SUCCESS) ? rv2 : rv3;
+ if (rv2 != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv2, NULL,
"%s: Failed to remove the service config from the "
"registry.", mpm_display_name);
- return (rv);
}
+ rv = (rv != APR_SUCCESS) ? rv : rv2;
+ if (rv != APR_SUCCESS)
+ return rv;
}
fprintf(stderr,"The %s service has been removed successfully.\n", mpm_display_name);
return APR_SUCCESS;
@@ -1041,6 +1131,7 @@
return (rv);
}
+ /* ###: utf-ize */
schService = OpenService(schSCManager, mpm_service_name,
SERVICE_START | SERVICE_QUERY_STATUS);
if (!schService) {
@@ -1065,6 +1156,7 @@
start_argv[argc] = NULL;
rv = APR_EINIT;
+ /* ###: utf-ize */
if (StartService(schService, argc, start_argv)
&& signal_service_transition(schService, 0, /* test only */
SERVICE_START_PENDING,
@@ -1178,7 +1270,8 @@
"Failed to open the NT Service Manager");
return;
}
-
+
+ /* ###: utf-ize */
schService = OpenService(schSCManager, mpm_service_name,
SERVICE_ALL_ACCESS);