stoddard99/04/08 13:26:28
Modified:src/main http_main.c
src/os/win32 registry.c registry.h service.c service.h
Log:
Win32 multiple services patch. Documentation to follow.
Submitted by: Keith Wannamaker
Reviewed by: Bill Stoddard, Ken Parzygnat
Revision ChangesPath
1.428 +216 -66 apache-1.3/src/main/http_main.c
Index: http_main.c
===
RCS file: /export/home/cvs/apache-1.3/src/main/http_main.c,v
retrieving revision 1.427
retrieving revision 1.428
diff -u -r1.427 -r1.428
--- http_main.c 1999/03/17 23:05:43 1.427
+++ http_main.c 1999/04/08 20:26:24 1.428
@@ -180,6 +180,10 @@
#ifdef WIN32
#include "../os/win32/service.h"
#include "../os/win32/registry.h"
+#define DEFAULTSERVICENAME "Apache"
+#define PATHSEPARATOR '\\'
+#else
+#define PATHSEPARATOR '/'
#endif
@@ -984,6 +988,9 @@
#endif
fprintf(stderr, " %s [-C \"directive\"] [-c \"directive\"]\n",
pad);
fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t]\n", pad);
+#ifdef WIN32
+fprintf(stderr, " %s [-n service] [-k signal] [-i] [-u]\n", pad);
+#endif
fprintf(stderr, "Options:\n");
#ifdef SHARED_CORE
fprintf(stderr, " -R directory : specify an alternate location for
shared object files\n");
@@ -1001,8 +1008,12 @@
fprintf(stderr, " -S : show parsed settings (currently
only vhost settings)\n");
fprintf(stderr, " -t : run syntax test for configuration
files only\n");
#ifdef WIN32
+fprintf(stderr, " -n name : set service name and use its
ServerConfigFile\n");
fprintf(stderr, " -k shutdown : tell running Apache to
shutdown\n");
fprintf(stderr, " -k restart : tell running Apache to do a
graceful restart\n");
+fprintf(stderr, " -k start : tell Apache to start\n");
+fprintf(stderr, " -i : install an Apache service\n");
+fprintf(stderr, " -u : uninstall an Apache service\n");
#endif
exit(1);
}
@@ -3465,7 +3476,7 @@
* some of it is #ifdef'd but was duplicated before anyhow. This stuff
* is still a mess.
*/
-static void common_init(void)
+void common_init(void)
{
INIT_SIGLIST()
#ifdef AUX3
@@ -4485,7 +4496,7 @@
common_init();
-if ((s = strrchr(argv[0], '/')) != NULL) {
+if ((s = strrchr(argv[0], PATHSEPARATOR)) != NULL) {
ap_server_argv0 = ++s;
}
else {
@@ -5434,7 +5445,13 @@
{
char buf[40], mod[200];
int i, rv;
-char **pass_argv = (char **) alloca(sizeof(char *) * (argc + 3));
+
+#ifdef WIN32
+#define NUMCHILDARGS 4
+#else
+#define NUMCHILDARGS 2
+#endif
+char **pass_argv = (char **) alloca(sizeof(char *) * (argc +
NUMCHILDARGS + 1));
/* We need an event to tell the child process to kill itself when
* the parent is doing a shutdown/restart. This will be named
@@ -5456,10 +5473,14 @@
pass_argv[0] = argv[0];
pass_argv[1] = "-Z";
pass_argv[2] = buf;
+#ifdef WIN32
+pass_argv[3] = "-f";
+pass_argv[4] = ap_server_confname;
+#endif
for (i = 1; i < argc; i++) {
- pass_argv[i + 2] = argv[i];
+pass_argv[i + NUMCHILDARGS] = argv[i];
}
-pass_argv[argc + 2] = NULL;
+pass_argv[argc + NUMCHILDARGS] = NULL;
rv = GetModuleFileName(NULL, mod, sizeof(mod));
if (rv == sizeof(mod)) {
@@ -5533,8 +5554,47 @@
return 0;
}
+/* To share the semaphores with other processes, we need a NULL ACL
+ * Code from MS KB Q106387
+ */
+
+static PSECURITY_ATTRIBUTES GetNullACL()
+{
+PSECURITY_DESCRIPTOR pSD;
+PSECURITY_ATTRIBUTES sa;
+
+sa = (PSECURITY_ATTRIBUTES) LocalAlloc(LPTR, sizeof
(SECURITY_ATTRIBUTES));
+pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
+if (pSD == NULL || sa == NULL)
+return NULL;
+if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) {
+LocalFree( pSD );
+LocalFree( sa );
+return NULL;
+}
+if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)) {
+LocalFree( pSD );
+LocalFree( sa );
+return NULL;
+}
+sa->nLength = sizeof(sa);
+sa->lpSecurityDescriptor = pSD;
+sa->bInheritHandle = TRUE;
+return sa;
+}
+
+
+static void CleanNullACL( void *sa ) {
+if( sa ) {
+LocalFree( ((PSECURITY_ATTRIBUTES)sa)->lpSecurityDescriptor);
+LocalFree( sa );
+}
+}
+
int master_main(int argc, char **argv)
{
+/* returns NULL if invalid (Win95?) */
+PSECURITY_ATTRIBUTES sa = GetNullACL();
int nchild = ap_daemons_to_start;
event **ev;