summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorWilliam A. Rowe Jr <wrowe@apache.org>2007-12-11 13:32:40 +0000
committerWilliam A. Rowe Jr <wrowe@apache.org>2007-12-11 13:32:40 +0000
commitb99945ec40082848f165df81b61a29f62d5328c0 (patch)
tree8dfa8ca9dbaa237a992811e09284a05dec689713 /support
parent0ae93ad6f9bd3cea1ec0ff506279e685fb25dc23 (diff)
downloadhttpd-b99945ec40082848f165df81b61a29f62d5328c0.tar.gz
Introduce --kill argument to ApacheMonitor for use by the
installer. This will permit the installation tool to remove all running instances before attempting to remove the .exe. Note that since the introduction of CriticalSections, our compatibility with NT 4 was destroyed, and at this point that is no loss (there are no more security updates to NT 4 ergo it's not an OS we want connected to the internet, anyways). The WTS api calls require 2000 or later, but I'm not wrapping them since nobody notices the same issue with CriticalSections. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@603238 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'support')
-rw-r--r--support/win32/ApacheMonitor.c121
-rw-r--r--support/win32/ApacheMonitor.dsp8
-rw-r--r--support/win32/ApacheMonitor.h1
-rw-r--r--support/win32/ApacheMonitor.rc1
4 files changed, 108 insertions, 23 deletions
diff --git a/support/win32/ApacheMonitor.c b/support/win32/ApacheMonitor.c
index 128d9cc287..296da05423 100644
--- a/support/win32/ApacheMonitor.c
+++ b/support/win32/ApacheMonitor.c
@@ -23,7 +23,7 @@
* ====================================================================
*/
-#define _WIN32_WINNT 0x0400
+#define _WIN32_WINNT 0x0500
#ifndef STRICT
#define STRICT
#endif
@@ -43,8 +43,15 @@
#include <shlobj.h>
#include <stdlib.h>
#include <stdio.h>
+#include <WtsApi32.h>
#include "ApacheMonitor.h"
+#ifndef AM_STRINGIFY
+/** Properly quote a value as a string in the C preprocessor */
+#define AM_STRINGIFY(n) AM_STRINGIFY_HELPER(n)
+/** Helper macro for AM_STRINGIFY */
+#define AM_STRINGIFY_HELPER(n) #n
+#endif
#define OS_VERSION_WIN9X 1
#define OS_VERSION_WINNT 2
@@ -1637,18 +1644,86 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
}
+static int KillAWindow(HWND appwindow)
+{
+ HANDLE appproc;
+ DWORD procid;
+ BOOL postres;
+
+ SetLastError(0);
+ GetWindowThreadProcessId(appwindow, &procid);
+ if (GetLastError())
+ return(2);
+
+ appproc = OpenProcess(SYNCHRONIZE, 0, procid);
+ postres = PostMessage(appwindow, WM_COMMAND, IDM_EXIT, 0);
+ if (appproc && postres) {
+ if (WaitForSingleObject(appproc, 10 /* seconds */ * 1000)
+ == WAIT_OBJECT_0) {
+ CloseHandle(appproc);
+ return (0);
+ }
+ }
+ if (appproc)
+ CloseHandle(appproc);
+
+ if ((appproc = OpenProcess(PROCESS_TERMINATE, 0, procid)) != NULL) {
+ if (TerminateProcess(appproc, 0)) {
+ CloseHandle(appproc);
+ return (0);
+ }
+ CloseHandle(appproc);
+ }
+
+ /* Perhaps we were short of permissions? */
+ return (2);
+}
+
+
+static int KillAllMonitors(void)
+{
+ HWND appwindow;
+ int exitcode = 0;
+ PWTS_PROCESS_INFO tsProcs;
+ DWORD tsProcCount, i;
+ DWORD thisProcId;
+
+ /* This is graceful, close our own Window, clearing the icon */
+ if ((appwindow = FindWindow(g_szWindowClass, g_szTitle)) != NULL)
+ exitcode = KillAWindow(appwindow);
+
+ if (g_dwOSVersion < OS_VERSION_WIN2K)
+ return exitcode;
+
+ thisProcId = GetCurrentProcessId();
+
+ if (!WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1,
+ &tsProcs, &tsProcCount))
+ return exitcode;
+
+ /* This is ungraceful; close other Windows, with a lingering icon.
+ * Since on terminal server it's not possible to post the message
+ * to exit across sessions, we have to suffer this side effect
+ * of a taskbar 'icon' which will evaporate the next time that
+ * the user hovers over it or when the taskbar area is updated.
+ */
+ for (i = 0; i < tsProcCount; ++i) {
+ if (strcmp(tsProcs[i].pProcessName, AM_STRINGIFY(BIN_NAME)) == 0
+ && tsProcs[i].ProcessId != thisProcId)
+ WTSTerminateProcess(WTS_CURRENT_SERVER_HANDLE,
+ tsProcs[i].ProcessId, 1);
+ }
+ WTSFreeMemory(tsProcs);
+ return exitcode;
+}
+
+
/* Create main invisible window */
HWND CreateMainWindow(HINSTANCE hInstance)
{
HWND hWnd = NULL;
WNDCLASSEX wcex;
- if (!GetSystemOSVersion(&g_dwOSVersion))
- {
- ErrorMessage(NULL, TRUE);
- return hWnd;
- }
-
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
@@ -1671,7 +1746,6 @@ HWND CreateMainWindow(HINSTANCE hInstance)
NULL, NULL, hInstance, NULL);
}
return hWnd;
-
}
@@ -1686,6 +1760,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
int i;
DWORD d;
+ if (!GetSystemOSVersion(&g_dwOSVersion))
+ {
+ ErrorMessage(NULL, TRUE);
+ return 1;
+ }
+
g_LangID = GetUserDefaultLangID();
if ((g_LangID & 0xFF) != LANG_ENGLISH) {
g_LangID = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
@@ -1708,6 +1788,21 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LoadString(hInstance, IDS_APMONITORCLASS, szTmp, MAX_LOADSTRING);
g_szWindowClass = strdup(szTmp);
+ if (strstr(lpCmdLine, "--kill") != NULL) {
+ /* Off to chase and close up every ApacheMonitor taskbar window */
+ return KillAllMonitors();
+ }
+
+ hMutex = CreateMutex(NULL, FALSE, "APSRVMON_MUTEX");
+ if ((hMutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS))
+ {
+ ErrorMessage(g_lpMsg[IDS_MSG_APPRUNNING - IDS_MSG_FIRST], FALSE);
+ if (hMutex) {
+ CloseHandle(hMutex);
+ }
+ return 0;
+ }
+
g_icoStop = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICOSTOP),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
g_icoRun = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICORUN),
@@ -1725,16 +1820,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
IMAGE_BITMAP, XBITMAP, YBITMAP,
LR_DEFAULTCOLOR);
- hMutex = CreateMutex(NULL, FALSE, "APSRVMON_MUTEX");
- if ((hMutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS))
- {
- ErrorMessage(g_lpMsg[IDS_MSG_APPRUNNING - IDS_MSG_FIRST], FALSE);
- if (hMutex) {
- CloseHandle(hMutex);
- }
- return 0;
- }
-
memset(g_stServices, 0, sizeof(ST_APACHE_SERVICE) * MAX_APACHE_SERVICES);
CoInitialize(NULL);
InitCommonControls();
diff --git a/support/win32/ApacheMonitor.dsp b/support/win32/ApacheMonitor.dsp
index 853ddbc60c..84369aaa72 100644
--- a/support/win32/ApacheMonitor.dsp
+++ b/support/win32/ApacheMonitor.dsp
@@ -52,8 +52,8 @@ BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib /nologo /subsystem:windows
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib /nologo /subsystem:windows /debug /opt:ref
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib wtsapi32.lib /nologo /subsystem:windows
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib wtsapi32.lib /nologo /subsystem:windows /debug /opt:ref
# Begin Special Build Tool
TargetPath=.\Release\ApacheMonitor.exe
SOURCE="$(InputPath)"
@@ -84,8 +84,8 @@ BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib /nologo /subsystem:windows /debug
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib /nologo /subsystem:windows /incremental:no /debug
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib wtsapi32.lib /nologo /subsystem:windows /debug
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib wtsapi32.lib /nologo /subsystem:windows /incremental:no /debug
# Begin Special Build Tool
TargetPath=.\Debug\ApacheMonitor.exe
SOURCE="$(InputPath)"
diff --git a/support/win32/ApacheMonitor.h b/support/win32/ApacheMonitor.h
index 8a64b8704b..085c45f8dd 100644
--- a/support/win32/ApacheMonitor.h
+++ b/support/win32/ApacheMonitor.h
@@ -18,6 +18,7 @@
* @file ApacheMonitor.h
* @brief Resource definitions for ApacheMonitor.rc and ApacheMonitor.c
*/
+#define BIN_NAME ApacheMonitor.exe
#define IDD_DLGSERVICES 101
#define IDS_APMONITORTITLE 102
diff --git a/support/win32/ApacheMonitor.rc b/support/win32/ApacheMonitor.rc
index 4e44a2939b..3d675ff14d 100644
--- a/support/win32/ApacheMonitor.rc
+++ b/support/win32/ApacheMonitor.rc
@@ -19,7 +19,6 @@
#include "ApacheMonitor.h"
#define LONG_NAME Apache HTTP Server Monitor
-#define BIN_NAME ApacheMonitor.exe
#include "../../build/win32/httpd.rc"