ApacheMonitor.c revision 3b09d2d26bf54dd6ace995ef14cf66cd0d83c4e1
f43ed9051a7f4db461d67ed4f7ece175b3dbca7cjerenkrantz/* Licensed to the Apache Software Foundation (ASF) under one or more
f43ed9051a7f4db461d67ed4f7ece175b3dbca7cjerenkrantz * contributor license agreements. See the NOTICE file distributed with
f43ed9051a7f4db461d67ed4f7ece175b3dbca7cjerenkrantz * this work for additional information regarding copyright ownership.
f43ed9051a7f4db461d67ed4f7ece175b3dbca7cjerenkrantz * The ASF licenses this file to You under the Apache License, Version 2.0
f43ed9051a7f4db461d67ed4f7ece175b3dbca7cjerenkrantz * (the "License"); you may not use this file except in compliance with
f43ed9051a7f4db461d67ed4f7ece175b3dbca7cjerenkrantz * the License. You may obtain a copy of the License at
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd * Unless required by applicable law or agreed to in writing, software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd/* ====================================================================
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen * ApacheMonitor.c Simple program to manage and monitor Apache services.
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd * Contributed by Mladen Turk <mturk mappingsoft.com>
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd * 05 Aug 2001
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * ====================================================================
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh/** Properly quote a value as a string in the C preprocessor */
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd/** Helper macro for AM_STRINGIFY */
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd/* Should be enough */
f43ed9051a7f4db461d67ed4f7ece175b3dbca7cjerenkrantz#define RESCAN_TIME 20000 /* registry rescan time (ms) */
aa0b2780958e9b1467c9d0153a05738e399811a5ndtypedef struct _st_APACHE_SERVICE
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh/* Global variables */
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohST_APACHE_SERVICE g_stServices[MAX_APACHE_SERVICES];
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohST_MONITORED_COMP g_stComputers[MAX_APACHE_COMPUTERS];
void am_ClearServicesSt()
for (i = 0; i < MAX_APACHE_SERVICES; i++)
void am_ClearComputersSt()
for (i = 0; i < MAX_APACHE_COMPUTERS; i++) {
return TRUE;
return FALSE;
if (szError) {
if (bFatal) {
PostQuitMessage(0);
return FALSE;
return FALSE;
!= ERROR_SUCCESS) {
return FALSE;
return TRUE;
buffer[0] = 0;
return buffer;
return FALSE;
case VER_PLATFORM_WIN32_NT:
case VER_PLATFORM_WIN32s:
*dwVersion = 0;
return FALSE;
return TRUE;
if (fDefault) {
if (!fEnabled) {
if (hMenu)
if (hMenu)
&rWorkArea, 0);
if (!bResult) {
static int nItems = 0;
if (!g_bDlgServiceOn) {
++nItems;
int nPtr = 0;
if (dwReaded > 0)
nPtr = 0;
NULL,
NULL,
TRUE,
NULL,
NULL,
&stInfo,
if (!bResult)
return FALSE;
0, 0, &dwThreadId));
0, 0, &dwThreadId));
return TRUE;
if (bRedirectConsole) {
NULL,
NULL,
TRUE,
NULL,
NULL,
&stInfo,
&prInfo);
if (!bResult) {
return FALSE;
return TRUE;
int ticks;
if (sPos)
switch (dwCommand)
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_CONTINUE:
case SERVICE_APACHE_RESTART:
return FALSE;
return FALSE;
return FALSE;
else if (!serviceFlag)
return TRUE;
if (!schSCManager) {
return FALSE;
switch (dwCommand)
case SERVICE_CONTROL_STOP:
&schSStatus)) {
case SERVICE_CONTROL_CONTINUE:
case SERVICE_APACHE_RESTART:
&schSStatus))
return FALSE;
if (!--ticks) {
if (!retValue) {
FALSE);
return retValue;
return FALSE;
return FALSE;
return TRUE;
return FALSE;
dwPid = 0;
if (!schSCManager) {
return FALSE;
if (lpdwPid) {
return FALSE;
return FALSE;
dwPid = 0;
return rv;
int i, stPos = 0;
int computers = 0;
return FALSE;
&& dwBufLen)
== ERROR_SUCCESS) {
== ERROR_SUCCESS)
++stPos;
++computers;
return TRUE;
switch (message)
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
case IDOK:
return TRUE;
case IDCANCEL:
return TRUE;
case IDC_LBROWSE:
return TRUE;
case WM_QUIT:
case WM_CLOSE:
return TRUE;
return FALSE;
return FALSE;
switch (message)
case WM_INITDIALOG:
if (GetApacheServicesStatus())
: g_hBmpStart);
return TRUE;
case WM_MANAGEMESSAGE:
return TRUE;
case WM_UPDATEMESSAGE:
return TRUE;
case WM_MEASUREITEM:
return TRUE;
case WM_SETCURSOR:
if (g_bConsoleRun) {
return TRUE;
case WM_DRAWITEM:
case ODA_SELECT:
case ODA_DRAWENTIRE:
g_szLocalHost) == 0) {
case ODA_FOCUS:
return TRUE;
case WM_COMMAND:
case IDL_SERVICES:
case LBN_DBLCLK:
return TRUE;
case IDOK:
return TRUE;
case IDC_SSTART:
return TRUE;
case IDC_SSTOP:
return TRUE;
case IDC_SRESTART:
return TRUE;
case IDC_SMANAGER:
return TRUE;
case IDC_SEXIT:
return TRUE;
case IDC_SCONNECT:
return TRUE;
case IDC_SDISCONN:
return TRUE;
case WM_SIZE:
case SIZE_MINIMIZED:
return TRUE;
case WM_QUIT:
case WM_CLOSE:
return TRUE;
return FALSE;
return FALSE;
switch (message)
case WM_CREATE:
case WM_TIMER:
switch (wParam)
case WM_TIMER_RESCAN:
if (g_hwndServiceDlg)
++nPrev;
++nNew;
if (g_hwndServiceDlg) {
case WM_TIMER_REFRESH:
if (g_bRescanServices)
if (g_hwndServiceDlg) {
else if (FindRunningServices())
if (g_hwndServiceDlg) {
case WM_QUIT:
case WM_TRAYMESSAGE:
switch (lParam)
case WM_LBUTTONDBLCLK:
if (!g_bDlgServiceOn)
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_COMMAND:
return TRUE;
return TRUE;
return TRUE;
case IDM_RESTORE:
if (!g_bDlgServiceOn)
case IDC_SMANAGER:
return TRUE;
case IDM_EXIT:
PostQuitMessage(0);
return TRUE;
return FALSE;
SetLastError(0);
if (GetLastError())
== WAIT_OBJECT_0) {
if (appproc)
static int KillAllMonitors(void)
int exitcode = 0;
return exitcode;
return exitcode;
for (i = 0; i < tsProcCount; ++i) {
return exitcode;
return hWnd;
DWORD d;
return KillAllMonitors();
if (hMutex) {