opnsense-src/bin/pkill/tests/pkill-x_test.sh
Mark Johnston e1a3b7ff9f pkill tests: Fix pkill usage in the pkill -x test
The target process name(s) mark the beginning of the command's
positional parameters, so the -P filter wasn't getting applied as
intended.  As a result, the second "pkill -x sleep -P $$" would kill all
sleep(1) processes in the system, which can cause problems when running
tests in parallel.

MFC after:	2 weeks

(cherry picked from commit 57b09e470dbd84d1491a8972cf504b25e788a6c3)
2025-04-06 13:54:03 +00:00

43 lines
646 B
Bash

#!/bin/sh
base=`basename $0`
echo "1..4"
name="pkill -x"
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -P $$ -x slee
if [ $? -ne 0 ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
pkill -P $$ -x sleep
if [ $? -eq 0 ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
rm -f $sleep
name="pkill -x -f"
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -P $$ -x -f "$sleep "
if [ $? -ne 0 ]; then
echo "ok 3 - $name"
else
echo "not ok 3 - $name"
fi
pkill -P $$ -x -f "$sleep 5"
if [ $? -eq 0 ]; then
echo "ok 4 - $name"
else
echo "not ok 4 - $name"
fi
rm -f $sleep