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 2001/04/12 15:58:35 UTC
cvs commit: httpd-2.0/server/mpm/winnt mpm_winnt.c mpm_winnt.h service.c
wrowe 01/04/12 06:58:35
Modified: server/mpm/winnt mpm_winnt.c mpm_winnt.h service.c
Log:
Clean up some exposed data that should be internal to service.c
Revision Changes Path
1.156 +20 -19 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.155
retrieving revision 1.156
diff -u -r1.155 -r1.156
--- mpm_winnt.c 2001/04/03 01:09:25 1.155
+++ mpm_winnt.c 2001/04/12 13:58:33 1.156
@@ -1521,8 +1521,6 @@
}
-#define SERVICE_UNNAMED (-1)
-
/* service_nt_main_fn needs to append the StartService() args
* outside of our call stack and thread as the service starts...
*/
@@ -1549,9 +1547,12 @@
return APR_ENOTIMPL;
}
+#define SERVICE_UNSET (-1)
+static apr_status_t service_set = SERVICE_UNSET;
static apr_status_t service_to_start_success;
static int inst_argc;
static const char * const *inst_argv;
+static char *service_name = NULL;
void winnt_rewrite_args(process_rec *process)
{
@@ -1563,7 +1564,6 @@
* We can't leave this phase until we know our identity
* and modify the command arguments appropriately.
*/
- apr_status_t service_named = SERVICE_UNNAMED;
apr_status_t rv;
char *def_server_root;
char fnbuf[MAX_PATH];
@@ -1602,7 +1602,7 @@
/* Rewrite process->argv[];
*
* strip out -k signal into signal_arg
- * strip out -n servicename into service_name & display_name
+ * strip out -n servicename and set the names
* add default -d serverroot from the path of this executable
*
* The end result will look like:
@@ -1650,7 +1650,8 @@
optbuf + 1, &optarg) == APR_SUCCESS) {
switch (optbuf[1]) {
case 'n':
- service_named = mpm_service_set_name(process->pool, optarg);
+ service_set = mpm_service_set_name(process->pool, &service_name,
+ optarg);
break;
case 'k':
signal_arg = optarg;
@@ -1702,47 +1703,47 @@
* after logging begins, and the failure can land in the log.
*/
if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
- service_to_start_success = mpm_service_to_start();
+ service_to_start_success = mpm_service_to_start(&service_name);
if (service_to_start_success == APR_SUCCESS)
- service_named = APR_SUCCESS;
+ service_set = APR_SUCCESS;
}
}
- if (service_named == SERVICE_UNNAMED && running_as_service) {
- service_named = mpm_service_set_name(process->pool,
- DEFAULT_SERVICE_NAME);
+ if (service_set == SERVICE_UNSET && running_as_service) {
+ service_set = mpm_service_set_name(process->pool, &service_name,
+ DEFAULT_SERVICE_NAME);
}
if (!strcasecmp(signal_arg, "install")) /* -k install */
{
- if (service_named == APR_SUCCESS)
+ if (service_set == APR_SUCCESS)
{
ap_log_error(APLOG_MARK,APLOG_ERR, 0, NULL,
- "%s: Service is already installed.", display_name);
+ "%s: Service is already installed.", service_name);
exit(1);
}
}
else if (running_as_service)
{
- if (service_named == APR_SUCCESS)
+ if (service_set == APR_SUCCESS)
{
rv = mpm_merge_service_args(process->pool, mpm_new_argv,
fixed_args);
if (rv == APR_SUCCESS) {
ap_log_error(APLOG_MARK,APLOG_NOERRNO|APLOG_INFO, 0, NULL,
"Using ConfigArgs of the installed service "
- "\"%s\".", display_name);
+ "\"%s\".", service_name);
}
else {
ap_log_error(APLOG_MARK,APLOG_INFO, rv, NULL,
"No installed ConfigArgs for the service "
- "\"%s\", using Apache defaults.", display_name);
+ "\"%s\", using Apache defaults.", service_name);
}
}
else
{
ap_log_error(APLOG_MARK,APLOG_INFO|APLOG_NOERRNO, 0, NULL,
- "No installed service named \"%s\".", display_name);
+ "No installed service named \"%s\".", service_name);
exit(1);
}
}
@@ -1782,7 +1783,7 @@
&& (service_to_start_success != APR_SUCCESS)) {
ap_log_error(APLOG_MARK,APLOG_ERR, service_to_start_success, NULL,
"%s: Unable to start the service manager.",
- display_name);
+ service_name);
exit(1);
}
@@ -1886,11 +1887,11 @@
{
if (osver.dwPlatformId != VER_PLATFORM_WIN32_NT)
{
- rv = mpm_service_to_start();
+ rv = mpm_service_to_start(&service_name);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK,APLOG_ERR, rv, server_conf,
"%s: Unable to start the service manager.",
- display_name);
+ service_name);
exit(1);
}
}
1.26 +3 -5 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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- mpm_winnt.h 2001/03/12 17:28:56 1.25
+++ mpm_winnt.h 2001/04/12 13:58:33 1.26
@@ -88,14 +88,12 @@
#define SERVICECONFIG "System\\CurrentControlSet\\Services\\%s"
#define SERVICEPARAMS "System\\CurrentControlSet\\Services\\%s\\Parameters"
-extern char const* service_name;
-extern char const* display_name;
-
-apr_status_t mpm_service_set_name(apr_pool_t *p, const char *name);
+apr_status_t mpm_service_set_name(apr_pool_t *p, const char **display_name,
+ const char *set_name);
apr_status_t mpm_merge_service_args(apr_pool_t *p, apr_array_header_t *args,
int fixed_args);
-apr_status_t mpm_service_to_start(void);
+apr_status_t mpm_service_to_start(const char **display_name);
apr_status_t mpm_service_started(void);
apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc,
char const* const* argv);
1.32 +73 -66 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.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- service.c 2001/03/22 06:01:19 1.31
+++ service.c 2001/04/12 13:58:34 1.32
@@ -76,11 +76,9 @@
#undef _WINUSER_
#include <winuser.h>
-static const char * service_name = NULL;
+static char *mpm_service_name = NULL;
+static char *mpm_display_name = NULL;
-/* ### should be namespace-protected */
-const char * display_name = NULL;
-
static struct
{
HANDLE mpm_thread; /* primary thread handle of the apache server */
@@ -444,7 +442,7 @@
HKEY hk;
errarg[0] = "The Apache service named";
- errarg[1] = display_name;
+ errarg[1] = mpm_display_name;
errarg[2] = "reported the following error:\r\n>>>";
errarg[3] = errmsg;
errarg[4] = "<<<\r\n before the error.log file could be opened.\r\n";
@@ -516,9 +514,10 @@
HANDLE thread;
DWORD threadid;
SECURITY_ATTRIBUTES sa = {0};
-
+ const char *ignored;
+
/* args and service names live in the same pool */
- mpm_service_set_name(mpm_new_argv->cont, argv[0]);
+ mpm_service_set_name(mpm_new_argv->cont, &ignored, argv[0]);
globdat.ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
globdat.ssStatus.dwCurrentState = SERVICE_START_PENDING;
@@ -639,19 +638,26 @@
}
-apr_status_t mpm_service_set_name(apr_pool_t *p, const char *name)
+apr_status_t mpm_service_set_name(apr_pool_t *p, const char **display_name,
+ const char *set_name)
{
char *key_name;
-
- service_name = apr_palloc(p, strlen(name) + 1);
- apr_collapse_spaces((char*) service_name, name);
- key_name = apr_psprintf(p, SERVICECONFIG, service_name);
- if (ap_registry_get_value(p, key_name, "DisplayName", (char**)&display_name) == APR_SUCCESS)
- return APR_SUCCESS;
-
- /* Take the given literal name if there is no service entry */
- display_name = apr_pstrdup(p, name);
- return APR_ENOFILE;
+ apr_status_t rv;
+
+ /* ### Needs improvement, on Win2K the user can _easily_
+ * change the display name to a string that doesn't reflect
+ * the internal service name + whitespace!
+ */
+ mpm_service_name = apr_palloc(p, strlen(set_name) + 1);
+ apr_collapse_spaces((char*) mpm_service_name, set_name);
+ key_name = apr_psprintf(p, SERVICECONFIG, mpm_service_name);
+ rv = ap_registry_get_value(p, key_name, "DisplayName", &mpm_display_name);
+ 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;
}
@@ -664,14 +670,14 @@
char **cmb_data;
apr_status_t rv;
- apr_snprintf(conf_key, sizeof(conf_key), SERVICEPARAMS, service_name);
+ apr_snprintf(conf_key, sizeof(conf_key), SERVICEPARAMS, mpm_service_name);
rv = ap_registry_get_array(p, conf_key, "ConfigArgs", &svc_args);
if (rv != APR_SUCCESS) {
if (rv == ERROR_FILE_NOT_FOUND) {
ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, 0, NULL,
"No ConfigArgs registered for %s, perhaps "
"this service is not installed?",
- service_name);
+ mpm_service_name);
return APR_SUCCESS;
}
else
@@ -682,7 +688,7 @@
return (APR_SUCCESS);
}
- /* Now we have the service_name arg, and the mpm_runservice_nt()
+ /* Now we have the mpm_service_name arg, and the mpm_runservice_nt()
* call appended the arguments passed by StartService(), so it's
* time to _prepend_ the default arguments for the server from
* the service's default arguments (all others override them)...
@@ -735,7 +741,7 @@
}
-apr_status_t mpm_service_to_start(void)
+apr_status_t mpm_service_to_start(const char **display_name)
{
HANDLE waitfor[2];
@@ -759,7 +765,7 @@
if (globdat.signal_monitor)
globdat.service_thread = CreateThread(NULL, 0,
monitor_service_9x_thread,
- (LPVOID) service_name, 0,
+ (LPVOID) mpm_service_name, 0,
&globdat.service_thread_id);
}
@@ -780,6 +786,7 @@
else if (globdat.service_thread)
CloseHandle(globdat.service_thread);
+ *display_name = mpm_display_name;
return APR_SUCCESS;
}
@@ -813,7 +820,7 @@
char *launch_cmd;
apr_status_t(rv);
- printf("Installing the %s service\n", display_name);
+ printf("Installing the %s service\n", mpm_display_name);
if (GetModuleFileName(NULL, exe_path, sizeof(exe_path)) == 0)
{
@@ -846,8 +853,8 @@
* modules or ISAPI dll's may depend on it.
*/
schService = CreateService(schSCManager, // SCManager database
- service_name, // name of service
- display_name, // name to display
+ 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
@@ -875,36 +882,36 @@
{
/* Store the launch command in the registry */
launch_cmd = apr_psprintf(ptemp, "\"%s\" -n %s -k runservice",
- exe_path, service_name);
- rv = ap_registry_store_value(SERVICECONFIG9X, service_name, launch_cmd);
+ exe_path, mpm_service_name);
+ rv = ap_registry_store_value(SERVICECONFIG9X, mpm_service_name, launch_cmd);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to add the RunServices registry entry.",
- display_name);
+ mpm_display_name);
return (rv);
}
- apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, service_name);
- rv = ap_registry_store_value(key_name, "DisplayName", display_name);
+ apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, mpm_service_name);
+ rv = ap_registry_store_value(key_name, "DisplayName", mpm_display_name);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to store DisplayName in the registry.",
- display_name);
+ mpm_display_name);
return (rv);
}
}
/* For both WinNT & Win9x store the service ConfigArgs in the registry...
*/
- apr_snprintf(key_name, sizeof(key_name), SERVICEPARAMS, service_name);
+ apr_snprintf(key_name, sizeof(key_name), SERVICEPARAMS, mpm_service_name);
rv = ap_registry_store_array(ptemp, key_name, "ConfigArgs", argc, argv);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to store the ConfigArgs in the registry.",
- display_name);
+ mpm_display_name);
return (rv);
}
- printf("The %s service is successfully installed.\n", display_name);
+ printf("The %s service is successfully installed.\n", mpm_display_name);
}
@@ -918,7 +925,7 @@
SC_HANDLE schService;
SC_HANDLE schSCManager;
- printf("Removing the %s service\n", display_name);
+ printf("Removing the %s service\n", mpm_display_name);
// TODO: Determine the minimum permissions required for security
schSCManager = OpenSCManager(NULL, NULL, /* local, default database */
@@ -930,12 +937,12 @@
return (rv);
}
- schService = OpenService(schSCManager, service_name, SERVICE_ALL_ACCESS);
+ schService = OpenService(schSCManager, mpm_service_name, SERVICE_ALL_ACCESS);
if (!schService) {
rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
- "%s: OpenService failed", display_name);
+ "%s: OpenService failed", mpm_display_name);
return (rv);
}
@@ -952,7 +959,7 @@
if (DeleteService(schService) == 0) {
rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
- "%s: Failed to delete the service.", display_name);
+ "%s: Failed to delete the service.", mpm_display_name);
return (rv);
}
@@ -961,30 +968,30 @@
}
else /* osver.dwPlatformId != VER_PLATFORM_WIN32_NT */
{
- printf("Removing the %s service\n", display_name);
+ printf("Removing the %s service\n", mpm_display_name);
/* TODO: assure the service is stopped before continuing */
- if (ap_registry_delete_value(SERVICECONFIG9X, service_name)) {
+ if (ap_registry_delete_value(SERVICECONFIG9X, mpm_service_name)) {
rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
"%s: Failed to remove the RunServices registry "
- "entry.", display_name);
+ "entry.", mpm_display_name);
return (rv);
}
/* we blast Services/us, not just the Services/us/Parameters branch */
- apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, service_name);
+ 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,
"%s: Failed to remove the service config from the "
- "registry.", display_name);
+ "registry.", mpm_display_name);
return (rv);
}
}
- printf("The %s service has been removed successfully.\n", display_name);
+ printf("The %s service has been removed successfully.\n", mpm_display_name);
return APR_SUCCESS;
}
@@ -1016,7 +1023,7 @@
{
apr_status_t rv;
- printf("Starting the %s service\n", display_name);
+ printf("Starting the %s service\n", mpm_display_name);
if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
@@ -1034,12 +1041,12 @@
return (rv);
}
- schService = OpenService(schSCManager, service_name,
+ schService = OpenService(schSCManager, mpm_service_name,
SERVICE_START | SERVICE_QUERY_STATUS);
if (!schService) {
rv = apr_get_os_error();
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL,
- "%s: Failed to open the service.", display_name);
+ "%s: Failed to open the service.", mpm_display_name);
CloseServiceHandle(schSCManager);
return (rv);
}
@@ -1047,7 +1054,7 @@
if (QueryServiceStatus(schService, &globdat.ssStatus)
&& (globdat.ssStatus.dwCurrentState == SERVICE_RUNNING)) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL,
- "Service %s is already started!", display_name);
+ "Service %s is already started!", mpm_display_name);
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return 0;
@@ -1055,7 +1062,7 @@
argc += 1;
start_argv = apr_palloc(ptemp, argc * sizeof(const char **));
- start_argv[0] = service_name;
+ start_argv[0] = mpm_service_name;
if (argc > 1)
memcpy(start_argv + 1, argv, (argc - 1) * sizeof(const char **));
@@ -1083,9 +1090,9 @@
/* Locate the active top level window named service_name
* provided the class is ApacheWin95ServiceMonitor
*/
- if (FindWindow("ApacheWin95ServiceMonitor", service_name)) {
+ if (FindWindow("ApacheWin95ServiceMonitor", mpm_service_name)) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL,
- "Service %s is already started!", display_name);
+ "Service %s is already started!", mpm_display_name);
return 0;
}
@@ -1105,7 +1112,7 @@
}
pCommand = apr_psprintf(ptemp, "\"%s\" -n %s -k runservice",
- exe_path, service_name);
+ exe_path, mpm_service_name);
for (i = 0; i < argc; ++i) {
pCommand = apr_pstrcat(ptemp, pCommand,
" \"", argv[i], "\"", NULL);
@@ -1124,7 +1131,7 @@
{
DWORD code;
while (GetExitCodeProcess(pi.hProcess, &code) == STILL_ACTIVE) {
- if (FindWindow("ApacheWin95ServiceMonitor", service_name)) {
+ if (FindWindow("ApacheWin95ServiceMonitor", mpm_service_name)) {
rv = APR_SUCCESS;
break;
}
@@ -1140,11 +1147,11 @@
}
if (rv == APR_SUCCESS)
- printf("The %s service is running.\n", display_name);
+ printf("The %s service is running.\n", mpm_display_name);
else
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
"%s: Failed to start the service process.",
- display_name);
+ mpm_display_name);
return rv;
}
@@ -1170,33 +1177,33 @@
return;
}
- schService = OpenService(schSCManager, service_name,
+ schService = OpenService(schSCManager, mpm_service_name,
SERVICE_ALL_ACCESS);
if (schService == NULL) {
/* Could not open the service */
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(), NULL,
- "Failed to open the %s Service", display_name);
+ "Failed to open the %s Service", mpm_display_name);
CloseServiceHandle(schSCManager);
return;
}
if (!QueryServiceStatus(schService, &globdat.ssStatus)) {
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(), NULL,
- "Query of Service %s failed", display_name);
+ "Query of Service %s failed", mpm_display_name);
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return;
}
if (!signal && (globdat.ssStatus.dwCurrentState == SERVICE_STOPPED)) {
- printf("The %s service is not started.\n", display_name);
+ printf("The %s service is not started.\n", mpm_display_name);
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return;
}
- printf("The %s service is %s.\n", display_name,
+ printf("The %s service is %s.\n", mpm_display_name,
signal ? "restarting" : "stopping");
if (!signal)
@@ -1227,19 +1234,19 @@
/* Locate the active top level window named service_name
* provided the class is ApacheWin95ServiceMonitor
*/
- hwnd = FindWindow("ApacheWin95ServiceMonitor", service_name);
+ hwnd = FindWindow("ApacheWin95ServiceMonitor", mpm_service_name);
if (hwnd && GetWindowThreadProcessId(hwnd, &service_pid))
globdat.ssStatus.dwCurrentState = SERVICE_RUNNING;
else
{
globdat.ssStatus.dwCurrentState = SERVICE_STOPPED;
if (!signal) {
- printf("The %s service is not started.\n", display_name);
+ printf("The %s service is not started.\n", mpm_display_name);
return;
}
}
- printf("The %s service is %s.\n", display_name,
+ printf("The %s service is %s.\n", mpm_display_name,
signal ? "restarting" : "stopping");
apr_snprintf(prefix, sizeof(prefix), "ap%ld", (long)service_pid);
@@ -1277,9 +1284,9 @@
}
if (success)
- printf("The %s service has %s.\n", display_name,
+ printf("The %s service has %s.\n", mpm_display_name,
signal ? "restarted" : "stopped");
else
printf("Failed to %s the %s service.\n",
- signal ? "restart" : "stop", display_name);
+ signal ? "restart" : "stop", mpm_display_name);
}