Make main() in pt-stalk.

This commit is contained in:
Daniel Nichter
2011-11-01 11:39:04 -06:00
parent dfad96537e
commit 255ea01fd8

View File

@@ -99,21 +99,24 @@ log() {
echo "${1}" >&2 echo "${1}" >&2
} }
# Make the collection location # The main code that runs by default. Arguments are the command-line options.
mkdir -p "${DEST}" || die "Can't make the destination directory" main() {
test -d "${DEST}" || die "${DEST} isn't a directory"
test -w "${DEST}" || die "${DEST} isn't writable"
# Test if we have root; warn if not, but it isn't critical. # Make the collection location
if [ "$(id -u)" != "0" ]; then mkdir -p "${DEST}" || die "Can't make the destination directory"
test -d "${DEST}" || die "${DEST} isn't a directory"
test -w "${DEST}" || die "${DEST} isn't writable"
# Test if we have root; warn if not, but it isn't critical.
if [ "$(id -u)" != "0" ]; then
echo 'Not running with root privileges!'; echo 'Not running with root privileges!';
fi fi
# We increment this variable every time that the check is true, and set it to 0 # We increment this variable every time that the check is true,
# if it's false. # and set it to 0 if it's false.
cycles_true=0; cycles_true=0;
while true; do while true; do
d=$(date +%F-%T | tr :- _); d=$(date +%F-%T | tr :- _);
# XXX This is where we decide whether to execute 'collect'. # XXX This is where we decide whether to execute 'collect'.
@@ -157,7 +160,14 @@ while true; do
find "/var/lib/oprofile/samples" -type d -name 'pt_collect_*' \ find "/var/lib/oprofile/samples" -type d -name 'pt_collect_*' \
-depth -mtime +${PURGE} -exec rm -f '{}' \; -depth -mtime +${PURGE} -exec rm -f '{}' \;
done done
}
# Execute the program if it was not included from another file.
# This makes it possible to include without executing, and thus test.
if [ "$(basename "$0")" = "pt-stalk" ] || [ "$(basename "$0")" = "bash" -a "$_" = "$0" ]; then
main "$@"
fi
# ############################################################################ # ############################################################################
# Documentation # Documentation