httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r603238 - in /httpd/httpd/trunk: CHANGES support/win32/ApacheMonitor.c support/win32/ApacheMonitor.dsp support/win32/ApacheMonitor.h support/win32/ApacheMonitor.rc
Date Tue, 11 Dec 2007 13:32:41 GMT
Author: wrowe
Date: Tue Dec 11 05:32:40 2007
New Revision: 603238

URL: http://svn.apache.org/viewvc?rev=603238&view=rev
Log:
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.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/support/win32/ApacheMonitor.c
    httpd/httpd/trunk/support/win32/ApacheMonitor.dsp
    httpd/httpd/trunk/support/win32/ApacheMonitor.h
    httpd/httpd/trunk/support/win32/ApacheMonitor.rc

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=603238&r1=603237&r2=603238&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Dec 11 05:32:40 2007
@@ -2,6 +2,11 @@
 Changes with Apache 2.3.0
 [ When backported to 2.2.x, remove entry from this file ]
 
+  *) ApacheMonitor.exe: Introduce --kill argument for use by the
+     installer.  This will permit the installation tool to remove
+     all running instances before attempting to remove the .exe.
+     [William Rowe]
+
   *) mod_proxy: Lower memory consumption for short lived connections.
      PR 44026. [Ruediger Pluem]
 

Modified: httpd/httpd/trunk/support/win32/ApacheMonitor.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/win32/ApacheMonitor.c?rev=603238&r1=603237&r2=603238&view=diff
==============================================================================
--- httpd/httpd/trunk/support/win32/ApacheMonitor.c (original)
+++ httpd/httpd/trunk/support/win32/ApacheMonitor.c Tue Dec 11 05:32:40 2007
@@ -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 @@
 }
 
 
+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 @@
                             NULL, NULL, hInstance, NULL);
     }
     return hWnd;
-
 }
 
 
@@ -1686,6 +1760,12 @@
     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 @@
     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),
@@ -1724,16 +1819,6 @@
     g_hBmpStop         = LoadImage(hInstance, MAKEINTRESOURCE(IDB_BMPSTOP),
                                    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);

Modified: httpd/httpd/trunk/support/win32/ApacheMonitor.dsp
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/win32/ApacheMonitor.dsp?rev=603238&r1=603237&r2=603238&view=diff
==============================================================================
--- httpd/httpd/trunk/support/win32/ApacheMonitor.dsp (original)
+++ httpd/httpd/trunk/support/win32/ApacheMonitor.dsp Tue Dec 11 05:32:40 2007
@@ -52,8 +52,8 @@
 # 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 @@
 # 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)"

Modified: httpd/httpd/trunk/support/win32/ApacheMonitor.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/win32/ApacheMonitor.h?rev=603238&r1=603237&r2=603238&view=diff
==============================================================================
--- httpd/httpd/trunk/support/win32/ApacheMonitor.h (original)
+++ httpd/httpd/trunk/support/win32/ApacheMonitor.h Tue Dec 11 05:32:40 2007
@@ -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

Modified: httpd/httpd/trunk/support/win32/ApacheMonitor.rc
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/win32/ApacheMonitor.rc?rev=603238&r1=603237&r2=603238&view=diff
==============================================================================
--- httpd/httpd/trunk/support/win32/ApacheMonitor.rc (original)
+++ httpd/httpd/trunk/support/win32/ApacheMonitor.rc Tue Dec 11 05:32:40 2007
@@ -19,7 +19,6 @@
 #include "ApacheMonitor.h"
 
 #define LONG_NAME Apache HTTP Server Monitor
-#define BIN_NAME  ApacheMonitor.exe
 
 #include "../../build/win32/httpd.rc"
 



Mime
View raw message