start_lttng_relayd_opt 1 "-d" "--working-directory $working_dir"
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
ok $? "Found lttng-relayd"
cwd=$(readlink "/proc/${pid}/cwd")
start_lttng_relayd_opt 1 "-d" ""
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
ok $? "Found lttng-relayd"
cwd=$(readlink "/proc/${pid}/cwd")
start_lttng_relayd_opt 1 "-b" "--working-directory $working_dir"
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
ok $? "Found lttng-relayd"
cwd=$(readlink "/proc/${pid}/cwd")
start_lttng_relayd_opt 1 "-b" ""
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
ok $? "Found lttng-relayd"
cwd=$(readlink "/proc/${pid}/cwd")
ERROR_OUTPUT_DEST=$(mktemp)
start_lttng_relayd_opt 1 "-b" "-v --working-dir $working_dir"
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
ok $? "Found lttng-relayd"
cwd=$(readlink "/proc/${pid}/cwd")
test $? -eq "1"
ok $? "Expect failure to start lttng-relayd for non-existent working directory"
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
if [ -z "$pid" ]; then
pass "No lttng-relayd present"
else
export LTTNG_RELAYD_WORKING_DIRECTORY=${working_dir}
start_lttng_relayd_opt 1 "-b" ""
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
ok $? "Found lttng-relayd"
cwd=$(readlink "/proc/$pid/cwd")
export LTTNG_RELAYD_WORKING_DIRECTORY=${working_dir_env}
start_lttng_relayd_opt 1 "-b" "--working-dir ${working_dir_cmdline}"
- pid=$(pgrep "$RELAYD_MATCH")
+ pid=$(lttng_pgrep "$RELAYD_MATCH")
ok $? "Found lttng-relayd"
cwd=$(readlink "/proc/$pid/cwd")
function check_sessiond()
{
- if [ -z "$(pgrep --full lt-lttng-sessiond)" ]; then
+ if [ -z "$(lttng_pgrep lt-lttng-sessiond)" ]; then
local str_date=$(date +%H%M%S-%d%m%Y)
diag "!!!The session daemon died unexpectedly!!!"
BAIL_OUT "*** Kernel too old for session daemon tests ***"
fi
- if [ -z $(pgrep --full lt-$SESSIOND_BIN) ]; then
+ if [ -z $(lttng_pgrep lt-$SESSIOND_BIN) ]; then
# We have to start it like this so the ulimit -c is used by this
# process. Also, we collect any error message printed out.
$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE 2>&1
function check_sessiond()
{
- if [ -z "$(pgrep --full lt-lttng-sessiond)" ]; then
+ if [ -z "$(lttng_pgrep lt-lttng-sessiond)" ]; then
local str_date=$(date +%H%M%S-%d%m%Y)
diag "!!!The session daemon died unexpectedly!!!"
function check_relayd()
{
- if [ -z "$(pgrep --full lt-lttng-relayd)" ]; then
+ if [ -z "$(lttng_pgrep lt-lttng-relayd)" ]; then
local str_date=$(date +%H%M%S-%d%m%Y)
diag "!!!The relay daemon died unexpectedly!!!"
BAIL_OUT "*** Kernel too old for session daemon tests ***"
fi
- if [ -z $(pgrep --full lt-$SESSIOND_BIN) ]; then
+ if [ -z $(lttng_pgrep lt-$SESSIOND_BIN) ]; then
# We have to start it like this so the ulimit -c is used by this
# process. Also, we collect any error message printed out.
$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1
{
local opt=$1
- if [ -z $(pgrep --full lt-$RELAYD_BIN) ]; then
+ if [ -z $(lttng_pgrep lt-$RELAYD_BIN) ]; then
$TESTDIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >$LOG_FILE_RELAYD 2>&1 &
ok $? "Start lttng-relayd (opt: \"$opt\")"
fi
function check_sessiond()
{
- if [ -z "$(pgrep --full lt-lttng-sessiond)" ]; then
+ if [ -z "$(lttng_pgrep lt-lttng-sessiond)" ]; then
local str_date=$(date +%H%M%S-%d%m%Y)
diag "!!!The session daemon died unexpectedly!!!"
BAIL_OUT "*** Kernel too old for session daemon tests ***"
fi
- if [ -z $(pgrep --full lt-$SESSIOND_BIN) ]; then
+ if [ -z $(lttng_pgrep lt-$SESSIOND_BIN) ]; then
# We have to start it like this so the ulimit -c is used by this
# process. Also, we collect any error message printed out.
#$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1
{
local opt=$1
- if [ -z $(pgrep --full lt-$RELAYD_BIN) ]; then
+ if [ -z $(lttng_pgrep lt-$RELAYD_BIN) ]; then
$TESTDIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >$LOG_FILE_RELAYD 2>&1 &
ok $? "Start lttng-relayd (opt: \"$opt\")"
fi
function check_relayd()
{
- if [ -z "$(pgrep --full lt-lttng-relayd)" ]; then
+ if [ -z "$(lttng_pgrep lt-lttng-relayd)" ]; then
local str_date=$(date +%H%M%S-%d%m%Y)
#diag "Relay daemon died. Starting it again"
trap null_pipes SIGPIPE
+# Check pgrep from env, default to pgrep if none
+if [ -z "$PGREP" ]; then
+ PGREP=pgrep
+fi
+
+# Due to the renaming of threads we need to use the full command (pgrep -f) to
+# identify the pids for multiple lttng related processes. The problem with "pgrep
+# -f" is that it ends up also looking at the arguments. We use a two stage
+# lookup. The first one is using "pgrep -f" yielding potential candidate.
+# The second on perform grep on the basename of the first field of the
+# /proc/pid/cmdline of the previously identified pids. The first field
+# correspond to the actual command.
+function lttng_pgrep ()
+{
+ local pattern=$1
+ local possible_pids
+ local full_command_no_argument
+ local command_basename
+
+ possible_pids=$($PGREP -f "$pattern")
+ if [ -z "$possible_pids" ]; then
+ return 0
+ fi
+
+ while IFS= read -r pid ; do
+ # /proc/pid/cmdline is null separated.
+ if full_command_no_argument=$(cut -d '' -f 1 < /proc/"$pid"/cmdline); then
+ command_basename=$(basename "$full_command_no_argument")
+ if grep -q "$pattern" <<< "$command_basename"; then
+ echo "$pid"
+ fi
+ fi
+ done <<< "$possible_pids"
+ return 0
+}
+
function print_ok ()
{
# Check if we are a terminal
DIR=$(readlink -f "$TESTDIR")
- if [ -z $(pgrep -f $RELAYD_MATCH) ]; then
+ if [ -z $(lttng_pgrep "$RELAYD_MATCH") ]; then
# shellcheck disable=SC2086
$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
#$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
local retval=0
local pids=
- pids=$(pgrep -f "$RELAYD_MATCH")
+ pids=$(lttng_pgrep "$RELAYD_MATCH")
if [ -z "$pids" ]; then
if [ "$withtap" -eq "1" ]; then
pass "No relay daemon to kill"
else
out=1
while [ -n "$out" ]; do
- out=$(pgrep -f "$RELAYD_MATCH")
+ out=$(lttng_pgrep "$RELAYD_MATCH")
if [ -n "$dtimeleft_s" ]; then
if [ $dtimeleft_s -lt 0 ]; then
out=
: "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
export LTTNG_SESSION_CONFIG_XSD_PATH
- if [ -z "$(pgrep -f "${SESSIOND_MATCH}")" ]; then
+ if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
# Have a load path ?
if [ -n "$load_path" ]; then
# shellcheck disable=SC2086
local retval=0
local runas_pids=
- runas_pids=$(pgrep -f "$RUNAS_MATCH")
+ runas_pids=$(lttng_pgrep "$RUNAS_MATCH")
local pids=
- pids=$(pgrep -f "$SESSIOND_MATCH")
+ pids=$(lttng_pgrep "$SESSIOND_MATCH")
if [ -n "$runas_pids" ]; then
pids="$pids $runas_pids"
else
out=1
while [ -n "$out" ]; do
- out=$(pgrep -f "${SESSIOND_MATCH}")
+ out=$(lttng_pgrep "${SESSIOND_MATCH}")
if [ -n "$dtimeleft_s" ]; then
if [ $dtimeleft_s -lt 0 ]; then
out=
done
out=1
while [ -n "$out" ]; do
- out=$(pgrep -f "$CONSUMERD_MATCH")
+ out=$(lttng_pgrep "$CONSUMERD_MATCH")
if [ -n "$dtimeleft_s" ]; then
if [ $dtimeleft_s -lt 0 ]; then
out=
return
fi
- PID_SESSIOND="$(pgrep -f "${SESSIOND_MATCH}") $(pgrep -f "$RUNAS_MATCH")"
+ PID_SESSIOND="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")"
if [ "$withtap" -eq "1" ]; then
diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
else
out=1
while [ $out -ne 0 ]; do
- pid="$(pgrep -f "$SESSIOND_MATCH")"
+ pid="$(lttng_pgrep "$SESSIOND_MATCH")"
# Wait until state becomes stopped for session
# daemon(s).
local retval=0
- PID_CONSUMERD="$(pgrep -f "$CONSUMERD_MATCH")"
+ PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
if [ -z "$PID_CONSUMERD" ]; then
if [ "$withtap" -eq "1" ]; then
else
out=1
while [ $out -ne 0 ]; do
- pid="$(pgrep -f "$CONSUMERD_MATCH")"
+ pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
# If consumerds are still present check their status.
# A zombie status qualifies the consumerd as *killed*
local withtap=$1
local signal=SIGSTOP
- PID_CONSUMERD="$(pgrep -f "$CONSUMERD_MATCH")"
+ PID_CONSUMERD="$(lttng_pgrep "$CONSUMERD_MATCH")"
diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
else
out=1
while [ $out -ne 0 ]; do
- pid="$(pgrep -f "$CONSUMERD_MATCH")"
+ pid="$(lttng_pgrep "$CONSUMERD_MATCH")"
# Wait until state becomes stopped for all
# consumers.