Fix: tests: `pgrep -f` flags unrelated process as lttng-sessiond
[lttng-tools.git] / tests / regression / tools / working-directory / test_relayd_working_directory
index 6231ece0ed37bb40961f8c6a2c31e127cb916598..24b87a9cc1eb15003e72232778dc4d9bc656aa26 100755 (executable)
@@ -67,7 +67,7 @@ function test_relayd_daemon()
 
        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")
@@ -88,7 +88,7 @@ function test_relayd_daemon_no_working_dir()
 
        start_lttng_relayd_opt 1 "-d" ""
 
-       pid=$(pgrep "$RELAYD_MATCH")
+       pid=$(lttng_pgrep "$RELAYD_MATCH")
        ok $? "Found lttng-relayd"
 
        cwd=$(readlink "/proc/${pid}/cwd")
@@ -111,7 +111,7 @@ function test_relayd_background()
 
        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")
@@ -132,7 +132,7 @@ function test_relayd_background_no_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")
@@ -145,35 +145,47 @@ function test_relayd_background_no_working_dir()
 
 function test_relayd_debug_permission()
 {
-       local output_pattern='Working directory \".*\" is not writable'
-       local working_dir
-       local cwd
-       local pid
-
-       working_dir=$(realpath "$(mktemp -d)")
+       local is_user
 
        diag "Test lttng-relayd change working directory on non writable directory"
 
-       # Removing write access to working dir
-       okx chmod -w "$working_dir"
+       if [ "$(id -u)" == "0" ]; then
+           is_user=0
+       else
+           is_user=1
+       fi
 
-       # Redirect the error output to a temporary file
-       ERROR_OUTPUT_DEST=$(mktemp)
-       start_lttng_relayd_opt 1 "-b" "-v --working-dir $working_dir"
+       skip $is_user "Skipping permission debug output test; operation can't fail as root" 6 ||
+       {
+               local output_pattern='Working directory \".*\" is not writable'
+               local working_dir
+               local cwd
+               local pid
 
-       pid=$(pgrep "$RELAYD_MATCH")
-       ok $? "Found lttng-relayd"
+               working_dir=$(realpath "$(mktemp -d)")
 
-       cwd=$(readlink "/proc/${pid}/cwd")
-       is "$cwd" "$working_dir" "Working directory changed"
+               # Removing write access to working dir
+               okx chmod -w "$working_dir"
 
-       grep -q "$output_pattern" "$ERROR_OUTPUT_DEST"
-       ok $? "Warning about missing write permission is present"
+               # Redirect the error output to a temporary file
 
-       stop_lttng_relayd
-       rm "$ERROR_OUTPUT_DEST"
-       rm -rf "$working_dir" "$ERROR_OUTPUT_DEST"
-       ERROR_OUTPUT_DEST=/dev/null
+               ERROR_OUTPUT_DEST=$(mktemp)
+               start_lttng_relayd_opt 1 "-b" "-v --working-dir $working_dir"
+
+               pid=$(lttng_pgrep "$RELAYD_MATCH")
+               ok $? "Found lttng-relayd"
+
+               cwd=$(readlink "/proc/${pid}/cwd")
+               is "$cwd" "$working_dir" "Working directory changed"
+
+               grep -q "$output_pattern" "$ERROR_OUTPUT_DEST"
+               ok $? "Warning about missing write permission is present"
+
+               stop_lttng_relayd
+               rm "$ERROR_OUTPUT_DEST"
+               rm -rf "$working_dir" "$ERROR_OUTPUT_DEST"
+               ERROR_OUTPUT_DEST=/dev/null
+       }
 }
 
 function test_relayd_failure()
@@ -196,7 +208,7 @@ function test_relayd_failure()
        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
@@ -225,7 +237,7 @@ function test_relayd_env()
        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")
@@ -252,7 +264,7 @@ function test_relayd_cmdline_overwrite_env()
        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")
This page took 0.026604 seconds and 5 git commands to generate.