stoddard 99/12/17 13:04:58
Modified: src/os/win32 main_win32.c Log: Windows: Some more work to properly handle -k restart,shutdown. I have made a simplifying assumption that the relative name of the server pidfile is always logs/httpd.pid. This saves the error prone effort of reading the config file in apache.exe (as opposed to ApacheCore.dll). I am really working hard to keep Windows specific junk out of http_main.c. Revision Changes Path 1.3 +90 -141 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- main_win32.c 1999/12/08 22:34:09 1.2 +++ main_win32.c 1999/12/17 21:04:57 1.3 @@ -66,7 +66,8 @@ */ #include "httpd.h" -#include "http_config.h" /* ap_server_root_relative */ +#include "http_main.h" +#include "http_config.h" #include "apr_getopt.h" #include "service.h" #include "http_log.h" @@ -75,17 +76,7 @@ __declspec(dllexport) int apache_main(int argc, char *argv[]); #define DEFAULTSERVICENAME "Apache" -#if 0 -API_VAR_IMPORT int ap_optreset; -API_VAR_IMPORT char *ap_optarg; -API_VAR_IMPORT int ap_optind; -#endif -API_VAR_IMPORT char *ap_pid_fname; /* Need to read the config first */ -API_VAR_IMPORT char *ap_server_root; -API_VAR_IMPORT ap_array_header_t *ap_server_pre_read_config; -API_VAR_IMPORT ap_array_header_t *ap_server_post_read_config; -#if 0 -static int send_signal(ap_context_t *p, char *signal) +static int send_signal(const char *signal, const char *server_root, ap_context_t *p) { HANDLE event; char prefix[20]; @@ -97,8 +88,7 @@ printf("signal = %s\n", signal); - fname = ap_server_root_relative (p, ap_pid_fname); - + 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); @@ -130,8 +120,7 @@ event = OpenEvent(EVENT_ALL_ACCESS, FALSE, EventName); printf("event handle = %d\n", event); if (event == NULL) { - printf("Unknown signal name \"%s\". Use either shutdown or restart.\n", - signal); + printf("Unable to open event %s.\n", EventName); return FALSE; } SetEvent(event); @@ -139,62 +128,6 @@ CloseHandle(event); return TRUE; } -#else -static int send_signal(ap_context_t *p, char *signal) -{ - HANDLE event; - char prefix[20]; - char *EventName; - FILE *fp; - int nread; - char *fname; - int end; - - printf("signal = %s\n", signal); - - fname = "e:/apache/logs/httpd.pid"; - - 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("Unknown signal name \"%s\". Use either shutdown or restart.\n", - signal); - return FALSE; - } - SetEvent(event); - ResetEvent(event); - CloseHandle(event); - return TRUE; -} -#endif int service_init() { /* @@ -212,32 +145,52 @@ */ return TRUE; } -#if 0 -int main(int argc, char *argv[]) + +static void usage() { - return apache_main(argc, argv); + 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); } -#else + int main(int argc, char *argv[]) { ap_context_t *pwincmd; int c; char *ch; char *service_name = NULL; //DEFAULTSERVICENAME; - char *tmp_server_root = NULL; char *signal_to_send = NULL; - char *server_confname = NULL; + char *server_root = NULL; + char *server_confname = SERVER_CONFIG_FILE; + char *temp_server_confname = NULL; char cwd[MAX_STRING_LEN]; char **new; BOOLEAN install = FALSE; BOOLEAN uninstall = FALSE; - BOOLEAN k = FALSE; - BOOLEAN n = FALSE; - BOOLEAN d = FALSE; - BOOLEAN f = FALSE; - ap_array_header_t *table; + ap_array_header_t *cmdtbl; int new_argc = 0; ap_create_context(&pwincmd, NULL); @@ -246,17 +199,17 @@ exit(0); } - /* Set up default ap_server_root (do we need HTTPD_ROOT? I think not...) */ + /* Set up default server_root */ if (!GetCurrentDirectory(sizeof(cwd),cwd)) { ap_log_error(APLOG_MARK,APLOG_ERR, GetLastError(), NULL, "GetCurrentDirectory() failure"); exit(0); } - ap_server_root = ap_os_canonical_filename(pwincmd, cwd); + server_root = ap_os_canonical_filename(pwincmd, cwd); - table = ap_make_array(pwincmd, 1, sizeof(char *)); + cmdtbl = ap_make_array(pwincmd, 1, sizeof(char *)); /* Add the new_argv[0] */ - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = argv[0]; new_argc++; @@ -272,20 +225,20 @@ int i; ap_registry_get_service_conf(pwincmd, &server_confname, argv[0]); for (i = 0; i < argc ; i++) { - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = argv[i]; } /* Add server_confname to the argument list */ - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = "-f"; - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = server_confname; - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = "-d"; - new = (char **) ap_push_array(table); - *new = ap_server_root; + new = (char **) ap_push_array(cmdtbl); + *new = server_root; argc += 4; - apache_main(new_argc, (char**) table->elts); + apache_main(new_argc, (char**) cmdtbl->elts); exit(0); } @@ -309,58 +262,67 @@ break; case 'f': server_confname = ap_optarg; - f = TRUE; break; case 'd': - ap_server_root = ap_optarg; - d = TRUE; + server_root = ap_os_canonical_filename(pwincmd, ap_optarg); + break; + case 'h': + usage(); break; + case '?': + usage(); + break; default: - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); ch = ap_pstrndup(pwincmd, (char*)&c, 1); *new = ap_pstrcat(pwincmd,"-", ch, NULL); new_argc++; if (ap_optarg) { - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = ap_optarg; new_argc++; } break; } } - - /* Check for conflicting options */ - /* Determine ap_server_confname. - * ap_server_confname is found in this order: + /* Determine server_confname. + * server_confname is found in this order: * (1) -f or -n * (2) [-d]/SERVER_CONFIG_FILE * (3) ./SERVER_CONFIG_FILE * (4) [Registry: HKLM\Software\[product]\ServerRoot]/SERVER_CONFIG_FILE * (5) /HTTPD_ROOT/SERVER_CONFIG_FILE (Humm, I don't think we should even try this... ) */ - if (!server_confname) { - server_confname = ap_pstrdup(pwincmd, SERVER_CONFIG_FILE); - if (access(ap_server_root_relative(pwincmd, server_confname), 0)) { - ap_registry_get_server_root(pwincmd, &tmp_server_root); - if (tmp_server_root) - ap_server_root = ap_pstrdup(pwincmd, ap_os_canonical_filename(pwincmd, tmp_server_root)); - else { - /* use default server_root */ - } + temp_server_confname = ap_pstrdup(pwincmd, server_confname); + if (!ap_os_is_path_absolute(temp_server_confname)) { + temp_server_confname = ap_make_full_path(pwincmd, server_root, temp_server_confname); + } + temp_server_confname = ap_os_canonical_filename(pwincmd, temp_server_confname); + ap_getparents(temp_server_confname); + ap_no2slash(temp_server_confname); + + if (access(temp_server_confname, 0)) { + ap_registry_get_server_root(pwincmd, &server_root); + if (!server_root) { + server_root = HTTPD_ROOT; } - } + server_root = ap_os_canonical_filename(pwincmd, server_root); - /* Canonicalize the server_confname */ - if (!ap_os_is_path_absolute(server_confname)) { - char *full_conf_path; - full_conf_path = ap_pstrcat(pwincmd, ap_server_root, "/", server_confname, NULL); - full_conf_path = ap_os_canonical_filename(pwincmd, full_conf_path); - server_confname = full_conf_path; + temp_server_confname = ap_pstrdup(pwincmd, server_confname); + if (!ap_os_is_path_absolute(temp_server_confname)) { + temp_server_confname = ap_make_full_path(pwincmd, server_root, temp_server_confname); + } + temp_server_confname = ap_os_canonical_filename(pwincmd, temp_server_confname); + ap_getparents(temp_server_confname); + ap_no2slash(temp_server_confname); } - ap_getparents(server_confname); - ap_no2slash(server_confname); + server_confname = temp_server_confname; + + /* By now, we should have canonicalized absolute paths to + * server_root and server_confname */ + /* Handle -i (install as a service) */ if (install) { if (!service_name) @@ -385,19 +347,7 @@ /* Handle -k restart|shutdown */ if (signal_to_send && strcasecmp(signal_to_send, "start")) { /* Treat -k start confpath as just -f confpath */ -#if 0 - server_rec *server_conf; - process_rec process; - process.pool = pwincmd; - process.pconf = pwincmd; - process.argc = argc; - process.argv = argv; - ap_setup_prelinked_modules(&process); - ap_server_pre_read_config = ap_make_array(pwincmd, 1, sizeof(char *)); - ap_server_post_read_config = ap_make_array(pwincmd, 1, sizeof(char *)); - server_conf = ap_read_config(&process, pwincmd, server_confname); -#endif - send_signal(pwincmd, signal_to_send); + send_signal(signal_to_send, server_root, pwincmd); exit(0); } @@ -405,14 +355,14 @@ * -f server_conf * -d server_root */ - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = "-f"; - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = server_confname; - new = (char **) ap_push_array(table); + new = (char **) ap_push_array(cmdtbl); *new = "-d"; - new = (char **) ap_push_array(table); - *new = ap_server_root; + new = (char **) ap_push_array(cmdtbl); + *new = server_root; new_argc += 4; /* Set optreset and optind to allow ap_getopt to work correctly @@ -421,7 +371,7 @@ ap_optreset = 1; ap_optind = 1; - return apache_main(new_argc, (char**) table->elts); + return apache_main(new_argc, (char**) cmdtbl->elts); /* What is this? */ /* Console application or a child process. */ @@ -434,4 +384,3 @@ } #endif } -#endif