}
-#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...
*/
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)
{
* 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];
/* 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:
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;
* 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);
}
}
&& (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);
}
{
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);
}
}
#undef _WINUSER_
#include <winuser.h>
-static const char * service_name = NULL;
-
-/* ### should be namespace-protected */
-const char * display_name = NULL;
+static char *mpm_service_name = NULL;
+static char *mpm_display_name = NULL;
static struct
{
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";
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;
}
-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;
}
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
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)...
}
-apr_status_t mpm_service_to_start(void)
+apr_status_t mpm_service_to_start(const char **display_name)
{
HANDLE waitfor[2];
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);
}
else if (globdat.service_thread)
CloseHandle(globdat.service_thread);
+ *display_name = mpm_display_name;
return APR_SUCCESS;
}
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)
{
* 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
{
/* 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);
}
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 */
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);
}
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);
}
}
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;
}
{
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)
{
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);
}
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;
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 **));
/* 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;
}
}
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);
{
DWORD code;
while (GetExitCodeProcess(pi.hProcess, &code) == STILL_ACTIVE) {
- if (FindWindow("ApacheWin95ServiceMonitor", service_name)) {
+ if (FindWindow("ApacheWin95ServiceMonitor", mpm_service_name)) {
rv = APR_SUCCESS;
break;
}
}
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;
}
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)
/* 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);
}
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);
}