diff options
Diffstat (limited to 'src/include/pcp.env')
-rw-r--r-- | src/include/pcp.env | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/include/pcp.env b/src/include/pcp.env new file mode 100644 index 0000000..d0ccab2 --- /dev/null +++ b/src/include/pcp.env @@ -0,0 +1,95 @@ +# +# Copyright (c) 2000,2003 Silicon Graphics, Inc. All Rights Reserved. +# Copyright (c) 2010 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. +# +# This file is sourced by PCP scripts to set the environment +# variables defined in the file named $PCP_CONF (or /etc/pcp.conf +# if $PCP_CONF is not defined). Any variable already defined in +# the environment is not changed. +# +# Note: any variables NOT starting with PCP_ will be ignored. +# This is a security issue so don't change it. +# Note also, this (variant of this) file is not used on Windows. +# +if [ -z "$PCP_ENV_DONE" ] +then + if [ -n "$PCP_CONF" ] + then + __CONF="$PCP_CONF" + elif [ -n "$PCP_DIR" ] + then + __CONF="$PCP_DIR/etc/pcp.conf" + else + __CONF=/etc/pcp.conf + fi + if [ ! -f "$__CONF" ] + then + echo "pcp.env: Fatal Error: \"$__CONF\" not found" >&2 + exit 1 + fi + eval `sed -e 's/"//g' $__CONF \ + | awk -F= ' +/^PCP_/ && NF == 2 { + exports=exports" "$1 + printf "%s=${%s:-\"%s\"}\n", $1, $1, $2 +} END { + print "export", exports +}'` + export PCP_ENV_DONE=y +fi + +# Always need to set $PATH ... sudo -E leaves $PCP_ENV_DONE set, but +# clears/resets $PATH. Note that order is important: any paths with +# PCP-specific binaries should end up ahead of more generic paths in +# the final $PATH to avoid conflicts on names of non-pcp binaries. +# +for dir in ${PCP_BIN_DIR} ${PCP_BINADM_DIR} \ + ${PCP_SHARE_DIR}/bin ${PCP_PLATFORM_PATHS} +do + if [ -d $dir ] + then + if echo ":$PATH:" | grep ":$dir:" >/dev/null 2>&1 + then + : + else + PATH="$dir:$PATH" + fi + fi +done +export PATH + +_get_pids_by_name() +{ + if [ $# -ne 1 ] + then + echo "Usage: _get_pids_by_name process-name" >&2 + exit 1 + fi + + # Algorithm ... all ps(1) variants have a time of the form MM:SS + # or HH:MM:SS or HH:MM.SS before the psargs field, so we're using + # this as the search anchor. + # + # Matches with $1 (process-name) occur if the first psarg is $1 + # or ends in /$1 ... the matching uses sed's regular expressions, + # so passing a regex into $1 will work. + + $PCP_PS_PROG $PCP_PS_ALL_FLAGS \ + | sed -n \ + -e 's/$/ /' \ + -e 's/[ ][ ]*/ /g' \ + -e 's/^ //' \ + -e 's/^[^ ]* //' \ + -e "/[0-9][:\.][0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \ + -e "/[0-9][:\.][0-9][0-9] *$1 /s/ .*//p" +} |