Index: devpcp/src/pmdas/windows/GNUmakefile =================================================================== --- devpcp.orig/src/pmdas/windows/GNUmakefile 2007-02-08 13:09:36.351012000 +1100 +++ devpcp/src/pmdas/windows/GNUmakefile 2007-02-08 16:35:49.856307750 +1100 @@ -31,11 +31,13 @@ CFILES = pmda.c data.c HFILES = shm.h shim_pcp.h shim.h SHIM_CFILES = shim.c pdherr.c util.c init.c instance.c help.c fetch.c SHIM_OBJECTS = $(SHIM_CFILES:.c=.obj) +CYGWIN_CFILES = pmcygwinserver.c +CYGWIN_OBJECTS = $(CYGWIN_CFILES:.c=.o) LLDLIBS = -lpcp -lpcp_pmda LCFLAGS = -I. PMNS = pmns.disk pmns.kernel pmns.mem pmns.network \ pmns.sqlserver pmns.filesys pmns.hinv pmns.pmda -LSRCFILES = $(SHIM_CFILES) \ +LSRCFILES = $(SHIM_CFILES) $(CYGWIN_CFILES) pmcygrunsrv \ Install Remove $(PMNS) root README \ GNUmakefile.install shim.save \ match-counters show-all-ctrs.c show-all-ctrs.save \ @@ -66,12 +68,14 @@ ifeq "$(do_build)" "true" # C compiler gulfs CMDTARGET = pmdawindows.exe SHIMTARGET = check_shim +CYGWINTARGET = pmcygwinserver else CMDTARGET = SHIMTARGET = +CYGWINTARGET = endif -default_pcp default: $(LSRCFILES) $(CMDTARGET) $(SHIMTARGET) +default_pcp default: $(LSRCFILES) $(CMDTARGET) $(SHIMTARGET) $(CYGWINTARGET) SHIM_CC = '$(DDKROOT)\bin\x86\cl' SHIM_CFLAGS = -DPCP_DEBUG -DPCP_VERSION=\"$(PCP_VERSION)\" -DWIN32 /Od /Zi /I$(TOPDIR)/src/include /I'$(DDKROOT)\inc\$(MSPLATFORM)' /I'$(DDKROOT)\inc\crt' /I'$(SDKROOT)\include' @@ -108,10 +112,17 @@ install install_pcp: check_shim default $(INSTALL) -m 755 show-all-ctrs.exe $(CMDTARGET) $(PMDADIR) $(INSTALL) -m 644 GNUmakefile.install $(PMDADIR)/Makefile $(INSTALL) -m 644 README root $(PMNS) domain.h $(CFILES) $(PMDADIR) + $(INSTALL) -m 755 -d $(PCP_BIN_DIR) + $(INSTALL) -m 755 pmcygrunsrv $(PCP_BIN_DIR)/pmcygrunsrv + $(INSTALL) -m 755 -d $(PCP_SHARE_DIR)/bin + $(INSTALL) -m 755 $(CYGWINTARGET) $(PCP_SHARE_DIR)/bin/$(CYGWINTARGET) else install install_pcp: endif +pmcygwinserver.exe: $(CYGWIN_OBJECTS) + $(CCF) -o pmcygwinserver.exe $(LDFLAGS) $(CYGWIN_OBJECTS) + shim.exe: platform_defs.h $(SHIM_OBJECTS) rm -f shim.exe $(SHIM_LINK) /out:shim.exe $(SHIM_OBJECTS) user32.lib pdh.lib advapi32.lib $(SHIM_LINK_FLAGS) Index: devpcp/src/pmdas/windows/pmcygwinserver.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ devpcp/src/pmdas/windows/pmcygwinserver.c 2007-02-08 16:34:03.881684750 +1100 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2007 Aconex, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include +#include +#include +#include +#include +#include + +char command[32]; +char *progname; +char *service; +char *timenow; +time_t now; + +void stop(int unused) +{ + (void)unused; + now = time(NULL); + timenow = ctime(&now); + timenow[strlen(timenow)-1] = '\0'; + snprintf(command, sizeof(command), "/etc/%s stop", service); + fprintf(stdout, "[%s] %s issuing \"%s\"\n", timenow, progname, command); + fflush(stdout); + + if (system(command) == 0) + exit(0); +} + +int main(int argc, char **argv) +{ + progname = basename(argv[0]); + if (argc != 2) { + fprintf(stderr, "%s: bad argument count (expected only 1, not %d).\n", + progname, argc - 1); + return 1; + } + service = argv[1]; + + now = time(NULL); + timenow = ctime(&now); + timenow[strlen(timenow)-1] = '\0'; + snprintf(command, sizeof(command), "/etc/%s start", service); + fprintf(stdout, "[%s] %s issuing \"%s\"\n", timenow, progname, command); + fflush(stdout); + + signal(SIGHUP, stop); + if (system(command) == 0) + pause(); + exit(1); +} Index: devpcp/src/pmdas/windows/pmcygrunsrv =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ devpcp/src/pmdas/windows/pmcygrunsrv 2007-02-08 16:37:56.152200750 +1100 @@ -0,0 +1,110 @@ +#!/bin/sh +# +# Copyright (c) 2007 Aconex. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# pmcygrunsrv: +# Manipulates one of the PCP "services" via cygrunsrv.exe. +# This script provides a dummy "service" executable which can +# be installed/removed/stopped/started/queried via the Windows +# (and Cygwin) services mechanisms. +# + +# Get standard environment +. /etc/pcp.env + +server="$PCP_SHARE_DIR/bin/pmcygwinserver" +user=Administrator +service=pcp # "pcp", "pmie" and "pmproxy" are valid + +verify_service() +{ + service="$1" + if [ "$1" != pcp -a "$1" != pmie -a "$1" != pmproxy ]; then + echo "Invalid service name: $service \(not pcp, pmie, or pmproxy\)" + exit 1 + fi +} + +report_service() +{ + service="$1" + cygrunsrv $verbose -Q $service 2>/dev/null + if [ $? -ne 0 ]; then + echo "Service : $service" + echo "Current State : Not installed" + fi +} + +usage() +{ + cat - < Installes a new service named . + -R Removes a service named . + -S Starts a service named . + -E Stops a service named . + -Q Queries a service named . + -L Lists services that have been installed. + +Services: + Valid are pcp, pmie, and pmproxy. +EOF + exit 1 +} + +install=false +remove=false +start=false +stop=false +query=false +list=false +verbose= + +while getopts I:R:S:E:Q:LVu:? c +do + case $c + in + I) verify_service $OPTARG; install=true ;; + R) verify_service $OPTARG; remove=true ;; + S) verify_service $OPTARG; start=true ;; + E) verify_service $OPTARG; stop=true ;; + Q) verify_service $OPTARG; query=true ;; + L) list=true ;; + V) verbose=-V ;; + u) user=$OPTARG ;; + *) usage ;; + esac +done +if $install ; then + cygrunsrv -I $service -u $user -n -o -y tcpip -s 1 -p $server -a $service \ + -1 /var/log/pcp/cygwin/$service.log -2 /var/log/pcp/cygwin/$service.log +elif $remove ; then + cygrunsrv -R $service +elif $query ; then + cygrunsrv -Q $service $verbose +elif $start ; then + cygrunsrv -S $service +elif $stop ; then + cygrunsrv -E $service +else + report_service pcp + report_service pmie + report_service pmproxy +fi +exit 0