commit a5012d86e87e1c59be4a221b7d47cc791b102555 Author: Maynard Johnson Date: Wed May 25 16:10:46 2011 -0500 Fix opcontrol --status to show accurate information for running daemon diff --git a/utils/opcontrol b/utils/opcontrol index 0f04354..f002f01 100644 --- a/utils/opcontrol +++ b/utils/opcontrol @@ -38,6 +38,16 @@ do_sysctl() echo $val > /proc/sys/$dev_name } +# Helper function to check if oprofile daemon is active. +# Takes one argument: the "lock file" for the oprofile daemon. +# The lock file may exist even if the daemon was killed or died in +# some way. So we do a kill SIG_DFL to test whether the daemon is +# truly alive. If the lock file is stale (daemon dead), the kill will +# not return '0'. +is_oprofiled_active() +{ + [ -f "$1" ] && kill -0 `cat "$1"` 2>/dev/null +} # check value is set error_if_empty() @@ -355,6 +365,7 @@ do_init() # location for daemon setup information SETUP_DIR="/root/.oprofile" SETUP_FILE="$SETUP_DIR/daemonrc" + SEC_SETUP_FILE="$SETUP_DIR/daemonrc_new" # initialize daemon vars decide_oprofile_device_mount @@ -408,6 +419,19 @@ set_event() do_save_setup() { create_dir "$SETUP_DIR" + SAVE_SETUP_FILE="$SETUP_FILE" + +# If the daemon is currently running, we want changes to the daemon config +# stored in the secondary cache file so that 'opcontrol --status' will +# show actual config data for the running daemon. The next time the +# daemon is restarted, we'll reload the config data from this secondary +# cache file. + + if is_oprofiled_active "$LOCK_FILE"; then + SETUP_FILE="$SEC_SETUP_FILE" + echo "The profiling daemon is currently active, so changes to the configuration" + echo "will be used the next time you restart oprofile after a --shutdown or --deinit." + fi touch $SETUP_FILE chmod 644 $SETUP_FILE @@ -451,12 +475,27 @@ do_save_setup() if test "$XEN_RANGE"; then echo "XEN_RANGE=$XEN_RANGE" >> $SETUP_FILE fi + SETUP_FILE="$SAVE_SETUP_FILE" } # reload all the setup-related information do_load_setup() { +# If a secondary setup file exists and the daemon is not running, +# then we'll move the data from the secondary file to the actual +# setup file to prepare for daemon startup. + if test -z "$SESSION_DIR"; then + __TMP_SESSION_DIR="/var/lib/oprofile" + else + __TMP_SESSION_DIR="$SESSION_DIR" + fi + + if test -f "$SEC_SETUP_FILE"; then + is_oprofiled_active "$__TMP_SESSION_DIR/lock" \ + || mv "$SEC_SETUP_FILE" "$SETUP_FILE" + fi + if test -f "$SETUP_FILE"; then # load the actual information from file # FIXME this is insecure, arbitrary commands could be added to @@ -1572,7 +1611,12 @@ do_status() { OPROFILED_PID=`cat $SESSION_DIR/lock 2>/dev/null` if test -n "$OPROFILED_PID" -a -d "/proc/$OPROFILED_PID"; then - echo "Daemon running: pid $OPROFILED_PID" + if test "$KERNEL_SUPPORT" = yes \ + && test 0 != $(cat /dev/oprofile/enable); then + echo "Daemon running: pid $OPROFILED_PID" + else + echo "Daemon paused: pid $OPROFILED_PID" + fi else echo "Daemon not running" fi