Ok, I'm stumped. The bug is as follows, Apache 2.0 on Win32 lets us use Listen(s) that map to running web servers, such as IIS or even another instance of Apache. This is clearly boneheaded, but that's Win32. First a little bit of background.
To actually run apache -k install or -k start/restart, we always test the config. That means we run the server up to post_config, and then perform the action specified with the -k option. -k stop and -k uninstall take things in stride, they too run the same hooks, but pretty much deal with it at the pre_config or rewrite_args phase [don't remember which off hand, just contrasting here.] Now the core fix is trivial, setsockopt for SO_REUSEADDR only after we have called bind. This is safe, since the -child- process isn't running this code fragment, only our parent process. The child inherits those listeners through an mpm_winnt specific code path. And we might be able to to away with SO_REUSEADDR on Win32, but I'm not certain of that. But here's the rub; 1. Command line apache.exe -k start/restart creates/tests listeners 2. Command line apache.exe starts the 'service' process 3. Service apache.exe parent creates listeners - and fails. We have a few options to fix this, such as; 1. never try the listeners by testing if 'service' command options were given (start or restart) and perhaps even skip the listener setup when we install, since that prevents the user from even getting an Apache 2.0.x service to install using the .msi installer, if they already were running a server on the port. 2. move the listeners into pre_mpm (losing the 'listen is valid' test prior to installing the service, and losing the echo-to-console when the listeners are in-use.) 3. close the listeners in post-config if we are about to perform any 'service' -k command such as 'start'... but this still won't solve the 'service' -k restart, since the service is running and bound to the ports. So in reality, this needs to be a combination of the first options for the 'restart' case plus this third option for 'start'. That last oddity really bugs me. There is no way to test the Admin's reconfig of Listen directives before we restart. All other aspects of the server are tested before we let them actually attempt the restart [which generally prevents the admin from hosing their config and then taking down the running server.] So no pretty answers. Comments on the solutions above? I'll commit some fix around noon, so I'd really like some feedback first from our Win32 developer-users. Bill
