stoddard 99/12/20 11:07:36
Modified: src/main http_main.c
src/include ap_mpm.h
src/os/win32 main_win32.c
src/modules/mpm/winnt winnt.c
Log:
Handle -k restart|shutdown command line option from http_main.c
Revision Changes Path
1.24 +31 -2 apache-2.0/src/main/http_main.c
Index: http_main.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_main.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- http_main.c 1999/12/01 01:16:11 1.23
+++ http_main.c 1999/12/20 19:07:22 1.24
@@ -66,7 +66,8 @@
const char *ap_server_argv0;
-API_VAR_EXPORT const char *ap_server_root;
+//API_VAR_IMPORT const char *ap_server_root;
+const char *ap_server_root;
ap_array_header_t *ap_server_pre_read_config;
ap_array_header_t *ap_server_post_read_config;
@@ -236,6 +237,11 @@
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Usage:
%s [-D name] [-d directory] [-f file]", bin);
#endif
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "
%s [-C \"directive\"] [-c \"directive\"]", pad);
+#ifdef WIN32
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "
%s [-k restart|shutdown|start]", pad);
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "
%s [-n service_name]", pad);
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "
%s [-i] [-u]", pad);
+#endif
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "
%s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]", pad);
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"Options:");
#ifdef SHARED_CORE
@@ -246,6 +252,14 @@
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -f
file : specify an alternate ServerConfigFile");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -C
\"directive\" : process directive before reading config files");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -c
\"directive\" : process directive after reading config files");
+#ifdef WIN32
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -n
name : set service name and use its ServerConfigFile");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k
shutdown : tell running Apache to shutdown");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k
restart : tell running Apache to do a graceful restart");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k
start : tell Apache to start");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -i
: install an Apache service");
+ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -u
: uninstall an Apache service");
+#endif
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -v
: show version number");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -V
: show compile settings");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -h
: list available command line options (this page)");
@@ -283,6 +297,10 @@
ap_context_t *ptemp; /* Pool for temporary config stuff, reset often */
ap_context_t *pcommands; /* Pool for -C and -c switches */
+#ifdef WIN32
+ char *signal = NULL;
+#endif
+
ap_server_argv0 = process->short_name;
ap_util_uri_init();
@@ -296,7 +314,7 @@
ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
ap_server_config_defines = ap_make_array(pcommands, 1, sizeof(char *));
- while (ap_getopt(pcommands, argc, argv, "C:c:d:f:vVlLth", &c) ==
APR_SUCCESS) {
+ while (ap_getopt(pcommands, argc, argv, "C:c:d:f:k:vVlLth", &c) ==
APR_SUCCESS) {
char **new;
switch (c) {
case 'c':
@@ -313,6 +331,11 @@
case 'f':
confname = ap_optarg;
break;
+#ifdef WIN32
+ case 'k':
+ signal = ap_optarg;
+ break;
+#endif
case 'v':
printf("Server version: %s\n", ap_get_server_version());
printf("Server built: %s\n", ap_get_server_built());
@@ -351,6 +374,12 @@
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"Syntax OK\n");
destroy_and_exit_process(process, 0);
}
+#ifdef WIN32
+ if (signal) {
+ ap_signal_parent(pconf, signal, ap_server_root);
+ destroy_and_exit_process(process, 0);
+ }
+#endif
ap_clear_pool(plog);
ap_run_open_logs(pconf, plog, ptemp, server_conf);
ap_post_config_hook(pconf, plog, ptemp, server_conf);
1.8 +5 -0 apache-2.0/src/include/ap_mpm.h
Index: ap_mpm.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/ap_mpm.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ap_mpm.h 1999/12/13 22:53:07 1.7
+++ ap_mpm.h 1999/12/20 19:07:23 1.8
@@ -128,6 +128,11 @@
void ap_start_shutdown(void);
void ap_start_restart(int graceful);
+/*
+ * ap_signal_parent() - used to send a signal to the parent process.
+ */
+void ap_signal_parent(ap_context_t *p, const char* signal, const char*
server_root);
+
#ifdef HAS_OTHER_CHILD
/*
* register an other_child -- a child which the main loop keeps track of
1.4 +13 -126 apache-2.0/src/os/win32/main_win32.c
Index: main_win32.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/os/win32/main_win32.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- main_win32.c 1999/12/17 21:04:57 1.3
+++ main_win32.c 1999/12/20 19:07:31 1.4
@@ -76,111 +76,13 @@
__declspec(dllexport) int apache_main(int argc, char *argv[]);
#define DEFAULTSERVICENAME "Apache"
-static int send_signal(const char *signal, const char *server_root,
ap_context_t *p)
-{
- HANDLE event;
- char prefix[20];
- char *EventName;
- FILE *fp;
- int nread;
- char *fname;
- int end;
-
- printf("signal = %s\n", signal);
-
- fname = ap_make_full_path(p, server_root, DEFAULT_PIDLOG);
- fp = fopen(fname, "r");
- if (!fp) {
- printf("Cannot read apache PID file %s. Error = %d\n", fname, errno);
- return FALSE;
- }
- prefix[0] = 'a';
- prefix[1] = 'p';
-
- nread = fread(prefix+2, 1, sizeof(prefix)-3, fp);
- if (nread == 0) {
- fclose(fp);
- printf("PID file %s was empty\n", fname);
- return FALSE;
- }
- fclose(fp);
-
- /* Terminate the prefix string */
- end = 2 + nread - 1;
- while (end > 0 && (prefix[end] == '\r' || prefix[end] == '\n'))
- end--;
- prefix[end + 1] = '\0';
-
- /* Build the event name. Should be one of the following...
- * apPID_shutdown
- * apPID_restart
- */
- EventName = ap_pstrcat(p,prefix,"_",signal,NULL);
- printf("event name = %s\n", EventName);
- event = OpenEvent(EVENT_ALL_ACCESS, FALSE, EventName);
- printf("event handle = %d\n", event);
- if (event == NULL) {
- printf("Unable to open event %s.\n", EventName);
- return FALSE;
- }
- SetEvent(event);
- ResetEvent(event);
- CloseHandle(event);
- return TRUE;
-}
-int service_init()
-{
-/*
- common_init();
-
- ap_cpystrn(ap_server_root, HTTPD_ROOT, sizeof(ap_server_root));
- if (ap_registry_get_service_conf(pconf, ap_server_confname,
sizeof(ap_server_confname),
- ap_server_argv0))
- return FALSE;
-
- ap_setup_prelinked_modules();
- server_conf = ap_read_config(pconf, ptrans, ap_server_confname);
- ap_log_pid(pconf, ap_pid_fname);
- post_parse_init();
-*/
- return TRUE;
-}
-
-static void usage()
-{
- const char *bin = "apache";
- char pad[MAX_STRING_LEN];
- unsigned i;
-
- for (i = 0; i < strlen(bin); i++)
- pad[i] = ' ';
- pad[i] = '\0';
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Usage:
%s [-D name] [-d directory] [-f file]", bin);
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "
%s [-C \"directive\"] [-c \"directive\"]", pad);
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "
%s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]", pad);
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"Options:");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -D
name : define a name for use in <IfDefine name> directives");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -d
directory : specify an alternate initial ServerRoot");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -f
file : specify an alternate ServerConfigFile");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -C
\"directive\" : process directive before reading config files");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -c
\"directive\" : process directive after reading config files");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -v
: show version number");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -V
: show compile settings");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -h
: list available command line options (this page)");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -l
: list compiled in modules");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -L
: list available configuration directives");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -t
: run syntax check for config files (with docroot check)");
- ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -T
: run syntax check for config files (without docroot check)");
- exit(0);
-}
-
int main(int argc, char *argv[])
{
ap_context_t *pwincmd;
int c;
char *ch;
char *service_name = NULL; //DEFAULTSERVICENAME;
- char *signal_to_send = NULL;
+ char *signal = NULL;
char *server_root = NULL;
char *server_confname = SERVER_CONFIG_FILE;
char *temp_server_confname = NULL;
@@ -195,7 +97,6 @@
ap_create_context(&pwincmd, NULL);
if (pwincmd == NULL) {
-// printf(stderr,"");
exit(0);
}
@@ -238,15 +139,15 @@
new = (char **) ap_push_array(cmdtbl);
*new = server_root;
argc += 4;
- apache_main(new_argc, (char**) cmdtbl->elts);
+ service_main(apache_main, new_argc, (char**) cmdtbl->elts);
exit(0);
}
/* Munch away at the command line arguments... */
- while (ap_getopt(pwincmd, argc, argv, "n:k:iuC:c:d:f:vVlLth", &c) ==
APR_SUCCESS) {
+ while (ap_getopt(pwincmd, argc, argv, "n:k:iuC:c:d:f:vVlLth?", &c) ==
APR_SUCCESS) {
switch (c) {
case 'k':
- signal_to_send = ap_pstrdup(pwincmd, ap_optarg);
+ signal = ap_optarg;
break;
case 'i':
install = TRUE;
@@ -266,12 +167,6 @@
case 'd':
server_root = ap_os_canonical_filename(pwincmd, ap_optarg);
break;
- case 'h':
- usage();
- break;
- case '?':
- usage();
- break;
default:
new = (char **) ap_push_array(cmdtbl);
ch = ap_pstrndup(pwincmd, (char*)&c, 1);
@@ -339,16 +234,18 @@
}
/* Handle -k <signal> -n <service_name> */
- if (service_name && signal_to_send) {
- send_signal_to_service(service_name, signal_to_send);
+ if (service_name && signal) {
+ send_signal_to_service(service_name, signal);
exit(0);
}
- /* Handle -k restart|shutdown */
- if (signal_to_send && strcasecmp(signal_to_send, "start")) {
- /* Treat -k start confpath as just -f confpath */
- send_signal(signal_to_send, server_root, pwincmd);
- exit(0);
+ /* Let http_main handle -k restart|shutdown */
+ if (signal && strcasecmp(signal, "start")) {
+ new = (char **) ap_push_array(cmdtbl);
+ *new = "-k";
+ new = (char **) ap_push_array(cmdtbl);
+ *new = signal;
+ new_argc += 2;
}
/* Complete building the new argv list. Need to add:
@@ -373,14 +270,4 @@
return apache_main(new_argc, (char**) cmdtbl->elts);
-/* What is this? */
- /* Console application or a child process. */
-#if 0
- if ((s = strrchr(argv[0], PATHSEPARATOR)) != NULL) {
- ap_server_argv0 = ++s;
- }
- else {
- ap_server_argv0 = argv[0];
- }
-#endif
}
1.34 +85 -10 apache-2.0/src/modules/mpm/winnt/winnt.c
Index: winnt.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/modules/mpm/winnt/winnt.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- winnt.c 1999/12/09 21:50:16 1.33
+++ winnt.c 1999/12/20 19:07:33 1.34
@@ -75,7 +75,7 @@
* Definitions of WINNT MPM specific config globals
*/
-char *ap_pid_fname=NULL;
+static char *ap_pid_fname = NULL;
static int ap_threads_per_child = 0;
static int workers_may_exit = 0;
static int max_requests_per_child = 0;
@@ -349,6 +349,61 @@
{
signal_parent(0);
}
+
+void ap_signal_parent(ap_context_t *p, const char* signal,
+ const char* server_root)
+{
+ HANDLE event;
+ char prefix[20];
+ char *EventName;
+ FILE *fp;
+ int nread;
+ char *fname;
+ int end;
+
+ printf("signal = %s\n", signal);
+
+ fname = ap_server_root_relative (p, ap_pid_fname);
+
+ fp = fopen(fname, "r");
+ if (!fp) {
+ printf("Cannot read apache PID file %s. Error = %d\n", fname, errno);
+ return;
+ }
+ prefix[0] = 'a';
+ prefix[1] = 'p';
+
+ nread = fread(prefix+2, 1, sizeof(prefix)-3, fp);
+ if (nread == 0) {
+ fclose(fp);
+ printf("PID file %s was empty\n", fname);
+ return;
+ }
+ fclose(fp);
+
+ /* Terminate the prefix string */
+ end = 2 + nread - 1;
+ while (end > 0 && (prefix[end] == '\r' || prefix[end] == '\n'))
+ end--;
+ prefix[end + 1] = '\0';
+
+ /* Build the event name. Should be one of the following...
+ * apPID_shutdown
+ * apPID_restart
+ */
+ EventName = ap_pstrcat(p,prefix,"_",signal,NULL);
+ printf("event name = %s\n", EventName);
+ event = OpenEvent(EVENT_ALL_ACCESS, FALSE, EventName);
+ printf("event handle = %d\n", event);
+ if (event == NULL) {
+ printf("Unable to open event %s.\n", EventName);
+ return;
+ }
+ SetEvent(event);
+ ResetEvent(event);
+ CloseHandle(event);
+ return;
+}
/*
* Initialise the signal names, in the global variables signal_name_prefix,
* signal_restart_name and signal_shutdown_name.
@@ -1321,7 +1376,7 @@
int rv;
char buf[1024];
char *pCommand;
-
+ int i;
STARTUPINFO si; /* Filled in prior to call to CreateProcess */
PROCESS_INFORMATION pi; /* filled in on call to CreateProces */
@@ -1363,8 +1418,11 @@
return -1;
}
- //pCommand = ap_psprintf(p, "\"%s\" -f \"%s\"", buf,
ap_server_confname);
- pCommand = ap_psprintf(p, "\"%s\" -f \"%s\"", buf, SERVER_CONFIG_FILE);
+ /* Build the command line */
+ pCommand = ap_psprintf(p, "\"%s\"", buf);
+ for (i = 1; i < server_conf->process->argc; i++) {
+ pCommand = ap_pstrcat(p, pCommand, " \"",
server_conf->process->argv[i], "\"", NULL);
+ }
/* Create a pipe to send socket info to the child */
if (!CreatePipe(&hPipeRead, &hPipeWrite, &sa, 0)) {
@@ -1497,6 +1555,11 @@
/* Create child process
* Should only be one in this version of Apache for WIN32
*/
+#if 1
+// ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_START_PENDING);
+#endif
while (remaining_children_to_start--) {
if (create_process(pconf, process_handles, process_kill_events,
¤t_live_processes) < 0) {
@@ -1506,8 +1569,11 @@
goto die_now;
}
}
-
- /* service_set_status(SERVICE_RUNNING);*/
+#if 1
+// ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_RUNNING);
+#endif
restart_pending = shutdown_pending = 0;
/* Wait for shutdown or restart events or for child death */
@@ -1640,7 +1706,7 @@
else {
/* This is the parent */
parent_pid = my_pid = getpid();
- ap_log_pid(pconf, ap_pid_fname);
+
}
ap_listen_pre_config();
@@ -1700,9 +1766,14 @@
ap_clear_pool(plog);
ap_open_logs(server_conf, plog);
- setup_signal_names(ap_psprintf(pconf,"ap%d", parent_pid));
+ setup_signal_names(ap_psprintf(pconf,"ap%d", parent_pid));
if (!restart) {
- /* service_set_status(SERVICE_START_PENDING);*/
+ ap_log_pid(pconf, ap_pid_fname);
+#if 1
+// ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_START_PENDING);
+#endif
AMCSocketInitialize();
// setup_signal_names(ap_psprintf(pconf,"ap%d", parent_pid));
@@ -1756,7 +1827,11 @@
CloseHandle(restart_event);
CloseHandle(shutdown_event);
AMCSocketCleanup();
- /* service_set_status(SERVICE_STOPPED); */
+#if 1
+// ReportStatusToSCMgr(SERVICE_STOPPED, NO_ERROR, 3000);
+#else
+// service_set_status(SERVICE_STOPPED);
+#endif
}
}
return !restart;