From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 3/7] test: In pasta demo, use pgrep instead of pstree to find namespace PID Date: Thu, 21 Jul 2022 14:06:33 +0200 Message-ID: <20220721120637.232914-4-sbrivio@redhat.com> In-Reply-To: <20220721120637.232914-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5268265580859024978==" --===============5268265580859024978== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Parsing pstree's output is somewhat unreliable: there might be multiple pasta instances running on the same host, and depending on the overall output width pstree might truncate some branches. Ask pasta to save its PID to file, and use that as parameter for pgrep to find the PID of the interactive shell whose user and network namespaces we want to join. Signed-off-by: Stefano Brivio --- test/demo/pasta | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/demo/pasta b/test/demo/pasta index f4b7da2..be117b3 100644 --- a/test/demo/pasta +++ b/test/demo/pasta @@ -48,7 +48,7 @@ nl say without PID, it will create a namespace. sleep 3 passt cd __TEMPDIR__/passt -passtb ./pasta +passtb ./pasta -P /tmp/pasta.pid sleep 3 nl @@ -57,8 +57,7 @@ say For convenience, let's enter this namespace nl say from another terminal. sleep 3 -ns pstree -p | grep pasta -nsout TARGET_PID pstree -p | grep pasta | sed -n 's/.*(\([0-9].*\))$/\1/p' +nsout TARGET_PID pgrep -P $(cat /tmp/pasta.pid) sleep 1 ns nsenter -t __TARGET_PID__ -U -n --preserve-credentials @@ -171,10 +170,10 @@ passt exit passt make clean passt CFLAGS="-g" make sleep 2 -passtb perf record -g ./pasta +passtb perf record -g ./pasta -P /tmp/pasta.pid sleep 2 -nsout TARGET_PID pstree -p | grep pasta | sed -n 's/.*(\([0-9].*\))$/\1/p' +nsout TARGET_PID pgrep -P $(cat /tmp/pasta.pid) sleep 1 ns nsenter -t __TARGET_PID__ -U -n --preserve-credentials sleep 5 -- 2.35.1 --===============5268265580859024978==--