Skip to contentSkip to conversation

tests: monitor: run-tests.sh: restore cwd before unshare

PATCH In review Florian Westphal 2 participants 2 messages Nov 7, 2024 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 tests: monitor: run-tests.sh: restore cwd before unshare

The monitor script no longer works if not called from tests/monitor directory:

% tests/monitor/run-tests.sh
unshare: failed to execute tests/monitor/run-tests.sh: No such file or directory

... because the script will change the directory. Stash and restore to old one so unshare $0 can work.

---
 tests/monitor/run-tests.sh | 2 ++
 1 file changed, 2 insertions(+)
tests/monitor/run-tests.sh +2 -0
index 214512d269e8..7a8b1a719dc1 100755
@@ -1,5 +1,6 @@
 #!/bin/bash
 
+pushd .
 cd $(dirname $0)
 nft=${NFT:-../../src/nft}
 debug=false
@@ -125,6 +126,7 @@ for arg in "$@"; do
 	[[ "$arg" == "--no-netns" ]] && netns=false
 done
 if $netns; then
+	popd
 	exec unshare -n $0 --no-netns "$@"
 fi
 
Signature · 1 line
2.45.2
reviewer
#1 lore raw
Quoted 7 lines · Florian Westphal

The monitor script no longer works if not called from tests/monitor directory:

% tests/monitor/run-tests.sh
unshare: failed to execute tests/monitor/run-tests.sh: No such file or directory

... because the script will change the directory. Stash and restore to old one so unshare $0 can work.

Still not perfect:

| % sudo ./tests/monitor/run-tests.sh ./tests/monitor/testcases/set-maps.t 
| /home/n0-1/git/nftables /home/n0-1/git/nftables
| /home/n0-1/git/nftables
| /home/n0-1/git/nftables /home/n0-1/git/nftables
| unknown option './tests/monitor/testcases/set-maps.t'
| Usage: run-tests.sh [-j|--json] [-d|--debug] [testcase ...]

AFAICT, $(dirname $0) is only needed to locate the local nft binary. Let me send a patch which eliminates the cd call entirely.

Cheers, Phil