From: Dave H. <hel...@us...> - 2012-03-06 18:25:21
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "SFCB - Small Footprint CIM Broker". The branch, master has been updated via cfbfd79f009a11a272c4edd1e281743bd597044a (commit) from 9c1c5431b1d58f1a29c184565b6557e0b00c4000 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit cfbfd79f009a11a272c4edd1e281743bd597044a Author: Dave Heller <hel...@us...> Date: Tue Mar 6 13:05:01 2012 -0500 [ 3497831 ] Updates to sfcb-ps test script ----------------------------------------------------------------------- Summary of changes: diff --git a/ChangeLog b/ChangeLog index 40a8adc..39189b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-03-06 Dave Heller <hel...@us...> + + * extra/sfcb-ps: + [ 3497831 ] Updates to sfcb-ps test script + 2012-03-02 Chris Buccella <buc...@li...> * interopProvider.c: diff --git a/NEWS b/NEWS index 8b5fb28..d64b625 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Everything in 1.3.13 and 1.3.14, plus: New features: - 3441679 Add a feature to validate CMPI types +- 3497831 Updates to sfcb-ps test script Bugs fixed: - 3495804 Cleanup: httpProcId still defined, wrong define in cimXmlGen diff --git a/extra/sfcb-ps b/extra/sfcb-ps index 16fcec8..ba15f95 100755 --- a/extra/sfcb-ps +++ b/extra/sfcb-ps @@ -13,12 +13,12 @@ # # Author: Mark Lanzo <ma...@us...> # -# Description: Scan running SFCB processes, +# Description: Scan running SFCB processes, # and figure out which ones are which, as best we can. # # This script is designed to run in embedded environments # This means that a very limited subset of Unix commands and shell features -# are used, because we stick to things known to be available in a reduced +# are used, because we stick to things known to be available in a reduced # shell environment. This does limit the capability somewhat. # ############################################################################## @@ -46,7 +46,7 @@ $N - Attempt to identify SFCB co-processes. those processes. Caution: Determination is not always 100% accurate. In particular, - the Main process is determined by seeing if the process is also the + the Main process is determined by seeing if the process is also the process group leader (its PID equals its PGID) - a condition which is true if SFCB was started as a daemon (normal mode) but which may not apply if SFCB was started in the foreground (developer mode). @@ -58,9 +58,14 @@ Options: -raw Scan for sfcbd processes and print process ID info, but don't otherwise attempt to classify the processes. - -main Specify the main sfcb process ID when not running in daemon + -main Specify the main sfcb process ID when not running in daemon mode. Experimental. + -useproc Use /proc fs to gather as much data as possible, rather than + relying on userspace commnads or options that may not be + avaliable in a small footprint environment. + + -maps Print memory maps for any Unknown processes HELP exit 0 @@ -75,6 +80,16 @@ check_arg () MAIN_PID=unknown RAW_PS= +PRINT_MAPS= + +# If ps options are not supported, run in -useproc mode. First check for error +# rc from ps, then double check the header line for the the requested option. +if ! ps -e >/dev/null 2>&1 || [ -z "$(ps -e -o pgid|head -n1|grep -i pgid)" ] +then + USE_PROC=true +else + USE_PROC= +fi while [ $# -gt 0 ] ; do case "$1" in @@ -90,6 +105,12 @@ while [ $# -gt 0 ] ; do -raw) RAW_PS=true ;; + -useproc) + USE_PROC=true ;; + + -maps) + PRINT_MAPS=true ;; + -*) die "Invalid option '$1'" ;; @@ -101,14 +122,30 @@ while [ $# -gt 0 ] ; do shift done +if [ -n "$USE_PROC" ] ; then + # For busybox ps + PS_INFO=$(ps | grep '[s]fcbd') +else + # Get everything from (standard) ps command + PS_INFO=$(ps -e -o pid,ppid,pgid,stat,cmd | grep '[s]fcbd') +fi + if [ -n "$RAW_PS" ] ; then printf "%5s %5s %5s %-4s %s\n" PID PPID PGID STAT CMD - ps -e -o pid,ppid,pgid,stat,cmd | grep 'sfcbd' + + if [ -n "$USE_PROC" ] ; then + echo "$PS_INFO" | while read pid user vsz stat cmd ; do + # We cannot get ppid & pgid from busybox ps so get them + # from /proc instead + read pid comm state ppid pgid therest < /proc/$pid/stat + printf "%5s %5s %5s %-4s %s\n" $pid $ppid $pgid $stat "$cmd" + done + else + echo "$PS_INFO" + fi exit 0 fi -PS_INFO=$(ps -e -o pid,ppid,pgid,stat,cmd | grep 'sfcbd') - if [ -z "$PS_INFO" ] ; then echo "No SFCB Processes found." exit 0 @@ -116,8 +153,35 @@ fi printf "%5s %5s %5s %-6s %s\n" PID PPID PGID STATE ROLE +# Really, in the case of -useproc we are expecting busybox ps, where the 2nd & +# 3rd fields will not be ppid & pgid. But it does not matter because we update +# with the correct values from /proc. echo "$PS_INFO" | while read pid ppid pgid stat cmd ; do - # If we launched as a daemon, then the top level process is the process + + if [ -n "$USE_PROC" ] ; then + + if [ ! -e "/proc/$pid/stat" ] ; then + role="process already gone." + printf "%5d %5s %5s %-6s %s\n" "$pid" "-" "-" "$stat" "$role" + break + fi + # Get ppid, pgid from /proc + read pid comm state ppid pgid therest < /proc/$pid/stat + + # Workaround lack of lsof support in some environments. + # Find inode of socket listening on http or https ports + # Determine if this pid has the socket open by checking for the + # socket inode in the fd list. + SOCKET_TEST="`cat /proc/net/tcp* | grep ":176[45]" | \ + grep -o '\:\([0-9,A-F]\{8\} \)\{2\}\( *[0-9]*\)\{3\}' | \ + grep -o ' [0-9]*$' | \ + while read inode; do ls -l /proc/$pid/fd/ | grep $inode; done`" + else + # Use standard lsof for socket test + SOCKET_TEST="`lsof -n -w -a -i :5988 -i :5989 -p $pid`" + fi + + # If we launched as a daemon, then the top level process is the process # group leader, so it is easy to identify. # # If not launched as a daemon, we have to be told how to recognize @@ -134,7 +198,7 @@ echo "$PS_INFO" | while read pid ppid pgid stat cmd ; do # Again, this requires that we be told who the master process is, # if we weren't launched as a daemon. - elif [ -n "`lsof -n -w -a -i :5988 -i :5989 -p $pid`" ] ; then + elif [ -n "$SOCKET_TEST" ] ; then if [ "$ppid" = "$pgid" -o \ "$ppid" = "$MAIN_PID" ] ; then role="Http Daemon" @@ -143,17 +207,17 @@ echo "$PS_INFO" | while read pid ppid pgid stat cmd ; do fi # SFCB opens up a huge number of sockets (like 100+!) before launching any - # of its child processes, -except- that it launches it logger process + # of its child processes, -except- that it launches it logger process # prior to opening the sockets. So the logger has a more normal count # of processes. Here, we make the guess that if it has less than 8 - # files open, it is the logger process (in fact it probably has about 4). + # files open, it is the logger process (in fact it probably has about 4). # Heuristics like this are bad, but I don't know any other way to reliably # identify the logger process. else open_fd=$(ls /proc/$pid/fd 2> /dev/null | wc -w) - # If we get 0 from above, the process must have gone away, so + # If we get 0 from above, the process must have gone away, so # don't bother reporting it. It was probably an HTTP request # handler. @@ -169,7 +233,7 @@ echo "$PS_INFO" | while read pid ppid pgid stat cmd ; do fi # Beyond this point, we can identify provider processes, but only by - # scanning the shared libraries they have loaded and looking for + # scanning the shared libraries they have loaded and looking for # specific shared libraries which carry that provider's code. Which # means knowing a priori the names of those specific libraries. # @@ -181,7 +245,7 @@ echo "$PS_INFO" | while read pid ppid pgid stat cmd ; do if [ -z "$role" ] ; then - # Cache contents of /proc/$pid/maps for efficiency, and also + # Cache contents of /proc/$pid/maps for efficiency, and also # in case the process vanishes while we are poking around. MAP=`cat /proc/$pid/maps 2>/dev/null` @@ -201,6 +265,8 @@ echo "$PS_INFO" | while read pid ppid pgid stat cmd ; do role="SFCB Internal Provider" elif echo "$MAP" | grep -q 'sfcInteropServerProvider' ; then role="SFCB Interop Server Provider" + elif echo "$MAP" | grep -q 'Provider.so' ; then + role=$(echo "$MAP" | grep -o '[^/]*Provider' | head -n1) else # Most likely it is another provider, but it could also # be Main if we couldn't figure that out on our own. @@ -210,6 +276,10 @@ echo "$PS_INFO" | while read pid ppid pgid stat cmd ; do if [ -n "$role" ] ; then printf "%5d %5d %5d %-6s %s\n" "$pid" "$ppid" "$pgid" "$stat" "$role" + # Output may aid in manually identifying the process. + if [ "$role" = "Unknown" -a -n "$PRINT_MAPS" ]; then + cat /proc/$pid/maps + fi fi done hooks/post-receive -- SFCB - Small Footprint CIM Broker |