diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
commit | 47e6e7c84f008a53061e661f31ae96629bc694ef (patch) | |
tree | 648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /src/pmsignal | |
download | pcp-47e6e7c84f008a53061e661f31ae96629bc694ef.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'src/pmsignal')
-rw-r--r-- | src/pmsignal/GNUmakefile | 30 | ||||
-rwxr-xr-x | src/pmsignal/pmsignal.sh | 120 |
2 files changed, 150 insertions, 0 deletions
diff --git a/src/pmsignal/GNUmakefile b/src/pmsignal/GNUmakefile new file mode 100644 index 0000000..24be489 --- /dev/null +++ b/src/pmsignal/GNUmakefile @@ -0,0 +1,30 @@ +#!gmake +# +# Copyright (c) 2009 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. +# + +TOPDIR = ../.. +include $(TOPDIR)/src/include/builddefs + +LSRCFILES = pmsignal.sh + +default: + +include $(BUILDRULES) + +install: default + $(INSTALL) -m 755 pmsignal.sh $(PCP_BINADM_DIR)/pmsignal$(SHELLSUFFIX) + +default_pcp : default + +install_pcp : install diff --git a/src/pmsignal/pmsignal.sh b/src/pmsignal/pmsignal.sh new file mode 100755 index 0000000..5a7e613 --- /dev/null +++ b/src/pmsignal/pmsignal.sh @@ -0,0 +1,120 @@ +#!/bin/sh +# +# Copyright (c) 2014 Red Hat. +# Copyright (c) 2009 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. +# +# Cross-platform signal/event sender for Performance Co-Pilot utilities. +# Supports a minimal set of signals, used by PCP tools on all platforms. +# + +. $PCP_DIR/etc/pcp.env + +status=1 +tmp=`mktemp -d /tmp/pcp.XXXXXXXXX` || exit 1 +trap "rm -rf $tmp; exit \$status" 0 1 2 3 15 +prog=`basename $0` +sigs="HUP USR1 TERM KILL" + +cat > $tmp/usage << EOF +# Usage: [options] PID ... | name ... + +Options: + -a,--all send signal to all named processes (killall mode) + -l,--list list available signals + -n,--dry-run list processes that would be affected + -s=N,--signal=N signal to send ($sigs)" + --help +EOF + +usage() +{ + [ ! -z "$@" ] && echo $@ 1>&2 + pmgetopt --progname=$prog --config=$tmp/usage --usage + exit 1 +} + +check() +{ + for sig in $sigs + do + [ $sig = "$1" ] && echo $sig && return + done + usage "$prog: invalid signal - $1" +} + +signal=TERM +aflag=false +lflag=false +nflag=false + +ARGS=`pmgetopt --progname=$prog --config=$tmp/usage -- "$@"` +[ $? != 0 ] && exit 1 + +eval set -- "$ARGS" +while [ $# -gt 0 ] +do + case "$1" + in + -a) aflag=true ;; + -l) lflag=true ;; + -n) nflag=true ;; + -s) signal=`check "$2"` + shift + ;; + --) shift + break + ;; + -\?) usage "" + ;; + esac + shift +done + +[ $lflag = true ] && echo "$sigs" && exit 0 + +[ $# -lt 1 ] && usage "$prog: Insufficient arguments" + +if [ $aflag = true ] +then + pids="" + for name in "$@"; do + program=`basename "$name"` + pidlist=`_get_pids_by_name "$program"` + pids="$pids $pidlist" + done +else + pids="$@" +fi +if [ $nflag = true ] +then + echo "$pids" + status=0 + exit +fi + +sts=0 +if [ "$PCP_PLATFORM" = mingw ] +then + for pid in $pids ; do + pcp-setevent $signal $pid + [ $? -eq 0 ] || sts=$? + done +else + for pid in $pids ; do + kill -$signal $pid + [ $? -eq 0 ] || sts=$? + done +fi + +status=$sts +exit |